Solve day7
This commit is contained in:
142
day7/input.txt
Normal file
142
day7/input.txt
Normal file
@@ -0,0 +1,142 @@
|
||||
......................................................................S......................................................................
|
||||
.............................................................................................................................................
|
||||
......................................................................^......................................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................................^.^.....................................................................
|
||||
.............................................................................................................................................
|
||||
....................................................................^.^.^....................................................................
|
||||
.............................................................................................................................................
|
||||
...................................................................^.^.^.^...................................................................
|
||||
.............................................................................................................................................
|
||||
..................................................................^.^.^.^.^..................................................................
|
||||
.............................................................................................................................................
|
||||
.................................................................^.^...^...^.................................................................
|
||||
.............................................................................................................................................
|
||||
................................................................^.^.^.^.^.^.^................................................................
|
||||
.............................................................................................................................................
|
||||
...............................................................^.......^...^.^...............................................................
|
||||
.............................................................................................................................................
|
||||
..............................................................^.^...^.^.....^.^..............................................................
|
||||
.............................................................................................................................................
|
||||
.............................................................^...^.^...^.....^.^.............................................................
|
||||
.............................................................................................................................................
|
||||
............................................................^.^.^.^...^...^.^.^.^............................................................
|
||||
.............................................................................................................................................
|
||||
...........................................................^.^.^...^.^.^.^.^.....^...........................................................
|
||||
.............................................................................................................................................
|
||||
..........................................................^.^.^...^.^.^.......^.^.^..........................................................
|
||||
.............................................................................................................................................
|
||||
.........................................................^.....^.....^.^.....^.^.^.^.........................................................
|
||||
.............................................................................................................................................
|
||||
........................................................^.....^...^.^.^.....^.^.^.^.^........................................................
|
||||
.............................................................................................................................................
|
||||
.......................................................^.^.^...^.^.^...^.^.^.^.^.^.^.^.......................................................
|
||||
.............................................................................................................................................
|
||||
......................................................^.^.^.^.^...^.^.^...^.....^...^.^......................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................^...^.^.^.......^.....^.^.^.^.^...^.....................................................
|
||||
.............................................................................................................................................
|
||||
....................................................^.^.^...^.....^.^.^.^.^.........^.^.^....................................................
|
||||
.............................................................................................................................................
|
||||
...................................................^.^.^.^.^.^...^.^.....^...^.^...^.^.^.^...................................................
|
||||
.............................................................................................................................................
|
||||
..................................................^...^.^.^.^.....^.^...^.^.^.....^.^.^.^.^..................................................
|
||||
.............................................................................................................................................
|
||||
.................................................^...^.^.^.^.^.^.^.......^.^.^...^.....^.^.^.................................................
|
||||
.............................................................................................................................................
|
||||
................................................^.....^.^.^.^.^...^...^.^.^.^...^.^.....^...^................................................
|
||||
.............................................................................................................................................
|
||||
...............................................^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.....^.^...............................................
|
||||
.............................................................................................................................................
|
||||
..............................................^.^.^...^.^.^.^...^...^...^.^.....^.^.^.^.^...^.^..............................................
|
||||
.............................................................................................................................................
|
||||
.............................................^.^.......^.^...^...^.^.^.....^.^...^...^.^.^...^.^.............................................
|
||||
.............................................................................................................................................
|
||||
............................................^...^.^.^.^.^.^.^.^.^...^...^.....^...^.^.^.^...^.^.^............................................
|
||||
.............................................................................................................................................
|
||||
...........................................^.^.^.^...^.......^.^.^.^.^.^.^.^.^.^.^...^.......^.^.^...........................................
|
||||
.............................................................................................................................................
|
||||
..........................................^.^.^...^.^...^.^...^.^.^.^.......^.^.^.^.....^...^.^...^..........................................
|
||||
.............................................................................................................................................
|
||||
.........................................^...^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.^.....^.........................................
|
||||
.............................................................................................................................................
|
||||
........................................^.^.^...^.^.^.....^.^.^...^.^...^.^.^.^...^.^.^.^.^.^.^...^.^........................................
|
||||
.............................................................................................................................................
|
||||
.......................................^...^.....^.^.^.^.^.^.^...^.....^.^...^...^.^...^.^.^.^.^.^.^.^.......................................
|
||||
.............................................................................................................................................
|
||||
......................................^...^...^.^.....^...^.^.^...^.^.^.^.^...^.^...^.^.^.^.^.^...^...^......................................
|
||||
.............................................................................................................................................
|
||||
.....................................^...^.^.^.^.^.^.^.^.^...^.^...^.....^.^.^.^.^...^.^...^...^...^.^.^.....................................
|
||||
.............................................................................................................................................
|
||||
....................................^.^.^.....^.^.^.^.^.^.......^.^.....^.^...^.^.^.^.^.^.^...^...^.^.^.^....................................
|
||||
.............................................................................................................................................
|
||||
...................................^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.....^...^.^.^.^...................................
|
||||
.............................................................................................................................................
|
||||
..................................^.^.^...^...^.^...^.^.^.^.^.^.^...^...^...^.^.^.^.^.^...^.^.....^.^.^.^.^..................................
|
||||
.............................................................................................................................................
|
||||
.................................^.^...^.^...^.^.^...^.^.^.^.^.^.^...^.^.^.^...^.....^.^...^...^.^.^.^.^.^.^.................................
|
||||
.............................................................................................................................................
|
||||
................................^.^.......^.^.^.^.....^.^.....^...^.^.^.^.^.^.^.....^.^.^.^.^...^...^.^.^...^................................
|
||||
.............................................................................................................................................
|
||||
...............................^.^.^...^.^.^.....^.^.^.^.^.......^.^...^.^.^.^.^.....^.^.^...^.^.^.^...^.....^...............................
|
||||
.............................................................................................................................................
|
||||
..............................^...^...^.^.^...^...^.^.^.^.^.^.....^.^.^.^.^...^.....^.^.^.^...^.^...^.^.^.^...^..............................
|
||||
.............................................................................................................................................
|
||||
.............................^.^.............^.^.^...^.^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.............................
|
||||
.............................................................................................................................................
|
||||
............................^.^.^.^...^.^.^.^.^.......^...^.^.^.^.....^.....^.......^.^.^.^.^.^.^.^.^...^...^.^.^............................
|
||||
.............................................................................................................................................
|
||||
...........................^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.......^.....^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.........^...........................
|
||||
.............................................................................................................................................
|
||||
..........................^...^.^.^.^.^.....^.^.^.^...^...^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^...^.......^.^.^.^..........................
|
||||
.............................................................................................................................................
|
||||
.........................^.....^.^.^.....^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.......^.^.^.^.^...^.....^.........................
|
||||
.............................................................................................................................................
|
||||
........................^.^.....^.^.^.^.^.^.^...^...^.^.^.^.^...^...^.^.^...^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^........................
|
||||
.............................................................................................................................................
|
||||
.......................^.^.^.^...^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.....^.^...^.....^...^.^.......................
|
||||
.............................................................................................................................................
|
||||
......................^.^.^.^.^...^.^.........^.^...^.^.^.....^.^.^.^.^.^.^...^...^.^...^.^.^...^.^...^...^.^.^...^.^.^......................
|
||||
.............................................................................................................................................
|
||||
.....................^.^.^.^.....^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.....^.^...^.^.^.^.^...^.....^.^.^.^.^.^.^.^.^.^.^.....................
|
||||
.............................................................................................................................................
|
||||
....................^.............^.^.^.^.^.....^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^.^.^.^.^.....^...^...^.^.^.^...^....................
|
||||
.............................................................................................................................................
|
||||
...................^.^.....^.^...^.^.^.^.^.^.^...^...^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.....^...^...^.^.^.^...................
|
||||
.............................................................................................................................................
|
||||
..................^...^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^...^.^.^...^.^.^.....^.^.....^.^.^.^.^...^.......^.^.^...^.^..................
|
||||
.............................................................................................................................................
|
||||
.................^.^.^...^...^...^.^...^.^.....^...^.^.^.^.^.....^.^.^.^.^.^...^.....^.....^.....^.^.^...^.^...^.^.^.^.^.^.^.................
|
||||
.............................................................................................................................................
|
||||
................^.^.^.^...^.^.^.^.^.^...^.^.^...^.^.^.......^.^.^...^...^.^.^...^.^.^.^.^.^...^.^.^.....^.^.^.^.....^.^.^...^................
|
||||
.............................................................................................................................................
|
||||
...............^.^.^.^...^.^.^.^.^...^...^.^.....^.^.^.^...^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^...^.....^...^.^...............
|
||||
.............................................................................................................................................
|
||||
..............^...^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.....^.^.^.....^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.....^..............
|
||||
.............................................................................................................................................
|
||||
.............^.^.^.^.^.^.^.^...^.^.....^.^.^.^...^.^.^.^.^.^...^...^.^.^.^.^.^.^.^...^.^.^.^.^...^...^.....^.^.....^.^.^.^.^.^.^.............
|
||||
.............................................................................................................................................
|
||||
............^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.....^.^.^.^.^.^.^.^.^...^...^.^.^............
|
||||
.............................................................................................................................................
|
||||
...........^.^.^...^.^.....^.^.^...^.^.^.....^.^.^.^.^...^.^.^.^.^...^.^.^.^...^.^.^.........^.^.^...^.^...^.^.^.^...^.^.^.^.^...^...........
|
||||
.............................................................................................................................................
|
||||
..........^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^...^.^...^...^.^.^...^.....^.^.^.^...^.^.^.^.^.^...^.^.^.^.^...^.^.....^..........
|
||||
.............................................................................................................................................
|
||||
.........^.........^.^.^.^.^.^.^.....^...^.^.^.^...^.^.^.....^.^...^.^.^...^.^...^.^.^.....^.^.^...^.^.....^.^.^.^.......^.^.^.^...^.........
|
||||
.............................................................................................................................................
|
||||
........^.^.^.^.^.^.^.^.^...^...^...^.^...^.^.^.^.^...^.^...^.....^.^...^...^...^.^...^.^.^...^.^.^.^.^.^...^.^.^.^...^.^.^...^.^.^.^........
|
||||
.............................................................................................................................................
|
||||
.......^...^...^.^.^.^.....^.^.^.^.^.^.^.^...^.........^...^.^...^...^...^.....^.....^.....^.....^...^.^.^...^.^.^.^.^...^.^.^.^.^...^.......
|
||||
.............................................................................................................................................
|
||||
......^...^.^.^...^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.^.^...^.^...^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.....^.^.^.^.^.^.....^.^.....^.^......
|
||||
.............................................................................................................................................
|
||||
.....^.....^.^.^.^.^...^.^.^...^.^.......^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^...^.^.^.^...^.^.^.^...^.....^.^.^.^.^.^.^.^.^.^.^.^.....
|
||||
.............................................................................................................................................
|
||||
....^.^.^.^.....^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^...^...^.^...^.^.^.^.^.^....
|
||||
.............................................................................................................................................
|
||||
...^.^.^...^.^.^.^.^.^.^.......^.^.....^.^...^...^.....^.^.^.......^.^.^...^.^.^.^.^.^...^.^.^...^.......^.^...^...^.^.^.^.^...^.^.^.^.^.^...
|
||||
.............................................................................................................................................
|
||||
..^.^.^...^.^.^.^.^...^...^.^.^...^...^...^.^...^...^.^.^...^...^...^.^.^...^.^.^.^...^.^...^...^.^...^.........^.^.^.^...^.^...^.^.^...^.^..
|
||||
.............................................................................................................................................
|
||||
.^.....^.^...^.^.^.....^...^...^...^.^...^.^...^...^.^...^.^.^.....^.^.^.^...^.^.....^.^...^.^.^...^.^.....^...^.^.^...^.......^.....^.^.^.^.
|
||||
.............................................................................................................................................
|
||||
21
day7/part1.py
Normal file
21
day7/part1.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
|
||||
FILE = "input.txt"
|
||||
|
||||
def main():
|
||||
raw_lines = Path(FILE).read_text().splitlines()
|
||||
beams = {raw_lines[0].index('S')}
|
||||
splits = 0
|
||||
for line in raw_lines[1:]:
|
||||
for i, c in enumerate(line):
|
||||
if c == '^':
|
||||
if i in beams:
|
||||
splits += 1
|
||||
beams.remove(i)
|
||||
beams.add(i-1)
|
||||
beams.add(i+1)
|
||||
return splits
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(main())
|
||||
25
day7/part2.py
Normal file
25
day7/part2.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from pathlib import Path
|
||||
|
||||
FILE = "input.txt"
|
||||
|
||||
def main():
|
||||
raw_lines = Path(FILE).read_text().splitlines()
|
||||
position = raw_lines[0].index('S')
|
||||
return traverse(position, raw_lines[1:], 0, dict())
|
||||
|
||||
def traverse(position: int, grid: list[str], level: int, memo: dict[tuple[int, int], int]) -> int:
|
||||
if (position, level) in memo.keys():
|
||||
return memo[(position, level)]
|
||||
if not len(grid):
|
||||
return 1
|
||||
if grid[0][position] == '^':
|
||||
memo[(position, level)] = (
|
||||
traverse(position-1, grid[1:], level+1, memo) +
|
||||
traverse(position+1, grid[1:], level+1, memo)
|
||||
)
|
||||
return memo[(position, level)]
|
||||
memo[(position, level)] = traverse(position, grid[1:], level+1, memo)
|
||||
return memo[(position, level)]
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(main())
|
||||
16
day7/test.txt
Normal file
16
day7/test.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
.......S.......
|
||||
...............
|
||||
.......^.......
|
||||
...............
|
||||
......^.^......
|
||||
...............
|
||||
.....^.^.^.....
|
||||
...............
|
||||
....^.^...^....
|
||||
...............
|
||||
...^.^...^.^...
|
||||
...............
|
||||
..^...^.....^..
|
||||
...............
|
||||
.^.^.^.^.^...^.
|
||||
...............
|
||||
Reference in New Issue
Block a user