diff --git a/2024/ruby/day_11.rb b/2024/ruby/day_11.rb index 3f6c8cc..864680b 100644 --- a/2024/ruby/day_11.rb +++ b/2024/ruby/day_11.rb @@ -6,14 +6,15 @@ blink = Hash.new {|h, k| 1 elsif n.zero? h[[1, times-1]] - elsif (s = n.to_s.size) && s.even? - a, b = [n.to_s[0...s/2], n.to_s[s/2..]].map(&:to_i) + elsif n.digits.length.even? + a, b = n.divmod(10**(d.length/2)) h[[a, times-1]] + h[[b, times-1]] else h[[n*2024, times-1]] end } +pp stones.sum { blink[[_1, 6]] } pp stones.sum { blink[[_1, 25]] } pp stones.sum { blink[[_1, 75]] }