p2 done
This commit is contained in:
44
14/n.py
44
14/n.py
@@ -32,23 +32,17 @@ for l in input:
|
|||||||
prev = (y, x)
|
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
|
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
|
X = 500
|
||||||
Y = 0
|
Y = 0
|
||||||
current = nextdown((Y, X))
|
current = (Y, X)
|
||||||
|
# print(current)
|
||||||
|
|
||||||
moving = True
|
moving = True
|
||||||
while (moving):
|
while (moving):
|
||||||
|
|
||||||
@@ -56,19 +50,23 @@ while cont:
|
|||||||
left = (current[0]+1, current[1]-1)
|
left = (current[0]+1, current[1]-1)
|
||||||
right = (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
|
current = down
|
||||||
if current[0] >= floor:
|
if current[0] >= floor:
|
||||||
cont = False
|
|
||||||
moving = False
|
moving = False
|
||||||
|
elif left not in cave:
|
||||||
elif not left in cave:
|
|
||||||
current = left
|
current = left
|
||||||
elif not right in cave:
|
elif right not in cave:
|
||||||
current = right
|
current = right
|
||||||
else:
|
else:
|
||||||
cave.add(current)
|
break
|
||||||
moving = False
|
|
||||||
|
|
||||||
# print(sorted(cave))
|
if current == (0, 500):
|
||||||
print(len(cave)-emptycave)
|
print("p2:", s+1)
|
||||||
|
break
|
||||||
|
|
||||||
|
cave.add(current)
|
||||||
|
|||||||
Reference in New Issue
Block a user