split: train

prompt: Take a list of integers; keep the even numbers.

solution:
def op_evens(xs):
    r = list(xs)
    r = [x for x in r if x % 2 == 0]
    return r


split: train

prompt: Take a list of integers; keep the positive numbers.

solution:
def op_pos(xs):
    r = list(xs)
    r = [x for x in r if x > 0]
    return r


split: train

prompt: Take a list of integers; double each.

solution:
def op_double(xs):
    r = list(xs)
    r = [x * 2 for x in r]
    return r


split: train

prompt: Take a list of integers; square each.

solution:
def op_square(xs):
    r = list(xs)
    r = [x * x for x in r]
    return r


split: train

prompt: Take a list of integers; add one to each.

solution:
def op_inc(xs):
    r = list(xs)
    r = [x + 1 for x in r]
    return r


split: train

prompt: Take a list of integers; negate each.

solution:
def op_negate(xs):
    r = list(xs)
    r = [-x for x in r]
    return r


split: train

prompt: Take a list of integers; take the absolute value of each.

solution:
def op_absval(xs):
    r = list(xs)
    r = [abs(x) for x in r]
    return r


split: train

prompt: Take a list of integers; reverse the order.

solution:
def op_rev(xs):
    r = list(xs)
    r = list(reversed(r))
    return r


split: train

prompt: Take a list of integers; sort ascending.

solution:
def op_sorta(xs):
    r = list(xs)
    r = sorted(r)
    return r


split: train

prompt: Take a list of integers; sort descending.

solution:
def op_sortd(xs):
    r = list(xs)
    r = sorted(r, reverse=True)
    return r


split: train

prompt: Take a list of integers; drop duplicates keeping first occurrence.

solution:
def op_uniq(xs):
    r = list(xs)
    r = list(dict.fromkeys(r))
    return r


split: train

prompt: Take a list of integers; subtract one from each.

solution:
def op_dec(xs):
    r = list(xs)
    r = [x - 1 for x in r]
    return r


split: train

prompt: Take a list of integers; return their sum.

solution:
def op_sum(xs):
    r = list(xs)
    return sum(r)


split: train

prompt: Take a list of integers; return the maximum (0 if empty).

solution:
def op_max(xs):
    r = list(xs)
    return max(r) if r else 0


split: train

prompt: Take a list of integers; return how many remain.

solution:
def op_len(xs):
    r = list(xs)
    return len(r)


split: train

prompt: Take a list of integers; return the count.

solution:
def op_cnt(xs):
    r = list(xs)
    return sum(1 for _ in r)


primitives: evens pos

split: train

prompt: Take a list of integers; keep the even numbers, then keep the positive numbers.

solution:
def op_evens_pos(xs):
    r = list(xs)
    r = [x for x in r if x % 2 == 0]
    r = [x for x in r if x > 0]
    return r


primitives: pos double

split: train

prompt: Take a list of integers; keep the positive numbers, then double each.

solution:
def op_pos_double(xs):
    r = list(xs)
    r = [x for x in r if x > 0]
    r = [x * 2 for x in r]
    return r


primitives: double square

split: train

prompt: Take a list of integers; double each, then square each.

solution:
def op_double_square(xs):
    r = list(xs)
    r = [x * 2 for x in r]
    r = [x * x for x in r]
    return r


primitives: square inc

split: train

prompt: Take a list of integers; square each, then add one to each.

solution:
def op_square_inc(xs):
    r = list(xs)
    r = [x * x for x in r]
    r = [x + 1 for x in r]
    return r


primitives: inc negate

split: train

prompt: Take a list of integers; add one to each, then negate each.

solution:
def op_inc_negate(xs):
    r = list(xs)
    r = [x + 1 for x in r]
    r = [-x for x in r]
    return r


primitives: negate absval

split: train

prompt: Take a list of integers; negate each, then take the absolute value of each.

solution:
def op_negate_absval(xs):
    r = list(xs)
    r = [-x for x in r]
    r = [abs(x) for x in r]
    return r

tests:
assert op_negate_absval([1, 2, 3, 4]) == [1, 2, 3, 4]
assert op_negate_absval([]) == []
assert op_negate_absval([-2, -1, 0, 1, 2]) == [2, 1, 0, 1, 2]
assert op_negate_absval([5, 5, 5]) == [5, 5, 5]
assert op_negate_absval([3, 1, 2]) == [3, 1, 2]
assert op_negate_absval([10]) == [10]
assert op_negate_absval([2, 4, 6]) == [2, 4, 6]
assert op_negate_absval([-7]) == [7]


