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 feels like overhead but still clever
how dare this be so beautiful
Thank you!
Ok, thanks.
Please, use spoiler flag next time.
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:
I know that lambda is anonymous function, and there's no need to create variable for lambda, but here we need to meet the interface requirements. Requirement here is that
check
is callable.In real world I would not create function for this one liner, that's why I'm showing solution with
lambda
.variable "check" holds the function. and ambda describes the oneliner function.
mult = lambda a,b:a*b
is the same as
def mult(a,b):
return a*b
What do you mean? Do you know how lambdas work? Do you know you can copy the code and make trials on your own to understand how it works? On your own computer, or just here, by clicking on
Fork
just below any solution.Why creating a variable for lambda?
clever use of mapping :)
After finding prime p with another prime at p + g, your program checks next g numbers for in-between primes, but if it actaully finds prime in-between, then that check is redundant since the outer for loop will go over it anyway.
So, your program basically does some extra looping.
Nice to see that Golden Ratio and Fibonacci properties are interleaving to produce
O(1)
and0(log n)
algorithmsHow to simplify Bessel+Kepler's formula...
N = Log(Sqrt(X / Phi) * Phi * Sqrt(5)) / Log(Phi)
into your form
N = Log(5 * X / math.Phi) / (2 * Log(Phi))
to get the index of the nearest Fib number?
Or this is to get the shortest term instead of the largest?
Moreover,
fib
function needs apply a correction factor to avoid loss precision and get the floor directlyF(n) = ((phi^n) + (1 - phi)^n) / sqrt(5)
Please fork and re-publish your translation. Cannot approve because there are some merge conflicts.
Loading more items...