[2023][ruby][8.1]

main
Alpha Chen 1 year ago
parent ee07a6130e
commit 794e3db35a
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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…
Cancel
Save