parent
ee07a6130e
commit
794e3db35a
@ -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
|
Loading…
Reference in new issue