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|
nums = line.chomp.each_char.map(&:to_i)
largest_joltage = recurse(12, nums, [])
@sum += largest_joltage.join.to_i
memo = recurse(12, nums, [])
@sum += memo.join.to_i
end
puts @sum
end
def recurse(i, nums, largest_joltage)
return largest_joltage if i == 0
def recurse(i, nums, memo)
return memo if i == 0
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