day08: Day 08: I Heard You Like Registers

Description Usage Arguments Details Examples

Description

I Heard You Like Registers

Usage

1

Arguments

lines

a character vector of commands to run

Details

Part One

You receive a signal directly from the CPU. Because of your recent assistance with jump instructions, it would like you to compute the result of a series of unusual register instructions.

Each instruction consists of several parts: the register to modify, whether to increase or decrease that register's value, the amount by which to increase or decrease it, and a condition. If the condition fails, skip the instruction without modifying the register. The registers all start at 0. The instructions look like this:

1
2
3
4
b inc 5 if a > 1
a inc 1 if b < 5
c dec -10 if a >= 1
c inc -20 if c == 10

These instructions would be processed as follows:

After this process, the largest value in any register is 1.

You might also encounter &lt;= (less than or equal to) or != (not equal to). However, the CPU doesn't have the bandwidth to tell you what all the registers are named, and leaves that to you to determine.

What is the largest value in any register after completing the instructions in your puzzle input?

Part Two

To be safe, the CPU also needs to know the highest value held in any register during this process so that it can decide how much memory to allocate to these operations. For example, in the above instructions, the highest value ever held was 10 (in register c after the third instruction was evaluated).

Examples

1
2
3
4
5
6
lines <- "
b inc 5 if a > 1
a inc 1 if b < 5
c dec -10 if a >= 1
c inc -20 if c == 10"
str(run_register_instructions(lines))

tjmahr/adventofcode17 documentation built on May 30, 2019, 2:29 p.m.