Advent of Code 2015 puzzles and solutions in AWK
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Day 01 - Not Quite Lisp
Day 02 - I Was Told There Would Be No Math
Day 03 - Perfectly Spherical Houses in a Vacuum
Day 04 - The Ideal Stocking Stuffer
Day 05 - Doesn't He Have Intern-Elves For This?
Day 06 - Probably a Fire Hazard
Day 07 - Some Assembly Required
Day 08 - Matchsticks
Day 09 - All in a Single Night
Day 10 - Elves Look, Elves Say
Day 11 - Corporate Policy
Day 12 -
Day 13 - Knights of the Dinner Table
Day 14 - Reindeer Olympics
Day 15 - Science for Hungry People
Day 16 - Aunt Sue
Day 17 - No Such Thing as Too Much
Day 18 - Like a GIF For Your Yard
Day 19 - Medicine for Rudolph
Day 20 - Infinite Elves and Infinite Houses
Day 21 - RPG Simulator 20XX
Day 22 - Wizard Simulator 20XX
Day 23 - Opening the Turing Lock
Day 24 - It Hangs in the Balance
Day 25 - Let It Snow

Build Status

Advent of Code 2015 puzzles solutions in AWK.

Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme.

Why AWK?

After solving the firsts two or three puzzle, I thought that AWK would be an ideal language. The puzzle input is (usually) to be parsed either line-by-line or sometimes character-by-character; AWK excel at both. As a results, solutions contain very few parsing related lines of code and can be focused on the problem.


Then Day 04 - The Ideal Stocking Stuffer required to compute a lot of MD5 hashes and it became quite challenging due to AWK's limitations. Using pipe has serious performance and portability impact, dynamic extensions is limited to Gawk and greatly limit usability. Implementing MD5 in pure AWK is tricky because it lacks bitwise operators (Gawk and busybox awk have them though).

Also puzzles gets harder as days goes by, to the point that finding elegant AWK solution become really challenging. The most outstanding limitations are:

  • There are very few built-in functions and (almost) all of them are string processing functions. Hasn't been a big issue since most challenges are mathematical puzzles.

  • Only two scalar types (if we omit regexp): strings and Double-precision floating-point numbers. This makes some stuff usually ubiquitous in "general purpose" programming languages (e.g. bitwise operations) a bit tricky.

  • It is not possible to return associative arrays from functions. This can be worked around by passing an array as parameter that is to be modified by the function.

  • The only composite type — associative arrays — is not recursive (values are limited to numbers or strings). Because of this, it is often hard to implement solutions able to solve the general case problem as they can require an "additional" dimension (e.g. 4 lines input vs arbitrary lines input). To work around this issue I've used multiple array subscripts (which is really only syntactic sugar), function recursion (basically using the call stack "as a dimension"), and serialization to string.