generated from public/aoc_template
Day 21 - some fiddling around
This commit is contained in:
parent
83f612ce9a
commit
8910705d2e
52
day21.py
52
day21.py
@ -1,7 +1,9 @@
|
|||||||
|
import math
|
||||||
from collections import deque, defaultdict
|
from collections import deque, defaultdict
|
||||||
from tools.aoc import AOCDay
|
from tools.aoc import AOCDay
|
||||||
from tools.coordinate import Coordinate
|
from tools.coordinate import Coordinate, Line
|
||||||
from tools.grid import Grid
|
from tools.grid import Grid
|
||||||
|
from tools.visualization import Window
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
@ -42,46 +44,48 @@ class Day(AOCDay):
|
|||||||
[
|
[
|
||||||
# (16733044, "input21_test"),
|
# (16733044, "input21_test"),
|
||||||
(None, "input21"),
|
(None, "input21"),
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
def parse_input(self) -> (Grid, Coordinate):
|
def parse_input(self) -> (Grid, Coordinate):
|
||||||
grid = Grid().from_data(self.getInput(), translate={'.': True, '#': False})
|
grid = Grid().from_data(self.getInput(), translate={".": True, "#": False})
|
||||||
start = None
|
start = None
|
||||||
for x in grid.getActiveCells():
|
for x in grid.find("S"):
|
||||||
if grid.get(x) == 'S':
|
|
||||||
start = x
|
start = x
|
||||||
grid.set(x, True)
|
grid.set(x, True)
|
||||||
|
break # there is only one S
|
||||||
|
|
||||||
return grid, start
|
return grid, start
|
||||||
|
|
||||||
def part1(self) -> Any:
|
def part1(self) -> Any:
|
||||||
needed_steps = 6 if 'test' in self._current_test_file else 64
|
needed_steps = 6 if self.is_test() else 64
|
||||||
grid, start = self.parse_input()
|
grid, start = self.parse_input()
|
||||||
return walk(grid, start, needed_steps)
|
return walk(grid, start, needed_steps)
|
||||||
|
|
||||||
def part2(self) -> Any:
|
def part2(self) -> Any:
|
||||||
grid, start = self.parse_input()
|
grid, start = self.parse_input()
|
||||||
needed_steps = 5000 if 'test' in self._current_test_file else 26501365
|
print(grid.getOnCount())
|
||||||
k = walk(grid, start, len(self.getInput()))
|
for i in [Coordinate(0, 65), Coordinate(65, 0), Coordinate(130, 65), Coordinate(65, 130)]:
|
||||||
g = walk(grid, start, 2 * len(self.getInput()))
|
t = walk(grid, i, 131) # this always yields 14746 ... coincidence?
|
||||||
v = walk(grid, start, 3 * len(self.getInput()))
|
print(f"{i} = {t}")
|
||||||
print(k, g, v, g-k, v-g)
|
|
||||||
return ""
|
for i in [Coordinate(0, 0), Coordinate(130, 0), Coordinate(0, 130), Coordinate(130, 130)]:
|
||||||
j = 0
|
t = walk(grid, i, 65)
|
||||||
mem = defaultdict(list)
|
print(f"{i} = {t}")
|
||||||
for i in range(1, 250, 2):
|
needed_steps = 5000 if self.is_test() else 26501365
|
||||||
k = walk(grid, start, i)
|
t = walk(grid, start, 64)
|
||||||
diff = k - j
|
k = walk(grid, start, len(self.getInput()) + 65)
|
||||||
j = k
|
g = walk(grid, start, 2 * len(self.getInput()) + 65)
|
||||||
mem[diff].append(i)
|
# v = walk(grid, start, (3 * len(self.getInput())) - 1)
|
||||||
print(i, "=>", k, "diff", diff, "mod", k % 81)
|
print(f"65={t}, 196={k}, 327={g}, {math.log(k)=}, {math.log(g)=}")
|
||||||
for k, v in mem.items():
|
print(((k - t) / 14746) * 3)
|
||||||
if len(v) > 1:
|
print((g - t) / 14746)
|
||||||
print(k, "=>", v)
|
print((g - k) / 14746)
|
||||||
|
print(g % k)
|
||||||
|
print(k / t)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
day = Day(2023, 21)
|
day = Day(2023, 21)
|
||||||
day.run(verbose=True)
|
day.run(verbose=True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user