diff --git a/2023/ruby/day_08.rb b/2023/ruby/day_08.rb new file mode 100644 index 0000000..5f7c2b2 --- /dev/null +++ b/2023/ruby/day_08.rb @@ -0,0 +1,14 @@ +instructions, network = ARGF.read.split("\n\n") + +network = network + .scan(/(\w+) = \((\w+), (\w+)\)/) + .to_h { [_1, { L: _2, R: _3 }] } + +node = "AAA" +p instructions.chars.map(&:to_sym) + .cycle.with_index.lazy + .filter_map {|dir, i| + node = network.fetch(node).fetch(dir) + (node == "ZZZ") ? i+1 : nil + } + .first