Skip to content

Commit c5166f1

Browse files
committed
Day 13 visualization
1 parent 4a0791e commit c5166f1

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

day13/d13.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,35 @@
33
sys.path.append('../common')
44
import intcode
55

6+
TILE_EMPTY = 0
7+
TILE_WALL = 1
8+
TILE_BLOCK = 2
9+
TILE_PADDLE = 3
10+
TILE_BALL = 4
11+
612
values = list(map(int, open('d13.in').read().strip().split(',')))
713
intcode.init(values)
814
output = intcode.runIntCode([])
915
screen = {}
1016
for i in range(len(output)//3):
1117
x,y, tile = output[i*3:i*3+3]
1218
screen[(x,y)] = tile
13-
print('Part 1:', sum([tile==2 for tile in screen.values()]))
19+
20+
def print_screen():
21+
for y in range(20):
22+
for x in range(40):
23+
if screen[(x,y)] == TILE_EMPTY:
24+
c = ' '
25+
elif screen[(x,y)] == TILE_WALL:
26+
c = '⬛️'
27+
elif screen[(x,y)] == TILE_BLOCK:
28+
c = '⬜️'
29+
elif screen[(x,y)] == TILE_PADDLE:
30+
c = '=='
31+
elif screen[(x,y)] == TILE_BALL:
32+
c = '⚫'
33+
print(c, end='')
34+
print()
35+
36+
print_screen()
37+
print('Part 1:', sum([tile==TILE_BLOCK for tile in screen.values()]))

day13/problem.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--- Day 13: Care Package ---
2+
As you ponder the solitude of space and the ever-increasing three-hour roundtrip for messages between you and Earth, you notice that the Space Mail Indicator Light is blinking. To help keep you sane, the Elves have sent you a care package.
3+
4+
It's a new game for the ship's arcade cabinet! Unfortunately, the arcade is all the way on the other end of the ship. Surely, it won't be hard to build your own - the care package even comes with schematics.
5+
6+
The arcade cabinet runs Intcode software like the game the Elves sent (your puzzle input). It has a primitive screen capable of drawing square tiles on a grid. The software draws tiles to the screen with output instructions: every three output instructions specify the x position (distance from the left), y position (distance from the top), and tile id. The tile id is interpreted as follows:
7+
8+
0 is an empty tile. No game object appears in this tile.
9+
1 is a wall tile. Walls are indestructible barriers.
10+
2 is a block tile. Blocks can be broken by the ball.
11+
3 is a horizontal paddle tile. The paddle is indestructible.
12+
4 is a ball tile. The ball moves diagonally and bounces off objects.
13+
For example, a sequence of output values like 1,2,3,6,5,4 would draw a horizontal paddle tile (1 tile from the left and 2 tiles from the top) and a ball tile (6 tiles from the left and 5 tiles from the top).
14+
15+
Start the game. How many block tiles are on the screen when the game exits?
16+
17+
--- Part Two ---
18+
The game didn't run because you didn't put in any quarters. Unfortunately, you did not bring any quarters. Memory address 0 represents the number of quarters that have been inserted; set it to 2 to play for free.
19+
20+
The arcade cabinet has a joystick that can move left and right. The software reads the position of the joystick with input instructions:
21+
22+
If the joystick is in the neutral position, provide 0.
23+
If the joystick is tilted to the left, provide -1.
24+
If the joystick is tilted to the right, provide 1.
25+
The arcade cabinet also has a segment display capable of showing a single number that represents the player's current score. When three output instructions specify X=-1, Y=0, the third output instruction is not a tile; the value instead specifies the new score to show in the segment display. For example, a sequence of output values like -1,0,12345 would show 12345 as the player's current score.
26+
27+
Beat the game by breaking all the blocks. What is your score after the last block is broken?

0 commit comments

Comments
 (0)