Skip to content

Commit 25aa660

Browse files
feat: Add recursive implication function for lists
1 parent 6e1a104 commit 25aa660

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

boolean_algebra/imply_gate.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ def imply_gate(input_1: int, input_2: int) -> int:
3333
return int(input_1 == 0 or input_2 == 1)
3434

3535

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+
3662
if __name__ == "__main__":
3763
import doctest
3864

0 commit comments

Comments
 (0)