[2024][ruby][11.x] refactoring

main
Alpha Chen 9 hours ago
parent 96d6e705ce
commit c05de086e0
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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]] }

Loading…
Cancel
Save