[2023][ruby][8.2] til about Integer#lcm
change nzxmlsspwnwtymszosuqyxqpkomkoxln
commit 3e19ad7330ce65371d1a10238a33d3dec53de772
author Alpha Chen <alpha@kejadlen.dev>
date
parent zsxqpnpu
diff --git a/2023/ruby/day_08.rb b/2023/ruby/day_08.rb
index 92e73f9..4eb1990 100644
--- a/2023/ruby/day_08.rb
+++ b/2023/ruby/day_08.rb
@@ -23,8 +23,4 @@ p steps.("AAA", /ZZZ/)
 # part two
 nodes = network.keys.select { _1.end_with?(?A) }
 node_steps = nodes.map { steps.(_1, /Z$/) }
-p node_steps
-  .map { Prime.prime_division(_1).to_h }
-  .inject {|acc, fac| acc.merge(fac) {|_,old,new| [old, new].max}}
-  .map { _1**_2 }
-  .inject(:*)
+p node_steps.inject(1, :lcm)