codyssi2024/problem2.py
2025-03-14 09:20:40 +01:00

39 lines
891 B
Python

my_input = open("inputs/input_2", "r").read().split("\n")
my_input = list(map(lambda x: True if x == "TRUE" else False, my_input))
p1 = 0
for i, x in enumerate(my_input):
if x:
p1 += (i + 1)
def solve_gates(inputs: list[bool]) -> list[bool]:
result_gates = []
is_or = False
for i in range(0, len(inputs), 2):
if is_or:
if my_input[i] or my_input[i + 1]:
result_gates.append(True)
else:
result_gates.append(False)
else:
if my_input[i] and my_input[i + 1]:
result_gates.append(True)
else:
result_gates.append(False)
is_or = not is_or
return result_gates
p2 = sum(solve_gates(my_input))
p3 = sum(my_input)
while len(my_input) > 1:
my_input = solve_gates(my_input)
p3 += sum(my_input)
print(p1)
print(p2)
print(p3)