primitives: absval rev

split: train

prompt: Take a list of integers; take the absolute value of each, then reverse the order.

solution:
def op_absval_rev(xs):
    r = list(xs)
    r = [abs(x) for x in r]
    r = list(reversed(r))
    return r


primitives: rev sorta

split: train

prompt: Take a list of integers; reverse the order, then sort ascending.

solution:
def op_rev_sorta(xs):
    r = list(xs)
    r = list(reversed(r))
    r = sorted(r)
    return r


primitives: sorta sortd

split: train

prompt: Take a list of integers; sort ascending, then sort descending.

solution:
def op_sorta_sortd(xs):
    r = list(xs)
    r = sorted(r)
    r = sorted(r, reverse=True)
    return r


primitives: sortd uniq

split: train

prompt: Take a list of integers; sort descending, then drop duplicates keeping first occurrence.

solution:
def op_sortd_uniq(xs):
    r = list(xs)
    r = sorted(r, reverse=True)
    r = list(dict.fromkeys(r))
    return r


primitives: uniq dec

split: train

prompt: Take a list of integers; drop duplicates keeping first occurrence, then subtract one from each.

solution:
def op_uniq_dec(xs):
    r = list(xs)
    r = list(dict.fromkeys(r))
    r = [x - 1 for x in r]
    return r


primitives: evens sum

split: train

prompt: Take a list of integers; keep the even numbers, then return their sum.

solution:
def op_evens_sum(xs):
    r = list(xs)
    r = [x for x in r if x % 2 == 0]
    return sum(r)

tests:
assert op_evens_sum([1, 2, 3, 4]) == 6
assert op_evens_sum([]) == 0
assert op_evens_sum([-2, -1, 0, 1, 2]) == 0
assert op_evens_sum([5, 5, 5]) == 0
assert op_evens_sum([3, 1, 2]) == 2
assert op_evens_sum([10]) == 10
assert op_evens_sum([2, 4, 6]) == 12
assert op_evens_sum([-7]) == 0


primitives: pos max

split: train

prompt: Take a list of integers; keep the positive numbers, then return the maximum (0 if empty).

solution:
def op_pos_max(xs):
    r = list(xs)
    r = [x for x in r if x > 0]
    return max(r) if r else 0

tests:
assert op_pos_max([1, 2, 3, 4]) == 4
assert op_pos_max([]) == 0
assert op_pos_max([-2, -1, 0, 1, 2]) == 2
assert op_pos_max([5, 5, 5]) == 5
assert op_pos_max([3, 1, 2]) == 3
assert op_pos_max([10]) == 10
assert op_pos_max([2, 4, 6]) == 6
assert op_pos_max([-7]) == 0


primitives: double len

split: train

prompt: Take a list of integers; double each, then return how many remain.

solution:
def op_double_len(xs):
    r = list(xs)
    r = [x * 2 for x in r]
    return len(r)

tests:
assert op_double_len([1, 2, 3, 4]) == 4
assert op_double_len([]) == 0
assert op_double_len([-2, -1, 0, 1, 2]) == 5
assert op_double_len([5, 5, 5]) == 3
assert op_double_len([3, 1, 2]) == 3
assert op_double_len([10]) == 1
assert op_double_len([2, 4, 6]) == 3
assert op_double_len([-7]) == 1


primitives: square cnt

split: train

prompt: Take a list of integers; square each, then return the count.

solution:
def op_square_cnt(xs):
    r = list(xs)
    r = [x * x for x in r]
    return sum(1 for _ in r)

tests:
assert op_square_cnt([1, 2, 3, 4]) == 4
assert op_square_cnt([]) == 0
assert op_square_cnt([-2, -1, 0, 1, 2]) == 5
assert op_square_cnt([5, 5, 5]) == 3
assert op_square_cnt([3, 1, 2]) == 3
assert op_square_cnt([10]) == 1
assert op_square_cnt([2, 4, 6]) == 3
assert op_square_cnt([-7]) == 1


primitives: inc sum

split: train

prompt: Take a list of integers; add one to each, then return their sum.

