Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions pipeline/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
### Basic functions

import copy


def increment(inp):
# list-of-int -> list-of-int #
return [each + 1 for each in inp]


def decrement(inp):
# list-of-int -> list-of-int #
return [each - 1 for each in inp]


def multiply_by_five(inp):
# list-of-int -> list-of-int #
return [each * 5 for each in inp]


def delete_last(inp):
# list-of-int -> list-of-int #
inp.pop()
return inp


def sum_list(inp):
# list-of-int -> int #
accu = 0
for each in inp:
accu += each
return accu


def max_val(inp):
# list-of-int -> int #
return max(inp)


def lenght(inp):
# list-of-int -> int #
return len(inp)


def average(inp):
# list-of-int -> int #
return sum_list(inp) / len(inp)


def add_zero_to_end(inp):
# list-of-int -> list-of-int #
inp.append(0)
return inp

### Intermidiet functions

def count_ones(inp):
# list-of-int -> int #
accu = 0
for each in inp:
if each == 1:
accu += 1
return accu


def reverse_list(inp):
# list-of-int -> list-of-int #
return inp[::-1]


def mirror(inp):
# list-of-int -> list-of-int #
return inp + inp[::-1]


def exchange_fours_to_ones(inp):
# list-of-int -> list-of-int #
for i in range(len(inp)):
if inp[i] == 4:
inp[i] = 1
return inp


def delete_even_indx(inp):
# list-of-int -> list-of-int #
del inp[1::2]
return inp


def copy_list(inp):
# list-of-int -> list-of-int #
return inp + inp


### Advanced

def change_max_val_to_zero(inp):
# list-of-int -> list-of-int #
for i in range(len(inp)):
if inp[i] == max(inp):
inp[i] = 0
return inp


def add_zero_if_ends_with_6(inp):
# list-of-int -> list-of-int #
if inp[len(inp) - 1] == 6:
inp.append(0)
return inp


def if_contains_3_do_reverse(inp):
# list-of-int -> list-of-int #
if 3 in inp:
return inp[::-1]
else:
return inp




9 changes: 9 additions & 0 deletions pipeline/tokens/function_name_tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"increment" : ["increment", "next", "increase", "add_one"],
"decrement" : ["decrement", "previous", "decrease", "subtract_one"],
"sum" : ["sum_all", "add_all", "summation"],
"append" : ["append", "add_element", "insert_to_tail"],
"remove" : ["remove", "delete_element", "delete_el"],
"len" : ["lenght", "len"],
"concatenate" : ["connect", "join", "concatenate", "combine_two"]
}
17 changes: 17 additions & 0 deletions pipeline/tokens/primitives_tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

{
"++" : ["<variable>++", "<variable> += 1", "<variable> = <variable> + 1"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i++ and i-- are not legal operations in python unfortunatelly

"--" : ["<variable>--", "<variable> -= 1", "<variable> = <variable> - 1"],
"append" : ["<variable1>.append(<variable2>)", "<variable1> +[<variable2>]"],
"remove" : ["<variable1>.remove(<variable2>)", "<variable1> +[<variable2>]"],
Copy link
Collaborator

@Goshagosha Goshagosha Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<variable1> +[<variable2>] is not remove

"concatenate" : ["<variable1> + <variable2>", "<variable1>.extend(<variable2>)"]

}








10 changes: 10 additions & 0 deletions pipeline/tokens/variables_tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"i" : ["i", "k", "index", "counter"],
"v" : ["var", "variable", "v"],
"t" : ["tem", "temp", "t"],
"list" : ["l", "list"],
"number" : ["number", "num", "n"],
"object" : ["object", "obj", "o"],
"accu" : ["accumulated", "accu", "summed"]
}