[2024][ruby][11.2]

main
Alpha Chen 4 weeks ago
parent 09db2ae1a0
commit 86081b2b0b
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -1,18 +1,21 @@
stones = DATA.read.scan(/\d+/).map(&:to_i) stones = DATA.read.scan(/\d+/).map(&:to_i)
25.times { blink = Hash.new {|h, k|
stones = stones.flat_map {|n| n, times = k
if n.zero? h[k] = if times.zero?
[1] 1
elsif (s = n.to_s.size) && s.even? elsif n.zero?
[n.to_s[0...s/2], n.to_s[s/2..]].map(&:to_i) h[[1, times-1]]
else elsif (s = n.to_s.size) && s.even?
[n * 2024] a, b = [n.to_s[0...s/2], n.to_s[s/2..]].map(&:to_i)
end h[[a, times-1]] + h[[b, times-1]]
} else
h[[n*2024, times-1]]
end
} }
pp stones.length pp stones.sum { blink[[_1, 25]] }
pp stones.sum { blink[[_1, 75]] }
__END__ __END__
1750884 193 866395 7 1158 31 35216 0 125 17

Loading…
Cancel
Save