solution:
def op_inc_sum(xs):
    r = list(xs)
    r = [x + 1 for x in r]
    return sum(r)


primitives: negate max

split: train

prompt: Take a list of integers; negate each, then return the maximum (0 if empty).

solution:
def op_negate_max(xs):
    r = list(xs)
    r = [-x for x in r]
    return max(r) if r else 0

tests:
assert op_negate_max([1, 2, 3, 4]) == -1
assert op_negate_max([]) == 0
assert op_negate_max([-2, -1, 0, 1, 2]) == 2
assert op_negate_max([5, 5, 5]) == -5
assert op_negate_max([3, 1, 2]) == -1
assert op_negate_max([10]) == -10
assert op_negate_max([2, 4, 6]) == -2
assert op_negate_max([-7]) == 7


primitives: absval len

split: train

prompt: Take a list of integers; take the absolute value of each, then return how many remain.

solution:
def op_absval_len(xs):
    r = list(xs)
    r = [abs(x) for x in r]
    return len(r)

tests:
assert op_absval_len([1, 2, 3, 4]) == 4
assert op_absval_len([]) == 0
assert op_absval_len([-2, -1, 0, 1, 2]) == 5
assert op_absval_len([5, 5, 5]) == 3
assert op_absval_len([3, 1, 2]) == 3
assert op_absval_len([10]) == 1
assert op_absval_len([2, 4, 6]) == 3
assert op_absval_len([-7]) == 1


primitives: rev cnt

split: train

prompt: Take a list of integers; reverse the order, then return the count.

solution:
def op_rev_cnt(xs):
    r = list(xs)
    r = list(reversed(r))
    return sum(1 for _ in r)

tests:
assert op_rev_cnt([1, 2, 3, 4]) == 4
assert op_rev_cnt([]) == 0
assert op_rev_cnt([-2, -1, 0, 1, 2]) == 5
assert op_rev_cnt([5, 5, 5]) == 3
assert op_rev_cnt([3, 1, 2]) == 3
assert op_rev_cnt([10]) == 1
assert op_rev_cnt([2, 4, 6]) == 3
assert op_rev_cnt([-7]) == 1


primitives: sorta sum

split: train

prompt: Take a list of integers; sort ascending, then return their sum.

solution:
def op_sorta_sum(xs):
    r = list(xs)
    r = sorted(r)
    return sum(r)

tests:
assert op_sorta_sum([1, 2, 3, 4]) == 10
assert op_sorta_sum([]) == 0
assert op_sorta_sum([-2, -1, 0, 1, 2]) == 0
assert op_sorta_sum([5, 5, 5]) == 15
assert op_sorta_sum([3, 1, 2]) == 6
assert op_sorta_sum([10]) == 10
assert op_sorta_sum([2, 4, 6]) == 12
assert op_sorta_sum([-7]) == -7


primitives: sortd max

split: train

prompt: Take a list of integers; sort descending, then return the maximum (0 if empty).

solution:
def op_sortd_max(xs):
    r = list(xs)
    r = sorted(r, reverse=True)
    return max(r) if r else 0

tests:
assert op_sortd_max([1, 2, 3, 4]) == 4
assert op_sortd_max([]) == 0
assert op_sortd_max([-2, -1, 0, 1, 2]) == 2
assert op_sortd_max([5, 5, 5]) == 5
assert op_sortd_max([3, 1, 2]) == 3
assert op_sortd_max([10]) == 10
assert op_sortd_max([2, 4, 6]) == 6
assert op_sortd_max([-7]) == -7


primitives: uniq len

split: train

prompt: Take a list of integers; drop duplicates keeping first occurrence, then return how many remain.

solution:
def op_uniq_len(xs):
    r = list(xs)
    r = list(dict.fromkeys(r))
    return len(r)

tests:
assert op_uniq_len([1, 2, 3, 4]) == 4
assert op_uniq_len([]) == 0
assert op_uniq_len([-2, -1, 0, 1, 2]) == 5
assert op_uniq_len([5, 5, 5]) == 1
assert op_uniq_len([3, 1, 2]) == 3
assert op_uniq_len([10]) == 1
assert op_uniq_len([2, 4, 6]) == 3
assert op_uniq_len([-7]) == 1


primitives: dec cnt

split: train

