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.
It's perfectly fine to iterate over the characters of a line looking for the first comment marker. It's even much more efficient in terms of runtime, see my other comment! And it can be beautiful too, have a look at my solution.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Hi, actually, function 1 is called when python interpret the line that contain @function1. So it call it like this: function1(function2). This is redefining the function2 to what function1 returns.
If function1 return function2, later calls to function2 will indeed execute the code of function 2.
In the case of this solution, as memoized function is returning the wrapped function, later calls to fibonacci actually will call wrapped function (that has inside it the original fibonacci function).
So, when the interpreter reads the line "@memoized", it calls the memoized function (like this memoized(fibonnacci) ). Then it creates the empty dictionary and return the wrapper function. This way the dictionary is not redefined to empty at every call to fibonacci function.
The dictionary is still saved at the memory and the wrapper function has a reference to it.
Later call to fibonacci function will indeed call the wrapper function because the memoized functoin redefined it to wrapper function.
Interesting idea! Probably should be more efficient)