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.
After you see the algo you will think, wow that was quite easy :D
I honestly don't recall if that has been the case, sorry.
When I saw the procided solutions from other users I also
realized that it didn't matter what the input number was
but I just felt it wasn't very well stated in the description.
So I got a bit confused.
wow, i didn't expect that way of solve it... i guess i should improve with algorithms
Java Translate is ready, please cheack it :D
Now do it without loop, in
O(1)
;)It should be 7/8 kyu, but it was funny to solve it
PHP translation is ready! Please check and approve
Oh, sorry. I've just added it, tell me if i did something wrong plz
No random tests, no one approve it.
That is wrong.
Java Translation is ready! Check it and approve
https://www.codewars.com/kumite/5f3bf591d0e11a00106f4f52?sel=5f3bf591d0e11a00106f4f52
Thanks you :D. It clarifies more things to me, to be honest... xD
That's because how type promotions work in C.
This will not work:
long toRet = firstNumber + secondNumber
because result of addition of two ints is also an int, so addition overflows, and then such overflowed result is assigned totoRet
. Addition result is not extended tolong
until actual assignment.However, these two will work:
long toRet = (long)firstNumber + secondNumber
, andreturn (long)firstNumber + secondNumber
They work because you explicitly promote one of operands to
long
, so actual addition is performed with longs and does not overflow.Main difference is: in the first case, you work with ints and you add two ints, receiving int in the result. In two remaining cases, you cast one operand to long, the other gets implicitly promoted to long, so you perform addition on two longs.
This comment is hidden because it contains spoiler information about the solution
Loading more items...