Skip to content

Instantly share code, notes, and snippets.

@carlwiedemann
Created December 11, 2024 05:49
Show Gist options
  • Save carlwiedemann/fea5ef40921e30a179a9941437832974 to your computer and use it in GitHub Desktop.
Save carlwiedemann/fea5ef40921e30a179a9941437832974 to your computer and use it in GitHub Desktop.
Advent of Code 2024 day011.rb
require_relative "main"
module Day011
INPUT = File.read("INPUT.txt")
s = INPUT.split.map { [_1.to_i, 1] }.to_h
convert = ->(n) do
return [1] if n == 0
t = n.to_s
ll = t.length / 2
t.length.even? ? [t[0...ll].to_i, t[ll..].to_i] : [n * 2024]
end
75.times do |i|
s = s.each_with_object(Hash.new { |h, k| h[k] = 0 }) do |(k, v), a|
convert.call(k).each { a[_1] += v }
end
# Part 1
if i == 24
answer1 = s.values.sum
pp answer1
end
end
# Part 2
answer2 = s.values.sum
pp answer2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment