Skip to content

Commit

Permalink
Add solution to 2023-12-14
Browse files Browse the repository at this point in the history
  • Loading branch information
fuglede committed Dec 14, 2023
1 parent 85f8a35 commit cfab3a0
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
100 changes: 100 additions & 0 deletions 2023/day14/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
..O...............O....O..O#.OO...O.O#...OO##O....#....O#.O#O....O#.......#.#OOO...O.......O##..#...
OO##.O..#..O..#.#........OO.....#...O.#.O..O...O..O.O...O..O....OOO.........#.#O.O....#..OO..#.##.O.
.#.O......O#.##..O..#...#..##.O......O.O#......O.O.OO..#.##.#OO.O..O.O..O#...O.O#.#O..O.#....O.O....
..#....O.#....O..O.OO#....#..#.OO...O..##OO###.#O#..#.O...#...#.O....O..#O#.O#..OO.#..O...#....O.O..
..#OO.O..###.....#.OOO...O....#OO.#..O.#.O.#.#.#O......O.O.O....O#O.O.O##.O..O..O..#.#O.#.O..O.O...O
..O...O.O##...#...O...##...#..O..........O#.#.OOO#.#..#.O......OO##........OO..O#...#.OO.....O.....#
.#.OO#.#O...#.OO....O.....O.O..O...#...O....O..#......###O..O..O#.....#.O..#O..#..O......#...O.....#
##....#O.#OO..#.......OO.....#..##....#..O#OO.#...OO.....O....#.....O#....O...OO#..#...#...O#...#.O#
...#...OO.O...O#.O.......#O....#..O..#.#.O.#.OOO.#..OOO.O#........##....#.O.O...#O..O.#OO.#OOO.O....
OO#.....O..#.#O....O...#..O.O...O..O.O#.........#O#OO..O.O....OO..OO...O...O...O.O....O....#..#..#..
O.#.O.#.....#...#.#........O..OO..O#O#O#.....#.#....O#..O.O......O.......#.....O...O...O.OO.O.O#...#
...#...O.#.#....O.OOO...#.##......OO.O...O....#.O#O..O....#..#..##.O...O....#...O..O.O.O........#OOO
.#.#......##O.OO.OO##.O...#.......O.#OO.##.#...O..#O..O.OO..O.O.O.#.O.O..#..O..#..#....OO..#..#.....
...#OO#.O....#O..O#.O..#.#.....#...#..O..O#O...........#...OO#O..O..#O...O.#..###.O.#......#...OO.O.
..#O....O.O#.O.O#.#.#...O....O.....O....#O........#OO.O#O#...O#.OO.O.....O.##..O.#...#.#.O...O#..#.#
.#..O#O...#O#.O.....O..#.#......O..OO.O.....O.....O.#.#O#.#O.O#.O###............##...O.....O.O.....#
.....O...#O#.#....O......##.#..#.##...#..O.O.O##....O..#...#O.O.....O..O#..#..O#...##...#...#OOO..O.
....O......OO##..O#O..O.....O#.#...O.#.O.#....#.OO.#OOO..#.O.O##.....O.O...#.....#.O.O....#...#.....
...O....#O....OO..#...#.O.......O.O....#.O......O..#.##O.....O...#O..#O#O.O#....#O..OO##..OO#....O.#
.#...#..#....O.....O.#OO.O..#...##...O.......O......#.O.#O..#..O....O..#........#...O...O###..O.....
#..#.O....O.#OOO##O#.##.O.#.#.#..#..O......#...OO.#..O...#....#....O...OO.#.OO...#.#........O......#
.....#O.#..###..O..#.#.#..#..#..O....#..#......#...O..#O....O....O.....OO.O#.......O..#....#...#..##
.#..#........#.#O#O...#...........O#....#.O.....#....#.##...#.O.O##..#O.#..O...#...##.O.##.O....O..O
...#.O...O...O........#...O..#.O.#.O.#....#OO......OO#.O.O##...##..OO#.#O.O.#..O....O......#....##..
.....#O..#.#.....#O#.#.#..#..O.........O.O.#...O...#OO#.....#.....O.O.#..##...OO...O...#OO.#........
....#.#..#O...O..#.O...O.OO......#O#.O##O.#..O..##.#O.O....O...##O..O...#.O..#O...##...O..O.#O....OO
...O..#....OO..O#.......#...........#..O.....O#OO#.O..O.O..#O...OOO..##OO........#..O.O##OO#...#O...
.O.......O.......O..O...###...O.....O.O.O#.#...O.O#..#O..#.O..OO....#O.....##...O...#O.#....O..#OO.O
##O#.O...OO.O.##.O...#....#..O.....OO.O....O#.O#.O..#....OO#.....OO..##.#......O.OO..#..#....#O..#O.
....#...#O....OO.....OO.O#.#.....#...O#O...#...#..OO..O##.O...O.O.O..........O.#.O#O....#O#...O.....
.....O.OO#OOO..##....##.....O#.......O#..#.#..OO...O..O...##...O..O.O#....OOO..#.OO........O..##..O.
.O.......#........#.....O.O...O...O.O...O..O....O#.....#.OO..O..#.##.#..#...#.#...O.#..##.......O...
.....O#....O.O.#..O.........O.O....###..O..OOO.O#..#..........#......OOOO.#O...O...O.O.....O.OOO##OO
#..#...........#....#...#.O..#...#O#...#...##.#....#O#.O#O......O#.#.#...O.O.#.O.#...O.O...OO.#....#
.O..O##....#..O.O..##.O.#..#........#..#.O.##...O...O....O.#...O...##..O#OO.#.#..O....O..##O...OO.O#
...O..#......#.#.......OO....#.....#......O.O....##O..OO.OO.#....##.O..O...........#OO...OO.O.O.OOO.
.........#.OO..O.O#....#.#..O...#.....O.O..............#.....OOOO.#..O.O#O.O.O...#..O.O.OO....O..#.O
O.........O##...#.....#....#.O......O.O.O.O..#.O#...O.OO.#.O.O.#.....O.O..OO#.#.#.O.#...#.....#....#
.OO.O.#O..O..#..O.O#.O..#O.#.#.OO.#O#OO..O.........O....#....#.O.O#.O.O.#...#..O...#..#.........O..O
OO..O......O#..#O..O.O.O..O...#..OO#.OO....#.OO.#O..O.O..#......#O.#....#...#.OOO....O.O.OO....#....
.O..#O#.......O....OO.O....#OO.O...O..#.....O#.O.OO.#..O..O.O#.....###O....#.....O.#.......O.....OO.
.O..O.O.##.OO..#.#.O...#...#.#..OOO..O.....#.#O#..OO.OOOO.#......O..#....O.#.O.#....#.....O...#..OO.
.#.#...OO..O....O.....O..##.#.#O#...#.....#..O.#......O.O##..#......O##..O.O...#O.#.O...........#O..
.OOO#....#..#O##..#.....O.OO#..O..#.##....OO..OO....#.##.#...#...O#O.....O#.#.#.O......#O...#.....#.
....O##....#...###O.OO..#...#.O.OO#O..O.O..##......O....#....#..O###..#..#.....O.......#..O.O#......
O.O...........O.#...OO.O.......#.....O...##.#..#.O#..#...#.O##..#O.##...O.....O...OOO.O.O..#OOO....#
.O.O#O...O...#...............OO#......O........##OO.......O...#OO.O..O....O..###.O..O...O...O.#.....
.O.##OO.........OO.OO..O..OO.#..#.#......O..O#O.O..##..O..O.##.....O#O.O...OO...O###..O......#.O....
#.O...O.O.O..O#..O.O......O.#.....O.O...#.#O.O..O.......O....#.....O#OO..O..O.O...O##..O.......#....
OOO...##...#..#.OO#O..O#.O.....O........O#....#.#.....O#.OOOO...#OOO...OO..OOO...O#........O...#....
#....#....#.....#....O.O..O.O...##.#..O##.#O.#.O.##O.............###..#O#O.O#..#........#.#O#....#..
O.#.#.OO.....#.##....OO...##..OO.#.......#O...O#............#O#O#....O..#......#......O#.OOO.O##..O.
....O....O.#O...#OO#...#.O....#.OO.O...##.O.O.O....OO#O.#....O.....O..#..O.#.O##O##....#..#..#.O.O..
###....#..#...OOO##O.O.#..#..O#......O....#.#.#OO.O....O.OOO..#...#O.##.#......OO.....O..#.O...#OO..
.#...O...O....OO.....O..O#..O.O.O.#.....#OO#O....O...OO..#..O.O.O.#..#O......##.....#.....#O.O......
.OOO........O.#.#....#OO..#.O.O...#.....#OO......O.....#......#.##.O.OO.....#O.#O..O.O....#...O.##.#
#O.O#..#..#...O.O#...O##..#..OOO....OO.#....#.O#OO.#..OO#.#OOO##OO.....O.O.O.....O...###O..O#O....#.
###...O..O.OO.#...#.O.O#O.OO..##O.OO..#..O...#.......#.......#.....#..#.#..O..#.OO....O..O..OO...#O.
OO...#OO.#....#.O.O.O..O....#O..#..O.O.O.#.......O......O.O.O.....O...O.OO#OO.......O..#.......#O...
.#OO.......O..OO.#O.#OO...#OO..O..O.#...O.O....O....#O#..OOO.#........#.O.O...#...O#.O...O.#.#....O.
#OO##.O...O....##..#....O.#..#.....##..O....#O...#......#O#.O..O.##.....O.O...#O.#OO.###O..#..O#O..#
.#...#.....O#.#....O.OO##.O.O..O........O##....#.O#O#.....##...O..O#.#....O.#...##...#..#O....O....O
..O..O....#..#....#..#.#.#O#........O..#.....O.###.#O...O...O##..O.O..#.#.O..#...OO.O.OOO.......#...
..OO##O.O..OO.O..#.#...O..O.#..O#..O#...#...O.O....#..O...O.#..#.#...O..OO..........O...O.O......O..
..#..#.#..O#.........O.......#.....#..#.....O#..#O.....OO..#...O#O.O#....#..O#....O..#O....O...O....
O..O..O.....#..#...O...#O.....O.OO..O....O.O....##..O.#OOO..#.#.O.O#......#.OOO..O.O.....#..#.......
....#.O.O.#.#..O#.....#..O##O..#..#.#....##O.....O##.#....O........O##...##OO...O#.#.O..O#O..#..O...
...#O.....O..##.#....O.OO.O...##..O........O..O.#.#........OO..OO...OO##...#....#...OO#..#O.O.......
##O..#OO....O..O#.O.O.#.OO.#O#.......#....O...#........O...#..O..OO#..O.....#...O...#....#..........
...##OO.O...#..#O...OO...#.OO.....O.O...OO..O#.........O...O....O#O#.O.#...OO...##O.#.#.O....O#..#..
#.....#...O.O.O...O#..#...OO.OO...O..##.#.......#.##OO...........O...O...##..OO..O..#.....#.O...OO..
..O.O...O#.OO#......OO..O#....O.O...#O.#.........O...#OO....O.O.O.#O........#.##.......#....##...#..
#.#...OO..#O..O.....OO###OOO........O.O.O....O#O#O#.O.....O#O..##.##O...O###....####.O..#..##....##O
..#..O.#.O.#.#...O.......O....O...OOOO...#.OO#....#.......O..O.........#..O.O.........#.O..O..O.O..#
#..OO...##.O.#.#..#...O.........#O.#.......#O....#..#O.#...O.O..##OOOO..#.#..........O..O.O.####..#.
#...O..#....#O..O#O#O.......O..O..O...O...OO.OO.OO.O..#.#.#OO#.#OO.#O........O..O.O.....OO.#O.#..O.#
..O.#...........O..OO......#OOO#...O#O#O......#......OO..O......O#..#.OOOO...O........#..#.OOO...#O.
O.##...#OO....OOO...O....O.....OO...##....#...#O.O..#..O#O....O#....O....##......OOO.O..#...O#OOOO..
...O.....O.O.#.#...OOO#OOO.O.....O#OOO#.#O...O#OO.O...#...O......OO.....O...#.O.#..##....#..O...OOO.
.#...O.....#..O......O...#.....##..O#.#O..O....O..#....O......##..#OO..O.##..#O....O......#.O.#OOO.O
.#...O...OO.....#.O..#OOO#.O....O.O...........#...O.....OO.##.#......O.O....#.O.##O....##......O....
.OO.....#O.##.##...#....#....OO.O...#.......OOO#..OO..O.O......#....#O...###.O..#.##.#.#..O.#...O...
....O.....OO..O##.O...#O##.O.#.OO.OO.O........#O............#OO.O#O.#.O##.##...........#..O.#O.O.#OO
..O..O...#O....O#..O.O..O..OOO..O..#.#.OO..#O#.#...O....#.O.#...#....##.....##O...#O##..O#.....#O...
O#.....O...#..##OO..O#O........#.#...#O...O#......#O..##.#O...O.O....OO..O.OOOO...#O.O.O....#OO.O.#.
.OO.....##..#...#.#....O...O...O...O..OO....#O..##O...O.#.OO.O##....#..O.OO.....O..##.O#.....#O..O#.
O.....O.O..#...O..#.#.OO...O..O#.#O..#O.#.#.##..#.O.OO##..O...#.#.O...##.O....O...OO...O#O..O.O.##O#
.#.O........##..........#...O...#O..O..#..O....OO.OO.#..O.O##.#...#.O#.O...##.O#...#....O......#..O.
O#O.OOO..##OO.#........#O.#O...OO...#.OO.........O.#.........#..#.....O.O...#..O#O.OO..O..O....O#...
.O#..O#...#O...O.O..O#...O.#.O.O....##O....O....##OO....O..O.#O.O....##.#O.....OO..#O..O....#OO...#.
O..........O.O.........#O...#...#..##........O.#......O#..O#.......O...O...#O....#.##......O.#.#.O.O
....O...#OO..O.O.....OO.#.#O.#........#O.O...#..#.....O...O.....OO...#.OO..##.O.#......#...#.O#..#..
...O..#.#...#.#..#..#...OO.#........##..O.O..#....#..O...O......#..O.......##....O............O.#..#
..O#.O.###........#.#.#...#.O.#O#O.O.O..O.O#O.....#O.O.O...O##O.....OO.O..O..#......O....O..#O......
#..O...O....OO.O.......O.......#..#O.#...O.###.....OO..O..O..OO.O#..#O.#OO.O#.O.O.O.O..O#...###O....
#....##O..O.#...O...#O....O#O#........#..#........###...##..O...O...OO.#.OO#..##..OOO......O.O.#.O#.
...OO.O........O...O..OO...O.O#O...O#.O.#.........O.O.......O.#....O...O..#.OO#..OOO...O.#..OO....O.
#O.OO.OO.##.#O...O.......#O.#O....O.#..O.......OOO...O#...##O##.#.......OO#O.....OO.OO#.O#O#O#....#.
....OO#OO...#........OO#...#..O....#.O..O...O.O.OO......O.#OO....#..#...........O...##..O..O.O......
#...O.O..O.##.......O.......O....O.O..#..#O...O.....OOO.#.O.....##..O..#O.......#..O..O.O.....O#OO.O
50 changes: 50 additions & 0 deletions 2023/day14/solutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from itertools import count

with open("input") as f:
ls = f.read().strip().split("\n")

board = {i + 1j * j: x for i, l in enumerate(ls) for j, x in enumerate(l)}


def tilt(board, d=1):
while True:
dirty = False
newboard = {}
for z in board:
if z in newboard:
continue
if z - d in board and board[z] == "O" and board[z - d] == ".":
newboard[z] = "."
newboard[z - d] = "O"
dirty = True
else:
newboard[z] = board[z]
if not dirty:
return board
board = newboard


def load(board):
return sum(100 - z.real for z, val in board.items() if val == "O")


# Part 1
print(load(tilt(board)))


# Part 2
def cycle(board):
for d in (1, 1j, -1, -1j):
board = tilt(board, d)
return board


seen = []
for i in count():
board = cycle(board)
if board in seen:
start = seen.index(board)
break
seen.append(board)

print(load(seen[((1000000000 - i) % (start - i)) + i - 1]))

0 comments on commit cfab3a0

Please sign in to comment.