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():
|
||||||
|
wait_for = []
|
||||||
gates, instructions = loadGates(input_f)
|
gates, instructions = loadGates(input_f)
|
||||||
|
|
||||||
#print(gates)
|
while instructions or wait_for:
|
||||||
#print(instructions)
|
if len(instructions) > 0:
|
||||||
wait_for = []
|
inst = instructions.pop(0)
|
||||||
for inst in instructions:
|
x,logic,y,z = inst
|
||||||
|
|
||||||
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