[2023][ruby][8.2] til about Integer#lcm

main
Alpha Chen 12 months ago
parent 5d7fc5b308
commit ca65631b37
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -23,8 +23,4 @@ p steps.("AAA", /ZZZ/)
# part two # part two
nodes = network.keys.select { _1.end_with?(?A) } nodes = network.keys.select { _1.end_with?(?A) }
node_steps = nodes.map { steps.(_1, /Z$/) } node_steps = nodes.map { steps.(_1, /Z$/) }
p node_steps p node_steps.inject(1, :lcm)
.map { Prime.prime_division(_1).to_h }
.inject {|acc, fac| acc.merge(fac) {|_,old,new| [old, new].max}}
.map { _1**_2 }
.inject(:*)

Loading…
Cancel
Save