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.
calm down
40% faster than
strconv.FormatInt
andstrconv.Itoa
? Amazing!This comment is hidden because it contains spoiler information about the solution
Why is Sprintf best when Itoa is 5 times faster in performance tests?
I like how overengineered this solution is ^^
I like how much faster the
strconv.Itoa
operation is thanfmt.Sprint
(according to benchmark at https://gist.github.com/evalphobia/caee1602969a640a4530)He didn't see my solution :)
It's not scalable, but it solves this kata.
Interesting solution, but would be hard to program for a building with 100 floors (or even 10)
The variables did absolutely help with readability. For me, your code was the easiest to read.
Yeah you're right it is. I looked at some benchmarking and it's about 50-100ms faster depending on the run, tbh it just wasn't something I thought about haha. I'll keep it in mind for the future though! Thanks for pointing it out :)
Looking at it even more I don't even need those variables but I think it helps the readability in this case.
Nicely done. But why do you redefine the "timeForLunaHome" and the "meetTime" variable. Is it not better only define them once outside the while loop?
1+2=3 (1th triangular number)
1+2+3=6 (2dn triangular number)
1+2+3+4=10 (3d triangular number)
1+2+3+4+5=15 (4th triangular number)
1+2+3+4+5+6=21 (5th triangular number)
1+2+...+13+14 = 105 (13th triangular number)
given n, return the sum of the triangular numbers 1 to n.
n=2 gives 3+6=9.
I just compared the commented code to code by @IonutArhire.
On my computer, the commented code took 15.5 seconds to exicute on an array with 500'000 elements of length 4 and k = 1000. Code by IonutArhire took 0.081 seconds. I am amazed by the difference!
My code took 0.71 seconds which is 20 times faster than the commented code, but still 10 times slover than the code of @IonutArhire.
@IonutArhire, could you please let me know why your code is so much faster than mine?
You could either see it as future proofing in case someone decides to increase the array but forget to update the return statement, or see it as over-engineering since "phrases.length" will always be 6.
Either way, cool solution.
Loading more items...