Skip to content

Instantly share code, notes, and snippets.

@sarahzrf
Created December 6, 2021 16:48
Show Gist options
  • Save sarahzrf/61898598a1b0e91f1bc31ed111d2aafe to your computer and use it in GitHub Desktop.
Save sarahzrf/61898598a1b0e91f1bc31ed111d2aafe to your computer and use it in GitHub Desktop.
def advance(fish)
new_fish = Hash.new(0)
fish.each do |timer, count|
if timer > 0
new_fish[timer - 1] += count
elsif timer == 0
new_fish[6] += count
new_fish[8] += count
else
raise "wtf?"
end
end
new_fish
end
count_by_timer = Hash.new(0)
gets.chomp.split(',').map(&:to_i).each do |n|
count_by_timer[n] += 1
end
80.times do
count_by_timer = advance count_by_timer
end
print count_by_timer.sum {|_, count| count}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment