-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_fun.py
More file actions
43 lines (32 loc) · 1.23 KB
/
full_fun.py
File metadata and controls
43 lines (32 loc) · 1.23 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
def generator_fizz_buzz(n):
x = 0
fizz = "Fizz"
buzz = "Buzz"
fizz_buzz = "{}{}".format(fizz, buzz)
fizz_int = 3
buzz_int = 5
show_self = lambda result: result
def get_from_if(expression, if_true_function, if_false_function,
if_true_args, if_false_args):
args = {True: if_true_args, False: if_false_args}
functions = {True: if_true_function, False: if_false_function}
return functions[expression](*args[expression])
def get_answer(i, execute_if, show_function):
is_fizz = i%fizz_int == 0
is_buzz = i%buzz_int == 0
args_for_true = [is_fizz, show_function, show_function,
[fizz_buzz], [buzz]]
args_for_false = [is_fizz, show_function, show_function,
[fizz], [i]]
result = execute_if(is_buzz, execute_if, execute_if,
args_for_true, args_for_false)
yield result
def recursive(i, limit, execute_if, show_function):
next_i = i+1
is_in_limits = next_i < limit-1
args_for_true = [next_i, limit, execute_if, show_function]
args_for_false = [next_i, execute_if, show_function]
yield from get_answer(i, execute_if, show_function)
yield from execute_if(is_in_limits, recursive, get_answer,
args_for_true, args_for_false)
yield from recursive(x, n, get_from_if, show_self)