prompt: Take a list of integers; subtract one from each, then return the count.

solution:
def op_dec_cnt(xs):
    r = list(xs)
    r = [x - 1 for x in r]
    return sum(1 for _ in r)

tests:
assert op_dec_cnt([1, 2, 3, 4]) == 4
assert op_dec_cnt([]) == 0
assert op_dec_cnt([-2, -1, 0, 1, 2]) == 5
assert op_dec_cnt([5, 5, 5]) == 3
assert op_dec_cnt([3, 1, 2]) == 3
assert op_dec_cnt([10]) == 1
assert op_dec_cnt([2, 4, 6]) == 3
assert op_dec_cnt([-7]) == 1


primitives: evens pos sum

split: train

prompt: Take a list of integers; keep the even numbers, then keep the positive numbers, then return their sum.

solution:
def op_evens_pos_sum(xs):
    r = list(xs)
    r = [x for x in r if x % 2 == 0]
    r = [x for x in r if x > 0]
    return sum(r)

tests:
assert op_evens_pos_sum([1, 2, 3, 4]) == 6
assert op_evens_pos_sum([]) == 0
assert op_evens_pos_sum([-2, -1, 0, 1, 2]) == 2
assert op_evens_pos_sum([5, 5, 5]) == 0
assert op_evens_pos_sum([3, 1, 2]) == 2
assert op_evens_pos_sum([10]) == 10
assert op_evens_pos_sum([2, 4, 6]) == 12
assert op_evens_pos_sum([-7]) == 0


primitives: double square len

split: train

prompt: Take a list of integers; double each, then square each, then return how many remain.

solution:
def op_double_square_len(xs):
    r = list(xs)
    r = [x * 2 for x in r]
    r = [x * x for x in r]
    return len(r)

tests:
assert op_double_square_len([1, 2, 3, 4]) == 4
assert op_double_square_len([]) == 0
assert op_double_square_len([-2, -1, 0, 1, 2]) == 5
assert op_double_square_len([5, 5, 5]) == 3
assert op_double_square_len([3, 1, 2]) == 3
assert op_double_square_len([10]) == 1
assert op_double_square_len([2, 4, 6]) == 3
assert op_double_square_len([-7]) == 1


primitives: inc negate sum

split: train

prompt: Take a list of integers; add one to each, then negate each, then return their sum.

solution:
def op_inc_negate_sum(xs):
    r = list(xs)
    r = [x + 1 for x in r]
    r = [-x for x in r]
    return sum(r)

tests:
assert op_inc_negate_sum([1, 2, 3, 4]) == -14
assert op_inc_negate_sum([]) == 0
assert op_inc_negate_sum([-2, -1, 0, 1, 2]) == -5
assert op_inc_negate_sum([5, 5, 5]) == -18
assert op_inc_negate_sum([3, 1, 2]) == -9
assert op_inc_negate_sum([10]) == -11
assert op_inc_negate_sum([2, 4, 6]) == -15
assert op_inc_negate_sum([-7]) == 6


primitives: absval rev len

split: train

prompt: Take a list of integers; take the absolute value of each, then reverse the order, then return how many remain.

solution:
def op_absval_rev_len(xs):
    r = list(xs)
    r = [abs(x) for x in r]
    r = list(reversed(r))
    return len(r)

tests:
assert op_absval_rev_len([1, 2, 3, 4]) == 4
assert op_absval_rev_len([]) == 0
assert op_absval_rev_len([-2, -1, 0, 1, 2]) == 5
assert op_absval_rev_len([5, 5, 5]) == 3
assert op_absval_rev_len([3, 1, 2]) == 3
assert op_absval_rev_len([10]) == 1
assert op_absval_rev_len([2, 4, 6]) == 3
assert op_absval_rev_len([-7]) == 1


primitives: sorta sortd sum

split: train

prompt: Take a list of integers; sort ascending, then sort descending, then return their sum.

solution:
def op_sorta_sortd_sum(xs):
    r = list(xs)
    r = sorted(r)
    r = sorted(r, reverse=True)
    return sum(r)

