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():
|
def part1():
|
||||||
gates, instructions = loadGates(input_f)
|
|
||||||
|
|
||||||
#print(gates)
|
|
||||||
#print(instructions)
|
|
||||||
wait_for = []
|
wait_for = []
|
||||||
for inst in instructions:
|
gates, instructions = loadGates(input_f)
|
||||||
|
|
||||||
x,logic,y,z = inst
|
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:
|
if x not in gates or y not in gates:
|
||||||
wait_for.append(inst)
|
wait_for.append(inst)
|
||||||
@ -62,13 +61,6 @@ def part1():
|
|||||||
|
|
||||||
gates[z] = returnLogic(x,logic,y,z,gates)
|
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 = ''
|
result = ''
|
||||||
|
|
||||||
countZ = 0
|
countZ = 0
|
||||||
@ -78,11 +70,7 @@ def part1():
|
|||||||
countZ += 1
|
countZ += 1
|
||||||
|
|
||||||
for i in range(countZ-1,-1,-1):
|
for i in range(countZ-1,-1,-1):
|
||||||
if i < 10:
|
result += str(gates[f"z{i:02}"])
|
||||||
result += str(gates['z0'+str(i)])
|
|
||||||
else:
|
|
||||||
result += str(gates['z'+str(i)])
|
|
||||||
#print(result)
|
|
||||||
return int(result, 2)
|
return int(result, 2)
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
Loading…
Reference in New Issue
Block a user