-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursionTest.py
More file actions
56 lines (34 loc) · 1.3 KB
/
recursionTest.py
File metadata and controls
56 lines (34 loc) · 1.3 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
47
48
49
50
51
52
53
54
55
56
# what do we need to do
# make a function with the one parameter
# calls a function that carries the parameter of interest and the recursive function
# define the recursive function when calling the parameter
#what we actually need to do
#make a lambda that takes in function that calls itself and pass in the recursive function wrap all that and give it the parameter
l = [1, 2, 3]
l2 = [l, l, l]
l3 = [l2, l2, l2]
print(l3)
part1 = (lambda recurFunc : lambda recurVals : recurFunc(recurFunc, recurVals))
def part1afunc(recurFunc):
def part1bfunc(vals):
return recurFunc(recurFunc, vals)
return part1bfunc
part2 = part1((lambda fl, y: [x for b in y for x in fl(fl,b)] if type(y) is list else [y]))
def part2func (fl, y):
if type(y) is not list:
return [y]
o = []
for b in y:
for x in part2func(fl,b):
o.append(x)
return o
part2def = part1(part2func)
print(part2(l3))
print(part2def(l3))
print(sum(l3, []))
part2fib = part1afunc((lambda s,x:1 if x==0 else x*s(s,x-1)))
print(part2fib(10))
#print(part1afunc(part2fib)(10))
#a = (lambda g: (lambda f, *a: f(f, *a))(lambda fl, y: [x for b in y for x in fl(fl,b)] if type(y) is list else [y]))(l2)
#print(a)
#(lambda n: (lambda f, *a: f(f, *a))(lambda rec, n: 1 if n == 0 else n*rec(rec, n-1), n))