This commit is contained in:
2022-12-14 18:46:06 +02:00
parent 37568edf3f
commit 9400f23a40

44
14/n.py
View File

@@ -32,23 +32,17 @@ for l in input:
prev = (y, x)
def nextdown(pos):
possibles = []
for y, x in cave:
if x == pos[1] and y > pos[0]:
possibles.append(y)
return (sorted(possibles)[0]-1, X)
cont = True
emptycave = len(cave)
floor = max(r[0] for r in cave)+2
while cont:
for i in range(-20000, 20000):
cave.add((floor, i))
p1 = False
for s in range(10000000):
X = 500
Y = 0
current = nextdown((Y, X))
current = (Y, X)
# print(current)
moving = True
while (moving):
@@ -56,19 +50,23 @@ while cont:
left = (current[0]+1, current[1]-1)
right = (current[0]+1, current[1]+1)
if not down in cave:
if (current[0]+1 >= floor and not p1):
print("p1:", s)
p1 = True
if down not in cave:
current = down
if current[0] >= floor:
cont = False
moving = False
elif not left in cave:
elif left not in cave:
current = left
elif not right in cave:
elif right not in cave:
current = right
else:
cave.add(current)
moving = False
break
# print(sorted(cave))
print(len(cave)-emptycave)
if current == (0, 500):
print("p2:", s+1)
break
cave.add(current)