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 comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Ok, thanks.
This comment is hidden because it contains spoiler information about the solution
Hi @Rockkley.
Lambdas are anonymous callable objects. If you want call it later, you must use a variable, no other choice to do that. And here (in codewars) if there no name, unit test cannot check the solution.
For your information, in python, a
def
(and so, a fonction) defined like that create a variable:The variable created is
foobar
, the proof, you can do that:It's the aim of the mechanism under the concept of decorators.
If you prefer i can use these solutions instead of lambda, the solution will be acepted:
With small
arr
, there can be no re-allocation.We can improve that with a pre-allocated array:
visited := make([int]*int, len(arr) - 1)
.Yes sometimes using memory in the right way (when input data allow it) can greatly optimize a program like tables of sinus in ancient architechtures which hasn't got any mathematical processor.
A recursive version if not optimized at compile time generate extra assemby instruction for creating/destroying a stack context for a function call. The context contains temporary variable, caller arguments, and the return for the instruction pointer. Iterative version keeps the same stack context, no need to manage life cycle of called context, so it's faster cause less instructions to execute.
A teminal recusion can be easily optimized at compile time can be do by «de-recursivate», i.e. transform a recusive algorithm by an iterative one through the use of its own stack with a fast use of this stack. GCC do that for example.
I'd like that these languages to be added too: Smalltalk and Ada
Thank you.
Yeah, you are right. Sometimes i choose the easy way.
Maybe, iterative version is easy too: https://www.codewars.com/kata/reviews/5d6ddad7e78d210001f76504/groups/5d809b2c01af06000163ed61 .
bravo, beautiful algorithm !
Me too
.
Loading more items...