From 93d4dcf4cadd61e0eccdd4276dbb7349a5740423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Thu, 14 Dec 2023 06:58:19 +0100 Subject: [PATCH] Add solution to 2023-12-14 --- 2023/day14/input | 100 ++++++++++++++++++++++++++++++++++++++++ 2023/day14/solutions.py | 50 ++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 2023/day14/input create mode 100644 2023/day14/solutions.py diff --git a/2023/day14/input b/2023/day14/input new file mode 100644 index 0000000..49345be --- /dev/null +++ b/2023/day14/input @@ -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 diff --git a/2023/day14/solutions.py b/2023/day14/solutions.py new file mode 100644 index 0000000..0d23eda --- /dev/null +++ b/2023/day14/solutions.py @@ -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)} +blocked = {loc for loc, val in board.items() if val == "#"} +rounds = {loc for loc, val in board.items() if val == "O"} + + +def tilt(rounds, d=1): + while True: + dirty = False + newrounds = set() + for z in rounds: + if z - d in board and z - d not in rounds and z - d not in blocked: + newrounds.add(z - d) + dirty = True + else: + newrounds.add(z) + if not dirty: + return newrounds + rounds = newrounds + + +def load(rounds): + return sum(100 - z.real for z in rounds) + + +def cycle(rounds): + for d in (1, 1j, -1, -1j): + rounds = tilt(rounds, d) + return rounds + + +# Part 1 +print(load(tilt(rounds))) + + +# Part 2 +seen = [] +for i in count(): + rounds = cycle(rounds) + if rounds in seen: + start = seen.index(rounds) + break + seen.append(rounds) + + +print(load(seen[(1000000000 - i) % (i - start) + start - 1]))