-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC2020_17.py
70 lines (54 loc) 路 1.55 KB
/
AoC2020_17.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env python3
#
# Advent of Code 2020 Day 17
#
import sys
from typing import Callable
from aoc.common import InputData
from aoc.common import SolutionBase
from aoc.common import aoc_samples
from aoc.game_of_life import ClassicRules
from aoc.game_of_life import GameOfLife
from aoc.game_of_life import InfiniteGrid
TEST = """\
.#.
..#
###
"""
ON = "#"
GENERATIONS = 6
CellFactory = Callable[[int, int], tuple[int, ...]]
Input = InputData
Output1 = int
Output2 = int
class Solution(SolutionBase[Input, Output1, Output2]):
def parse_input(self, input_data: InputData) -> Input:
return input_data
def solve(self, inputs: Input, cell_factory: CellFactory) -> int:
alive = {
cell_factory(r, c)
for r, row in enumerate(inputs)
for c, state in enumerate(row)
if state == ON
}
game_of_life = GameOfLife(alive, InfiniteGrid(), ClassicRules())
for i in range(GENERATIONS):
game_of_life.next_generation()
return sum(1 for _ in game_of_life.alive)
def part_1(self, inputs: Input) -> int:
return self.solve(inputs, cell_factory=lambda r, c: (0, r, c))
def part_2(self, inputs: Input) -> int:
return self.solve(inputs, cell_factory=lambda r, c: (0, 0, r, c))
@aoc_samples(
(
("part_1", TEST, 112),
("part_2", TEST, 848),
)
)
def samples(self) -> None:
pass
solution = Solution(2020, 17)
def main() -> None:
solution.run(sys.argv)
if __name__ == "__main__":
main()