DEV Community

Discussion on: Advent of Code 2019 Solution Megathread - Day 13: Care Package

Collapse
 
neilgall profile image
Neil Gall

Pretty straightforward today, which was nice after yesterday's tricky part 2 that I haven't solved yet (I didn't have as much time as usual). I adapted the idea from the painting robot to screen drawing, and used a very simple input logic for part 2 to make the paddle track the ball's x coordinate.

opcode screen_input(void *io_context) {
    struct screen *screen = (struct screen *)io_context;

    if (screen->paddle_x < screen->ball_x)
        return 1;
    else if (screen->paddle_x > screen->ball_x)
        return -1;
    else
        return 0;
}

Job done!