Skip to content

aschmied/advent-of-code-2016

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code 2016

This repo contains my solutions to the Advent of Code 2016 puzzles. I'm reading Martin's Clean Code book while solving these, so I'm trying to apply the principles from that book.

My Favourite Solutions

Because it contains this method:

def aba_to_bab(self, aba):
  a = aba[0]
  b = aba[1]
  return b + a + b

There is a small LCD screen controlled by a simple scripting language and we need to determine the text on the screen after a given sequence of instructions.

A Screen object stores the screen state and provides an interface for its manipulation, Instruction objects manipulate the screen, and a parser reads text and constructs a sequence of instruction objects.

We are given a compressed input and asked to determine the length of the output. The input is compressed by a run-length scheme. A string like (mxn) in the input means the m bytes following the ) should be repeated n times in the output. In the first part of the puzzle recursive repeats are ignored: if a repeat sequence appears in a repeated string then we treat the repeat sequence like normal bytes. In the second part recursive repeats are allowed.

I solved part 1 by decoding the input. For part 2 the problem description suggests we calculate the length of the decoded text without actually decoding it. A recursive approach works.

Example

I tested these with Python 2.7.8. Run them like:

cd day01
python main.py

Each solution has unit tests:

cd day01
python -m unittest discover

About

My solutions to the Advent of Code 2016 puzzles

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages