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 (s = n.to_s.size) && s.even? a, b = [n.to_s[0...s/2], n.to_s[s/2..]].map(&:to_i) h[[a, times-1]] + h[[b, times-1]] else h[[n*2024, times-1]] end } pp stones.sum { blink[[_1, 25]] } pp stones.sum { blink[[_1, 75]] } __END__ 125 17