rename arr buf to memo

This commit is contained in:
onyx-and-iris 2025-12-04 00:34:52 +00:00
parent 08da9593cc
commit 2a3c0d36a0

View File

@ -7,20 +7,20 @@ class Main
$stdin.each_line do |line| $stdin.each_line do |line|
nums = line.chomp.each_char.map(&:to_i) nums = line.chomp.each_char.map(&:to_i)
largest_joltage = recurse(12, nums, []) memo = recurse(12, nums, [])
@sum += largest_joltage.join.to_i @sum += memo.join.to_i
end end
puts @sum puts @sum
end end
def recurse(i, nums, largest_joltage) def recurse(i, nums, memo)
return largest_joltage if i == 0 return memo if i == 0
max = nums[..-i].max max = nums[..-i].max
largest_joltage << max memo << max
recurse(i - 1, nums[nums.find_index(max) + 1..], largest_joltage) recurse(i - 1, nums[nums.find_index(max) + 1..], memo)
end end
end end