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.
I declared my variables as unsigned long long int and I have also changed the return type to this. It worked.
You've got a typo in the first two math equations, instead of r variable, b should be used.
I just tried it, there are no issues.
It's a wrong assumption that
long
is always 32 bits.long
is not less thanint
and not less than 32 bits. In 64-bit Linux it's 64 bits.You are probably converting to
unsigned long
when it's too late and the result is already truncated (at best; or even more likely undefined).I tried to change the function to unsigned long but I get the same error.
And what's the message now? VS C++ uses 32 bit, but here it's 64 bit... and there are better ways to force 64 bits on different platforms? Many comments for a small solution of a simple kata. Fact is, there's no overflow here and no VS C++;-)!
long is platform dependant (has 4 bytes on 32 bit platforms, then you have to use long long or __int64 (eg. look here https://msdn.microsoft.com/en-us/en-en/library/s3f49ktz.aspx)).
The most correct way of doing this is to use stdint.h header (from C99) and then use int64_t which is platform independant and is always 64bit.
This comment is hidden because it contains spoiler information about the solution
ExtendedTest3
✘ Expected: equal to 4000000000
Actual: -294967296
C++ version has prototype: long sumTwoSmallestNumbers(std::vector n), it is IMPOSSIBLE to have 4000000000 as answer
It's a "long" which has 8 Byte or 64 Bit, try sizeof(m) which is 8... so there's no problem, because all the others are only int.
It is rather bad as 9999999999 overflows (0x2_540B_E3FF) and 32 bit architectures use 0x7FFFFFFF as max for signed int.
This comment is hidden because it contains spoiler information about the solution