AoC 2016 Day 4: Room Validator

Source: Security Through Obscurity1

Part 1: A room is described as a name, a sector ID, and a checksum as follows:

aaaaa-bbb-z-y-x-123[abxyz]

name: aaaaa-bbb-z-y-x sector ID: 123 checksum: abxyz


> A room is valid if the checksum contains the five most common letters if the name (ties broken alphabetically).





An interesting problem. The first thing that we have to do is parse the input:

```python
with open(args.input_file, 'r') as fin:
    for room in fin:
        m = re.match(r'([a-z-]+)-(\d+)\[([a-z]+)\]', room)
        name, sector_id, checksum = m.groups()

        ...

The next thing we want to do is generate a checksum (so we can see if it’s correct):

read more...


AoC 2016 Day 2: Pin Typer

Source: Bathroom Security

Part 1: Take a keypad with the following layout:

1 2 3 4 5 6 7 8 9


> Using the instructions UDLR for Up, Down, Left, and Right respectively, move a 'finger' around over the keypad. At the end of each line of instructions, output the current digit.





First, let's define the grid. We'll use the same trick with complex numbers as [last time]https://blog.jverkamp.com/2016/12/01/aoc-2016-day-1-taxicab-simulator/.

```python
grid = {
    '-1-1j': 1, '+0-1j': 2, '+1-1j': 3,
    '-1+0j': 4, '+0+0j': 5, '+1+0j': 6,
    '-1+1j': 7, '+0+1j': 8, '+1+1j': 9,
}

From there, we can move around the grid, make sure we don’t move off the end, and output a character at the end of each line:

read more...