stones = DATA.read.scan(/\d+/).map(&:to_i) blink = Hash.new {|h, k| n, times = k h[k] = if times.zero? 1 elsif n.zero? h[[1, times-1]] 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]] } __END__ 125 17