Advent of Code puzzles.
Chris Walker 1bec85dbec Commiting work so far 1 year ago
2016 Commiting work so far 1 year ago
2017 Commiting work so far 1 year ago Moar code 1 year ago
run.rb Haven't committed for a while. Dangerous. 1 year ago

Advent of Code

Solutions to the Advent of Code problems.

I wanted to learn Ruby, so I started the 2016 problems in ruby, in late November 2017.

It’s now December 2017, so I’ll start on the 2017 problems in Ruby as well

Running the code

./run.rb [YYYY] [...D] [--test]

  • YYYY is the year, defaults to “this year”
  • ...D are space separated days, default is all days 1 to 25
  • --test run any test problems for these days, rather than on the live input.

Template for solutions:

Turns out that loading code via a file is not ruby-like (I think). I.e. the equivalent in most other languages is:

some_variable = load_module("some_module")

But ruby doesn’t seem to have the required, file-local scoping for globals and methods, so the easiest way to emulate this behaviour was to use anonymous modules (meaning they cannot clash with another namespace, and anonymous classes for local scoping) and have each one “register” back to the main class and from there we can put the solution in a local map.

Seems there ought to be another way, but I couldn’t find it. (yet.)

So this is the code, that goes in each day’s solution. do
    solution = do
        def test_problem_1
            [["in", "out"]]
        def problem_1(input)
            output = "?"
        def test_problem_2
            [["in", "out"]]
        def problem_2(input)
            output = "??"