-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenhanced_evolved_functions.py
More file actions
46 lines (39 loc) · 1.06 KB
/
enhanced_evolved_functions.py
File metadata and controls
46 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Automatically generated evolved functions
# Generated by MCTS + Evolution Coding Agent
# Primitive functions (manually implemented)
def add(x, y): return x + y
def sub(x, y): return x - y
def mul(x, y): return x * y
def div(x, y): return x // y if y != 0 else 0
def eq(x, y): return x == y
def lt(x, y): return x < y
def gt(x, y): return x > y
def if_then_else(cond, then_val, else_val): return then_val if cond else else_val
def identity(x): return x
# Evolved functions
# Fitness: 0.850
def factorial(n):
if eq(n, 0):
return 1
else:
return mul(n, factorial(sub(n, 1)))
# Fitness: 0.780
def power(base, exp):
if eq(exp, 0):
return 1
else:
return mul(base, power(base, sub(exp, 1)))
# Fitness: 0.720
def max_two(a, b):
return if_then_else(gt(a, b), a, b)
# Fitness: 0.690
def fib_helper(n):
if lt(n, 2):
return n
else:
return add(fib_helper(sub(n, 1)), fib_helper(sub(n, 2)))
# Fitness: 0.920
def advanced_combo(n):
fact_n = factorial(n)
power_n = power(n, 2)
return max_two(fact_n, power_n)