Skip to content

Commit

Permalink
Add 2024, day 11, second part
Browse files Browse the repository at this point in the history
  • Loading branch information
bewuethr committed Dec 12, 2024
1 parent f408540 commit 3ba0ceb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 2024/day11/day11b
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby

def blink(n)
if n == "0"
["1"]
elsif n.length.even?
[n[...n.length / 2], n[n.length / 2..].to_i.to_s]
else
[(n.to_i * 2024).to_s]
end
end

stones = File.read(ARGV[0]).split

stone_count = stones.tally

75.times do |i|
new_count = Hash.new(0)
stone_count.keys.each do |key|
blink(key).each { new_count[_1] += stone_count[key] }
end

stone_count = new_count
end

puts stone_count.values.sum

0 comments on commit 3ba0ceb

Please sign in to comment.