-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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() | ||
free = board.keys() - rounds - blocked | ||
for z in rounds: | ||
w = z - d | ||
if w in free: | ||
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])) |