Good time a day.
Could you explain how to solve this task, which you can see by that link: https://www.codewars.com/kata/61559bc4ead5b1004f1aba83/train/python ?
I couldn`t solve it and unlock solution of case. The best practice was
def spiral_sum(size):
return (size + 1) * (size + 1) // 2 - 1
I don`t understand the best solution.
Could you explain this formula? I know that is more mathematic then programming, but I don`t understand the idea of solution.
Thank you for help.
I would solve it recursively.
For odd values, $f(n) = n^2 - f(n-2) - 1$
For even values, $f(n)=n^2 - f(n-2) - 2$