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.
40% faster than
strconv.FormatInt
andstrconv.Itoa
? Amazing!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)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.
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.
Nice to see that someone has a smiliar solution to me.
@myjinxin2015 version looks slick af, but it is quite slow performance wise. Your ( @hei-yu-fa ) code does not look that good, but is twice as fast. It all comes down to what you are after.
@myjinxin2015 timed at 3870.2 milisec when called for nNumber = 5000
@hei-yu-fa timed at 1972.2 milisec when called for nNumber = 5000
Could not agree more! And 16 people think this is clever! The only way of which this code is clever, is in its way of making a simple statement hard to read.