Solve day 20 and day 21 part 1.
This commit is contained in:
55
d21.py
Normal file
55
d21.py
Normal 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()
|
||||
Reference in New Issue
Block a user