advent_of_code/2024/day18/main.py

66 lines
1.4 KiB
Python
Raw Normal View History

2024-12-18 06:42:31 -05:00
import sys
import math
import os
sys.path.insert(1, os.path.abspath('../../'))
from python_tools.aoc_utils import *
START = [0,0]
# INPUTS = ["test.txt", [6,6], 12]
INPUTS = ["input.txt", [70,70,], 1000]
END = INPUTS[1]
def grid_check(x, i):
global END
return ((0 <= x[0] <= END[0]) and (0 <= x[1] <= END[1]) and (x not in i))
def part_one(input):
add = lambda x,y: [x[0]+y[0], x[1]+y[1]]
sub = lambda x,y: [x[0]-y[0], x[1]-y[1]]
mag = lambda x: math.sqrt(x[0]**2 + x[1]**2)
p = [0,0]
G = {}
V = set()
V.add(tuple(p))
G[tuple([mag(sub(END, p)), *p])] = [p]
while True:
keys = list(G.keys())
keys.sort()
print("G", G)
p_list = G.pop(keys[0])
p = p_list[-1]
for x in [[1,0],[-1,0],[0,1],[0,-1]]:
nx = add(x,p)
if nx == END:
print("WE FOUND THE END", len(p_list))
return
print(V)
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]
# if []
pass
def part_two(input):
pass
def main():
f = open(INPUTS[0], 'r')
contents = [list(map(int, x.strip().split(","))) for x in f.readlines()]
print(contents[:INPUTS[2]])
part_one(contents[:INPUTS[2]])
part_two(contents[:INPUTS[2]])
if __name__ == "__main__":
main()