-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_a.py
executable file
·45 lines (33 loc) · 1009 Bytes
/
part_a.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
#!/usr/bin/env python3
import utils
from year_2019.day_05.part_b import get_program_result_and_output_extended
import year_2019.day_09.part_a
TILE_EMPTY = 0
TILE_WALL = 1
TILE_BLOCK = 2
TILE_PADDLE = 3
TILE_BALL = 4
class Challenge(utils.BaseChallenge):
def solve(self, _input, debug=False):
"""
>>> Challenge().default_solve()
247
"""
_, output_stream = get_program_result_and_output_extended(_input, [])
game = fill_game(output_stream)
return sum(
1
for tile_id in game.values()
if tile_id == TILE_BLOCK
)
def fill_game(output_stream, game=None):
if len(output_stream) % 3 != 0:
raise Exception(f"Expected triplets, but got {len(output_stream)}")
if game is None:
game = {}
for index in range(0, len(output_stream), 3):
x, y, tile_id = output_stream[index:index + 3]
game[(x, y)] = tile_id
return game
Challenge.main()
challenge = Challenge()