|Chris Walker 1bec85dbec Commiting work so far||1 year ago|
|2016||1 year ago|
|2017||1 year ago|
|README.md||1 year ago|
|run.rb||1 year ago|
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
./run.rb [YYYY] [...D] [--test]
YYYYis the year, defaults to “this year”
...Dare space separated days, default is all days 1 to 25
--testrun any test problems for these days, rather than on the live input.
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.
Module.new do solution = Class.new do def test_problem_1 [["in", "out"]] end def problem_1(input) output = "?" end def test_problem_2 [["in", "out"]] end def problem_2(input) output = "??" end end AOC::register(solution.new) end