-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion.json
More file actions
30 lines (30 loc) · 876 Bytes
/
recursion.json
File metadata and controls
30 lines (30 loc) · 876 Bytes
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
{
"name": "recursion",
"functions": {
"factorial": {
"params": {"n": "int"},
"returns": "int",
"steps": [
{"if": "n <= 1", "then": [{"return": 1}]},
{"let": "sub", "call": "factorial", "with": {"n": "n - 1"}},
{"return": "n * sub"}
]
},
"fibonacci": {
"params": {"n": "int"},
"returns": "int",
"steps": [
{"if": "n <= 0", "then": [{"return": 0}]},
{"if": "n == 1", "then": [{"return": 1}]},
{"let": "a", "call": "fibonacci", "with": {"n": "n - 1"}},
{"let": "b", "call": "fibonacci", "with": {"n": "n - 2"}},
{"return": "a + b"}
]
}
},
"steps": [
{"let": "fact5", "call": "factorial", "with": {"n": "5"}},
{"let": "fib7", "call": "fibonacci", "with": {"n": "7"}},
{"return": "{'factorial_5': fact5, 'fibonacci_7': fib7}"}
]
}