tests:
assert op_sorta_sortd_sum([1, 2, 3, 4]) == 10
assert op_sorta_sortd_sum([]) == 0
assert op_sorta_sortd_sum([-2, -1, 0, 1, 2]) == 0
assert op_sorta_sortd_sum([5, 5, 5]) == 15
assert op_sorta_sortd_sum([3, 1, 2]) == 6
assert op_sorta_sortd_sum([10]) == 10
assert op_sorta_sortd_sum([2, 4, 6]) == 12
assert op_sorta_sortd_sum([-7]) == -7


primitives: uniq dec len

split: train

prompt: Take a list of integers; drop duplicates keeping first occurrence, then subtract one from each, then return how many remain.

solution:
def op_uniq_dec_len(xs):
    r = list(xs)
    r = list(dict.fromkeys(r))
    r = [x - 1 for x in r]
    return len(r)

tests:
assert op_uniq_dec_len([1, 2, 3, 4]) == 4
assert op_uniq_dec_len([]) == 0
assert op_uniq_dec_len([-2, -1, 0, 1, 2]) == 5
assert op_uniq_dec_len([5, 5, 5]) == 1
assert op_uniq_dec_len([3, 1, 2]) == 3
assert op_uniq_dec_len([10]) == 1
assert op_uniq_dec_len([2, 4, 6]) == 3
assert op_uniq_dec_len([-7]) == 1


primitives: evens double

split: heldout

prompt: Take a list of integers; keep the even numbers, then double each.

solution:
def op_evens_double(xs):
    r = list(xs)
    r = [x for x in r if x % 2 == 0]
    r = [x * 2 for x in r]
    return r

tests:
assert op_evens_double([1, 2, 3, 4]) == [4, 8]
assert op_evens_double([]) == []
assert op_evens_double([-2, -1, 0, 1, 2]) == [-4, 0, 4]
assert op_evens_double([5, 5, 5]) == []
assert op_evens_double([3, 1, 2]) == [4]
assert op_evens_double([10]) == [20]
assert op_evens_double([2, 4, 6]) == [4, 8, 12]
assert op_evens_double([-7]) == []


primitives: pos square

split: heldout

prompt: Take a list of integers; keep the positive numbers, then square each.

solution:
def op_pos_square(xs):
    r = list(xs)
    r = [x for x in r if x > 0]
    r = [x * x for x in r]
    return r


primitives: double inc

split: heldout

prompt: Take a list of integers; double each, then add one to each.

solution:
def op_double_inc(xs):
    r = list(xs)
    r = [x * 2 for x in r]
    r = [x + 1 for x in r]
    return r


primitives: square negate

split: heldout

prompt: Take a list of integers; square each, then negate each.

solution:
def op_square_negate(xs):
    r = list(xs)
    r = [x * x for x in r]
    r = [-x for x in r]
    return r


primitives: inc absval

split: heldout

prompt: Take a list of integers; add one to each, then take the absolute value of each.

solution:
def op_inc_absval(xs):
    r = list(xs)
    r = [x + 1 for x in r]
    r = [abs(x) for x in r]
    return r


primitives: negate rev

split: heldout

prompt: Take a list of integers; negate each, then reverse the order.

solution:
def op_negate_rev(xs):
    r = list(xs)
    r = [-x for x in r]
    r = list(reversed(r))
    return r


primitives: absval sorta

split: heldout

prompt: Take a list of integers; take the absolute value of each, then sort ascending.

solution:
def op_absval_sorta(xs):
    r = list(xs)
    r = [abs(x) for x in r]
    r = sorted(r)
    return r

tests:
assert op_absval_sorta([1, 2, 3, 4]) == [1, 2, 3, 4]
assert op_absval_sorta([]) == []
assert op_absval_sorta([-2, -1, 0, 1, 2]) == [0, 1, 1, 2, 2]
assert op_absval_sorta([5, 5, 5]) == [5, 5, 5]
assert op_absval_sorta([3, 1, 2]) == [1, 2, 3]
assert op_absval_sorta([10]) == [10]
assert op_absval_sorta([2, 4, 6]) == [2, 4, 6]
assert op_absval_sorta([-7]) == [7]


primitives: rev sortd

split: heldout

prompt: Take a list of integers; reverse the order, then sort descending.

solution:
def op_rev_sortd(xs):
    r = list(xs)
    r = list(reversed(r))
    r = sorted(r, reverse=True)
    return r


primitives: sorta uniq

split: heldout

prompt: Take a list of integers; sort ascending, then drop duplicates keeping first occurrence.

