Solve day 20 and day 21 part 1.

This commit is contained in:
2023-12-26 21:46:55 -05:00
parent 0d1b3fbc2c
commit c5813e168b
2 changed files with 163 additions and 0 deletions

55
d21.py Normal file
View File

@@ -0,0 +1,55 @@
from lib import *
EXAMPLE = """
...........
.....###.#.
.###.##..#.
..#.#...#..
....#.#....
.##..S####.
.##..#...#.
.......##..
.##.#.####.
.##..##.##.
...........
"""
def solve(i: Input, second=False):
res = 0
g = i.grid2()
s = g.find('S')[0]
g[s] = 'O'
# steps = 64
steps = 26501365
seen = set()
for i in range(steps):
os = tuple(g.find('O'))
if os in seen:
seen.add(os)
print(f"SEEN {i}")
break
for o in os:
g[o] = '.'
for o in os:
for nb in g.neighbors_ort(o):
if not g[nb] == "#":
g[nb] = 'O'
return len(g.find('O'))
def main():
DAY_INPUT = "i21.txt"
print("Example 1:", solve(Input(EXAMPLE)))
print("Solution 1:", solve(Input(DAY_INPUT)))
return
print("Example 2:", solve(Input(EXAMPLE), True))
return
print("Solution 2:", solve(Input(DAY_INPUT), True))
return
if __name__ == "__main__":
main()