Solution to problem 7 in Python

This commit is contained in:
David Doblas Jiménez 2022-03-10 14:28:49 +01:00
parent b12d1031a7
commit 174fe20026

View File

@ -81,7 +81,7 @@ def rshift_gate(x: int, y: int) -> int:
@functools.lru_cache() @functools.lru_cache()
def rec_solve(node): def rec_solve(node: str) -> int:
if node.isdigit(): if node.isdigit():
return int(node) return int(node)
instruction = gates[node] instruction = gates[node]
@ -109,7 +109,7 @@ for instr in instructions:
gates[rhs.strip()] = lhs.strip().split() gates[rhs.strip()] = lhs.strip().split()
def part_1(): def part_1() -> None:
signal_a = rec_solve("a") signal_a = rec_solve("a")
print(f"Signal A will be ultimately {signal_a}") print(f"Signal A will be ultimately {signal_a}")
@ -121,7 +121,7 @@ def part_1():
# provided to wire a? # provided to wire a?
def part_2(): def part_2() -> None:
signal_a = rec_solve("a") signal_a = rec_solve("a")
rec_solve.cache_clear() rec_solve.cache_clear()
gates["b"] = [str(signal_a)] gates["b"] = [str(signal_a)]