mirror of
https://github.com/onyx-and-iris/aoc2025.git
synced 2025-12-08 11:47:47 +00:00
rename arr buf to memo
This commit is contained in:
parent
08da9593cc
commit
2a3c0d36a0
12
day_03/2.rb
12
day_03/2.rb
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user