Cleaned up 2024/24 P1
This commit is contained in:
parent
6ff341175f
commit
add8230d4b
@ -39,14 +39,13 @@ def returnLogic(x,logic,y,z,gates):
|
||||
# #
|
||||
#########################################
|
||||
def part1():
|
||||
gates, instructions = loadGates(input_f)
|
||||
|
||||
#print(gates)
|
||||
#print(instructions)
|
||||
wait_for = []
|
||||
for inst in instructions:
|
||||
|
||||
x,logic,y,z = inst
|
||||
gates, instructions = loadGates(input_f)
|
||||
|
||||
while instructions or wait_for:
|
||||
if len(instructions) > 0:
|
||||
inst = instructions.pop(0)
|
||||
x,logic,y,z = inst
|
||||
|
||||
if x not in gates or y not in gates:
|
||||
wait_for.append(inst)
|
||||
@ -62,13 +61,6 @@ def part1():
|
||||
|
||||
gates[z] = returnLogic(x,logic,y,z,gates)
|
||||
|
||||
while len(wait_for) > 0:
|
||||
for wdx, w in enumerate(wait_for):
|
||||
x,logic,y,z = w
|
||||
if x in gates and y in gates:
|
||||
gates[z] = returnLogic(x,logic,y,z,gates)
|
||||
wait_for.pop(wdx)
|
||||
|
||||
result = ''
|
||||
|
||||
countZ = 0
|
||||
@ -78,11 +70,7 @@ def part1():
|
||||
countZ += 1
|
||||
|
||||
for i in range(countZ-1,-1,-1):
|
||||
if i < 10:
|
||||
result += str(gates['z0'+str(i)])
|
||||
else:
|
||||
result += str(gates['z'+str(i)])
|
||||
#print(result)
|
||||
result += str(gates[f"z{i:02}"])
|
||||
return int(result, 2)
|
||||
|
||||
start_time = time.time()
|
||||
|
Loading…
Reference in New Issue
Block a user