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.
response to old question on performance:
my understanding is because the divisions are all repetition and the Math.Log is all repetition.
combined altogether, youre doing approximately more loops than what you think jt should be doing.
You have absolutely no idea what you're talking about. This is an equation based on math equations since the discovery of Euler's number in the 1700's. It's probably the easiest way to solve this problem, provided you understand the math and remember the formula. Personally, I solved this w/ a while loop b/c I couldn't remember the formula w/o checking, but your analysis is f-----g absurd.
I solved the kata with while loop, but have exactly no idea what's going on here.
Seems like you are a type of guy who would calculate 9 * 9 by adding 9 nine times instead of using a multiplication table
ofc, always keeping that in mind since highschool, just in case.
Is here a meeting of people who studied economics, but gave up on their profession? 😅
thats cool tho
I tried to do this, but couldn't get the brackets in the right position. Just gave up with a while loop.
I suck.
I'm sort of a js noob, how did you compare the execution times and with what inputs? I tried using something called perflink and somehow got the exact opposite result?
A lot of people are really up their own behinds about this not being the best practice, thinking that it's because coders don't know basic math instead of the fact that the computation time on this O(n) is over twice as long as a while loop. Elitists are often not elite, and the comments on this solution are the proof.
Faster to type, but not faster to compute. It takes over twice as long for the computer to accomplish this task than a while loop. Hopefully in the past three years you've come to realize the compounding importance of this and perhaps grown some perspective on why you may not always be right, while looking down on others less.
Sometimes single-line/method-chaining/nested-methods can be the coolest, easiest to read, most performant way to do something. Other times it a self-gratifying, useless, tortured attempt to say, "look, I can do this with on a single line!" This is certainly the latter. Single line does not necessarily equal good.
How can log(x) be O(1)? I need to take an algorithms course I guess :)
I compared by
console.time
andconsole.timeEnd
surrounding the test cases.O(1)
solution.Logarithm calculation can be implemented w/
O(logn)
, right?Why does the standard
O(n)
while loop solution run twice as fast as this one?~13ms avg vs ~30ms avg.
Am I wrong assuming this one should be faster?
I have noticed a pattern on codewars that anytime some basic math can solve a problem an overly complicated brute force method tends to win out over the simple and faster mathematical solution.
Loading more items...