solution:
def op_sorta_uniq(xs):
    r = list(xs)
    r = sorted(r)
    r = list(dict.fromkeys(r))
    return r


primitives: sortd dec

split: heldout

prompt: Take a list of integers; sort descending, then subtract one from each.

solution:
def op_sortd_dec(xs):
    r = list(xs)
    r = sorted(r, reverse=True)
    r = [x - 1 for x in r]
    return r


primitives: evens len

split: heldout

prompt: Take a list of integers; keep the even numbers, then return how many remain.

solution:
def op_evens_len(xs):
    r = list(xs)
    r = [x for x in r if x % 2 == 0]
    return len(r)

tests:
assert op_evens_len([1, 2, 3, 4]) == 2
assert op_evens_len([]) == 0
assert op_evens_len([-2, -1, 0, 1, 2]) == 3
assert op_evens_len([5, 5, 5]) == 0
assert op_evens_len([3, 1, 2]) == 1
assert op_evens_len([10]) == 1
assert op_evens_len([2, 4, 6]) == 3
assert op_evens_len([-7]) == 0


primitives: pos cnt

split: heldout

prompt: Take a list of integers; keep the positive numbers, then return the count.

solution:
def op_pos_cnt(xs):
    r = list(xs)
    r = [x for x in r if x > 0]
    return sum(1 for _ in r)

tests:
assert op_pos_cnt([1, 2, 3, 4]) == 4
assert op_pos_cnt([]) == 0
assert op_pos_cnt([-2, -1, 0, 1, 2]) == 2
assert op_pos_cnt([5, 5, 5]) == 3
assert op_pos_cnt([3, 1, 2]) == 3
assert op_pos_cnt([10]) == 1
assert op_pos_cnt([2, 4, 6]) == 3
assert op_pos_cnt([-7]) == 0


primitives: double sum

split: heldout

prompt: Take a list of integers; double each, then return their sum.

solution:
def op_double_sum(xs):
    r = list(xs)
    r = [x * 2 for x in r]
    return sum(r)

tests:
assert op_double_sum([1, 2, 3, 4]) == 20
assert op_double_sum([]) == 0
assert op_double_sum([-2, -1, 0, 1, 2]) == 0
assert op_double_sum([5, 5, 5]) == 30
assert op_double_sum([3, 1, 2]) == 12
assert op_double_sum([10]) == 20
assert op_double_sum([2, 4, 6]) == 24
assert op_double_sum([-7]) == -14


primitives: square max

split: heldout

prompt: Take a list of integers; square each, then return the maximum (0 if empty).

solution:
def op_square_max(xs):
    r = list(xs)
    r = [x * x for x in r]
    return max(r) if r else 0

tests:
assert op_square_max([1, 2, 3, 4]) == 16
assert op_square_max([]) == 0
assert op_square_max([-2, -1, 0, 1, 2]) == 4
assert op_square_max([5, 5, 5]) == 25
assert op_square_max([3, 1, 2]) == 9
assert op_square_max([10]) == 100
assert op_square_max([2, 4, 6]) == 36
assert op_square_max([-7]) == 49


primitives: inc len

split: heldout

prompt: Take a list of integers; add one to each, then return how many remain.

solution:
def op_inc_len(xs):
    r = list(xs)
    r = [x + 1 for x in r]
    return len(r)

tests:
assert op_inc_len([1, 2, 3, 4]) == 4
assert op_inc_len([]) == 0
assert op_inc_len([-2, -1, 0, 1, 2]) == 5
assert op_inc_len([5, 5, 5]) == 3
assert op_inc_len([3, 1, 2]) == 3
assert op_inc_len([10]) == 1
assert op_inc_len([2, 4, 6]) == 3
assert op_inc_len([-7]) == 1


primitives: negate cnt

split: heldout

prompt: Take a list of integers; negate each, then return the count.

solution:
def op_negate_cnt(xs):
    r = list(xs)
    r = [-x for x in r]
    return sum(1 for _ in r)

tests:
assert op_negate_cnt([1, 2, 3, 4]) == 4
assert op_negate_cnt([]) == 0
assert op_negate_cnt([-2, -1, 0, 1, 2]) == 5
assert op_negate_cnt([5, 5, 5]) == 3
assert op_negate_cnt([3, 1, 2]) == 3
assert op_negate_cnt([10]) == 1
assert op_negate_cnt([2, 4, 6]) == 3
assert op_negate_cnt([-7]) == 1


