Skip to content

Commit

Permalink
Added solution for 2023/Day 21
Browse files Browse the repository at this point in the history
  • Loading branch information
npanuhin committed Dec 23, 2023
1 parent 27ee91f commit b891fb3
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .github/src/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def main():
for changed_path in json.load(file):
changed_path = mkpath('../../', changed_path)
while changed_path:
changed.add(changed_path)
changed_path = os.path.dirname(changed_path)
changed.add(os.path.abspath(changed_path))

print('Changed files:', changed)

Expand All @@ -41,7 +40,7 @@ def main():
if not day.solved:
continue

if changed and day.path not in changed:
if changed and os.path.abspath(day.path) not in changed:
print(f"Skipping day {day.year}/{day.folder_name} as it wasn't changed")
continue

Expand Down
131 changes: 131 additions & 0 deletions 2023/Day 21/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
...................................................................................................................................
....#...........#...#...........................#....................................#....##........#..........#.....#.............
..........#...##..#.....................#.#.#..................................#.#..#..#............#........#.....................
....#................##.....................#..........#........................##.#...#..#......#...#......#....#.................
.#..#.................................#.................................................#..#............#..#.##.#.#.........###....
..#...#.#.......#......#...........#................#............................................##.........#...#...#....##........
................#.#..........#..........##..#..............................#...#................#.#......##.......#............#...
........#.#...#..#.##.#.....#......................#.#.............................#....#......#.#.#...#........#..................
.#...##.........#..#..........#....#.....#...........................................#........#.......#.......#...........#........
.........##............#.......#..#.......#...#.#.....................................#..###.......###.........#.....#...#.....#...
.#..#.......#....#..#............#.....#............................#................#.........##...................#..#.#..#......
.#.................###..#...........#.........#................##....#...........#...........#.....................................
.....##.........#..#..........#.....##....#................#..##...................#......#.....#..#.....#.#.......................
..........#......#..............#..#...#..............................................#...........#.#........#............#.#......
...........#.#......#.....#.#.....#.....................#...........#....#.............#.#......##...#......#.....##...............
..............#...##....##.....#......#...............#.#.#...#.....#.................#.#.............#...............#....#.#.#...
.##.#........#.........#.#.#....#....#.......#.........................#...............#..........#.....##....#...............##...
.....#.......##............#.........#....#.................#.................#.......#...............#......................#...#.
...............#..........................#........#..#.......##..#....#..#...#................#....#...#.........#.#.#..#......#..
..........#..#..#..#.##.........#......#.......................#.....#.........#......................#...#.##......#....#....#....
....#.........#......#................#..#.............##.#......................#...........#..#.............#....##........#.....
.............#...#.................#...#...........#...#.#......#......#.......................#.................#....#.#....##....
.......#.#.....#..........#.....#.##............#.#......#........#...#.......##................#................#.......#.........
.#.....................#..#.....#.#...........................#..................#...........#....#......##..............#.....##..
.....#..............#....#.....................#..##...........................#..................#...................#.........#..
....#..#.##........#.....#.........................................#......#.......................#....#....#...#...#....#...#.....
...................#....###....#............#..#.............#.#......#........##.................#...#....#.....#.##..............
......#...#........#....#.....#................#...............................#........................##..#..#......##........#..
.#.....#..........#....#........#................#....#...#..#..#.............#..#..........................#.........#..........#.
.......................#.....#.................#.....................................##.#.........#..................#.....#....#..
.#..................#....#....#...........#....#...#..#..#.............#....#....#####....#.........#.......#..#..###...........##.
....#.......#.#............#.#.................##.............#.#.#....#...##...#...#...............##.###...........##......#...#.
.....#...#...#.........#.....................#....##..#........#......#.................#.#...................#.#..............#...
........##.....##.........#.#......................................#..........#.....#.#.....#.#..............#..........#..........
........#....#.........#..#..............##.....#.....#.....#............#............#....................#.....#.....#.......#.#.
......##...........................#............#.....#.#..............#...........#.......................................#.......
.#.......#...#....#...............................#....##...#..........#.##........##....#................##...........#...........
.#.##.........#.................#................#.#..#.#................#.................................#.......................
.#..#..............#.##.........##.....................................#.....#........#.#..##..#..##............#..........#...#...
....#.##...........###.........#.....#........##...#...#......##..#...............#.#.......#...#.#..........#..........#..........
..........#.....#.....................#..##..#.#.##.............#..............#.............#......##...........##....#.......#...
.....#.......#..................#..........#.......#........#..........##.....#....#...........................#..............#....
.........#.......................##...............#......#.....#...#..........#.#..#...................#...................#.##....
.........#..............................##......##...#..............#...##......#..............#.....#.......................#.....
....#............................#...#..#.#.......#.............#...............#.....#..................#........#.........#......
..#.....................##........#......#...#....#.#..............#...............#.........#...#....#.###..........#....#..#..#..
...........#...#.................#.........#..##.#......#.#.................#..#.......#..............................#..........#.
.....#.#.................##.#.....#....#.........#.....#..#...#.......##..#................................##.................#....
.......#..............#.......#................#.......#..............##.....#...#...#.............................................
.#......#.................#......#.......#.........#...........#...#.......#...#...#......#.......#.#.....#...#..................#.
..#...#...............#.......#.#...................#.....#.#........................#......#....##.#..............................
...##....#......................................#......##.......................#..#...##...............................#...#......
.##..........................................#...............#.......................##.....#...............#.#....................
..#..#...................................##..#.....................................#........##.....#....###......##............#...
...#............#.......#.........#..#.....#.......#.........##........................#...#...#.#..#....#.#.##....#........##.#...
.....#...........#.#....#..............#.....#..............#.................#.......#....#................#....#.................
....#............#......#.............#....#.#...##..#....#.#...#......#.......#...........#..........#.......#....................
...##..............#......#...#........#.........#...#....#............#..#..........#.#..#.......#...#.........#.....#............
.............#.##.........#...#....##.#...#...........##...........##..#....#.......#............##................#...............
.............#..##...#.#.#.#..#.#............#...#......#...#.....#.........###....#..............#............#.#.....#........##.
..........#.................#.....#.........#.#......#.#...........#.......#...............#..#..........#........#.....##.......#.
....................#................#......................#..............#........##...#......#....#...........#.#....#..........
..................#.....#.#.#....#...#..........................#...#...........................................#....#...#.........
......#..........#.#..#........#.....#.......................#.........#......#.............#..............................#.......
...........##....#..#........#...#............#...............#.#.##.#.#.#............#...#........#.....#..#.#...#......#.........
.................................................................S.................................................................
.....#........#......#...........#..#............#..............#........###........#......#............#.....#....#...#...........
..................................#..#................#........#.........#...#.#.......#..#..........#...........#......#.#........
............#.........###........#........##........................#...#.....#......#..##..#.......#..###..............#..........
..........#..............................................#...............#..............#............#.#...#..............#........
...........#...#..#...##...........#............#.....#.#..#..#........#..#...............#...............#.....#.....#.##.........
.....................#....#..........#..#..................#..#.........#......#..................#.................#..#...........
............#....#.#...............#.....#..........##..............#...#.#....#....#......#.......................................
.#...........#............#..#..#....................................#.......#......#.....#....#.............#.....................
..#.#...........#.............#...............#...#.....#.......#.............#.........#.#.........#..........#...................
..............#................##.#.#.#.#......#...#...........#....#.#.....................#...........##.#..#.............#.##...
...#...............#..........................##........#..#.....................#...........#...#...#.#...#......##...............
........#..........#...#..........#...#.....#............#.......................#.#..........#...#..........................##....
.......#..............#.............#.......##.#..#...#........#.....#..#.....#....#............................#........#...#.....
..........#.............#...........#........#..#...###....#..........#...#....#..............#.##.............#.........#...#.##..
.........................#.#..........#.....#.........##.#..............#.....##.........#.##.....#.....#..........................
....#....#.................#..........#...#.....##.#...#....#.........##.....#.##.............................................#....
...#....#.#............#...........................#......................#..#..#...###............#...#...........................
..............#............#................#...#.#..........................#....................#...#.#............#.....#.....#.
.......#.......#........#..................#.#....#...#..............#......#...............#.......##...#.................#.......
.....#.#..............................#.#...#..................#...........#.##................#...................#..#.#..........
.....#..........#..........#.#.....#.........#....................#..#..#.......#......................##................#.....#...
....#..................................#....#........#.........#..........#...#.........#..#..........#.............#.......#..#...
.#.................#........#..#.#......#..#.#.....#..#.........#......#......#.#........#.....#.#....#............#.......#.##....
...............#................#..........#...#.#...#...#....#.#..#...........#....#..............................#............#..
.........#...........#.........#................................#...#..#........................................#....#.#...........
...#..................#...........#........#................#.#....#............#...#........................#...#.................
.#..............##.....#.......#......#..............#..........................#.#...........#............#...........#....#......
........#....#......................#................#........#...................#.........................#.#....#............##.
...........#.........#.#...........##......##..#.#..#.....................#.#......#...........#.............#.....................
...........#...##.........#...........................#......##.......#......#...............#.#...........#.##...#..#..#..#..#....
....#...##..#.#..#.#....#...........#.........#.....#.........#.#.....................#..................#..........#........##.#..
.....##....#..........#.#...........#....#..............#................#.......#....................##......#....................
.#..#..#........#....................#..#.#....#........##.....##.#......#.....#......#....#.....................#......#..###.#...
.........#...#...............#.........#..#............#.#....#.........#.............#...#.................#..............##......
...##........#.#.#.....##..#........................#....#...#...........#..........#.#............#.#...#.............#...........
...##..............#......##.................#...........#..........#..............##......................#...#.....#....#..#.....
........#........#........#.................###.................................#....................##.#.#...#...............#..#.
.......#.......................................#..........#..........................#.#............#.........#..#..##.............
.........#.........................#................#................#...#.......#..#..#.......#.........###.......................
........#.....#......###.#...............................#........#....#.....#..##.............................#..#...#........#...
...........#.#....#..........#.#...#..........####.#......####.#....................#.............................#................
...##.............#..#........#................#......................#...#......#..#........#......#..................#...#.#...#.
.#........#.......#.......#.......#................#........#..#.....#...........#.........#.......#.#........#........##...#..#...
..........#.......#............#.........................#.................#....#...........##.........#...#................#....#.
.........##.#.....#...#..##..............................#..................................##......##..#..........................
........#......###..#....#....#.##....#..............#........#...#.........................................#........#...........#.
.......#.....#.#..#....#..........#...#.#..#....................#........#..............#......#..#..#....#............#.......#...
...........#.##..#......##.#...............#.............#.##.............#.......................#...........##...................
.###.....................#.#..........................................#.#.................#........#............#.........#........
.....#....#......#..#.....#............#..............................................#....##.......#........#..#..........#.......
.......#......................................................##...#.................#.......................##....................
......#.#....#...#...............#.#...#..#...............##......#..#............#.....#.......#.................#..##..#.#.....#.
............#........#..#.........#....#......##.#........#....#..#...........................#...............#............##......
.....#....#.##.......................#....................#.#.................................................#....##....#...#.....
..............###..#.....#........#.........##.#...........#.#.#...#.............#......#...............#.##...........##..........
........................#..#.........#.....#.......#.........#.....#................#.#.#..........................#.#......##.....
.......##........#......#........#.##.#.#........#......................................#......#...#.#...#.......#..#.....#........
.#.....####..........#......#.......................#.............#...........#.....#.......#.#.....................#..............
...#.....#...##.............#...............#..##..................#................#..........#...#........#.......#..............
.#.........#..#...#.#....#....#.......#...........#...............#...............#...#........#..........................#........
...............#....#........###.......#....................................#.................#...........#.........#..#...........
.......#......#..#.....#.........#.........#............#.......................#..#........#...#..#.....#.......#.............#...
........................#.............#........#..........#.................#......##.#..#...#.............#...........#...#....#..
....#.....#....#......#...#...#...................#..##.................#..........##.##...............#..........##...............
...................................................................................................................................
35 changes: 35 additions & 0 deletions 2023/Day 21/part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
DIRECTIONS = [(-1, 0), (0, 1), (1, 0), (0, -1)]
STEPS = 64


with open('input.txt') as file:
garden = list(filter(None, map(str.strip, file)))

width, height = len(garden[0]), len(garden)

plots = set([next(
(y, x)
for y, row in enumerate(garden)
for x, plot in enumerate(row)
if plot == 'S'
)])

ans = [[False] * width for _ in range(height)]

for step in range(STEPS - 1, -1, -1):
new_plots = set()

for y, x in plots:
for dy, dx in DIRECTIONS:
new_y = y + dy
new_x = x + dx
if 0 <= new_y < height and 0 <= new_x < width and garden[new_y][new_x] != '#' and not ans[new_y][new_x]:
new_plots.add((new_y, new_x))

if step % 2 == 0:
for y, x in new_plots:
ans[y][x] = True

plots = new_plots

print(sum(sum(row) for row in ans))
Loading

0 comments on commit b891fb3

Please sign in to comment.