Part 2 :)

This commit is contained in:
Daniel Weber 2024-12-18 08:47:54 -05:00
parent d050a1a6b3
commit da8d8f6008

View File

@ -1,3 +1,4 @@
import re
import sys
import math
import os
@ -22,7 +23,7 @@ def part_one(input):
V = set()
V.add(tuple(p))
G[tuple([mag(sub(END, p)), *p])] = [p]
while True:
while len(G)>0:
keys = list(G.keys())
keys.sort()
p_list = G.pop(keys[0])
@ -30,21 +31,32 @@ def part_one(input):
for x in [[1,0],[-1,0],[0,1],[0,-1]]:
nx = add(x,p)
if nx == END:
print("P1: ", len(p_list))
return
return len(p_list)
if grid_check(nx, input) and tuple(nx) not in V:
h = tuple([mag(sub(END, nx)), *nx])
V.add(tuple(nx))
G[h] = [*p_list, nx]
return -1
def part_two(input):
pass
result = 0
upper = len(input)
lower = INPUTS[2]
while upper != lower:
test = int(round((upper - lower+0.001)/2))+lower
result = part_one(input[:test])
if result == -1:
upper = test-1
else:
lower = test
print("P2: ", str(input[lower]).strip('[]').replace(" ", ""))
def main():
f = open(INPUTS[0], 'r')
contents = [list(map(int, x.strip().split(","))) for x in f.readlines()]
part_one(contents[:INPUTS[2]])
part_two(contents[:INPUTS[2]])
print("P1: ", part_one(contents[:INPUTS[2]]))
part_two(contents)
if __name__ == "__main__":
main()