primitives: absval sum

split: heldout

prompt: Take a list of integers; take the absolute value of each, then return their sum.

solution:
def op_absval_sum(xs):
    r = list(xs)
    r = [abs(x) for x in r]
    return sum(r)

tests:
assert op_absval_sum([1, 2, 3, 4]) == 10
assert op_absval_sum([]) == 0
assert op_absval_sum([-2, -1, 0, 1, 2]) == 6
assert op_absval_sum([5, 5, 5]) == 15
assert op_absval_sum([3, 1, 2]) == 6
assert op_absval_sum([10]) == 10
assert op_absval_sum([2, 4, 6]) == 12
assert op_absval_sum([-7]) == 7


primitives: rev max

split: heldout

prompt: Take a list of integers; reverse the order, then return the maximum (0 if empty).

solution:
def op_rev_max(xs):
    r = list(xs)
    r = list(reversed(r))
    return max(r) if r else 0

tests:
assert op_rev_max([1, 2, 3, 4]) == 4
assert op_rev_max([]) == 0
assert op_rev_max([-2, -1, 0, 1, 2]) == 2
assert op_rev_max([5, 5, 5]) == 5
assert op_rev_max([3, 1, 2]) == 3
assert op_rev_max([10]) == 10
assert op_rev_max([2, 4, 6]) == 6
assert op_rev_max([-7]) == -7


primitives: sorta len

split: heldout

prompt: Take a list of integers; sort ascending, then return how many remain.

solution:
def op_sorta_len(xs):
    r = list(xs)
    r = sorted(r)
    return len(r)

tests:
assert op_sorta_len([1, 2, 3, 4]) == 4
assert op_sorta_len([]) == 0
assert op_sorta_len([-2, -1, 0, 1, 2]) == 5
assert op_sorta_len([5, 5, 5]) == 3
assert op_sorta_len([3, 1, 2]) == 3
assert op_sorta_len([10]) == 1
assert op_sorta_len([2, 4, 6]) == 3
assert op_sorta_len([-7]) == 1


primitives: sortd cnt

split: heldout

prompt: Take a list of integers; sort descending, then return the count.

solution:
def op_sortd_cnt(xs):
    r = list(xs)
    r = sorted(r, reverse=True)
    return sum(1 for _ in r)

tests:
assert op_sortd_cnt([1, 2, 3, 4]) == 4
assert op_sortd_cnt([]) == 0
assert op_sortd_cnt([-2, -1, 0, 1, 2]) == 5
assert op_sortd_cnt([5, 5, 5]) == 3
assert op_sortd_cnt([3, 1, 2]) == 3
assert op_sortd_cnt([10]) == 1
assert op_sortd_cnt([2, 4, 6]) == 3
assert op_sortd_cnt([-7]) == 1


primitives: uniq sum

split: heldout

prompt: Take a list of integers; drop duplicates keeping first occurrence, then return their sum.

solution:
def op_uniq_sum(xs):
    r = list(xs)
    r = list(dict.fromkeys(r))
    return sum(r)

tests:
assert op_uniq_sum([1, 2, 3, 4]) == 10
assert op_uniq_sum([]) == 0
assert op_uniq_sum([-2, -1, 0, 1, 2]) == 0
assert op_uniq_sum([5, 5, 5]) == 5
assert op_uniq_sum([3, 1, 2]) == 6
assert op_uniq_sum([10]) == 10
assert op_uniq_sum([2, 4, 6]) == 12
assert op_uniq_sum([-7]) == -7


primitives: dec max

split: heldout

prompt: Take a list of integers; subtract one from each, then return the maximum (0 if empty).

solution:
def op_dec_max(xs):
    r = list(xs)
    r = [x - 1 for x in r]
    return max(r) if r else 0

tests:
assert op_dec_max([1, 2, 3, 4]) == 3
assert op_dec_max([]) == 0
assert op_dec_max([-2, -1, 0, 1, 2]) == 1
assert op_dec_max([5, 5, 5]) == 4
assert op_dec_max([3, 1, 2]) == 2
assert op_dec_max([10]) == 9
assert op_dec_max([2, 4, 6]) == 5
assert op_dec_max([-7]) == -8