I forgot and missed this one :(
Just a simple equation. Loop over all the numbers and sum up the values.
Similar to part 1, but you have to do the equation recursively and sum up the values until the cost of what is left is <= 0
(mass <= 6
). I did this with memoization to avoid repeated calculations, but after realized that the calculation is log(n)
, so you can definitely just do it with a simple loop.