File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,32 @@ def imply_gate(input_1: int, input_2: int) -> int:
33
33
return int (input_1 == 0 or input_2 == 1 )
34
34
35
35
36
+ def recursive_imply_list (input_list : list [int ]) -> int :
37
+ """
38
+ Recursively calculates the implication of a list.
39
+ Strictly The Implication is Applied Consecuteivly left to right:
40
+ ( (a -> b) -> c ) -> d ...
41
+
42
+ >>> recursive_imply_list([])
43
+ 1
44
+ >>> recursive_imply_list([0])
45
+ 0
46
+ >>> recursive_imply_list([1])
47
+ 1
48
+ >>> recursive_imply_list([1, 0, 1])
49
+ 1
50
+ >>> recursive_imply_list([1, 1, 0])
51
+ 0
52
+ """
53
+ if not input_list :
54
+ return 1
55
+ if len (input_list ) == 1 :
56
+ return input_list [0 ]
57
+ first_implication = imply_gate (input_list [0 ], input_list [1 ])
58
+ new_list = [first_implication , * input_list [2 :]]
59
+ return recursive_imply_list (new_list )
60
+
61
+
36
62
if __name__ == "__main__" :
37
63
import doctest
38
64
You can’t perform that action at this time.
0 commit comments