You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
469 B
22 lines
469 B
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
|