Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This is not using recursion since it is not a function that calls itself until some stop condition is met.
This is Python closure. The
b
parameter of each of the operand functions becomes a context of the function instance returned from those functions.In other words, the parameter is captured into the state of the generated lambda function.
This comment is hidden because it contains spoiler information about the solution
Yes - recursions are fascinating, however, be careful with them. Recursions could be double-edged swords...
Consider that each recursion level costs in memory on the stack. So if you have too many levels (self invocation) you would end up with a crash on lack of memory (or slowing down your whole computer as your code exhausts whole of the available memory).
In this specific case it is probably fine - we assume a number with a reasonable number of digits.
Note that this implementation has very high memory cost.
You accumulate the
multiples
list with all the numbers in the range before summing up - each number in the list holds an integer value type of memory.Consider what would happen if you run this with a very large number...