mirror of
https://github.com/onyx-and-iris/aoc2025.git
synced 2025-12-08 11:47:47 +00:00
28 lines
504 B
Ruby
Executable File
28 lines
504 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
class Main
|
|
def run
|
|
@sum = 0
|
|
|
|
$stdin.each_line do |line|
|
|
nums = line.chomp.each_char.map(&:to_i)
|
|
largest_joltage = recurse(12, nums, [])
|
|
@sum += largest_joltage.join.to_i
|
|
end
|
|
|
|
puts @sum
|
|
end
|
|
|
|
def recurse(i, nums, largest_joltage)
|
|
return largest_joltage if i == 0
|
|
|
|
max = nums[..-i].max
|
|
largest_joltage << max
|
|
|
|
recurse(i - 1, nums[nums.find_index(max) + 1..], largest_joltage)
|
|
end
|
|
end
|
|
|
|
Main.new.run
|