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.
¿Pero esto qué es?
Interesante. Muy buena. Pero tal vez esa primera línea se podría hacer
int q[n = l < n? l : n] = {};
para conservar memoria y ciclos.
No lo he probado, solo es una idea.
resolved
Fails for n==3 and m==4
C lang:
Submitted: {9848.07753012, 1736.48177667}
Expected: {9848.07753012, 1736.48177667}
Submitted: {781.444791958, 180.410745584}
Expected: {781.444791958, 180.410745584}
a b c d e f g ....
@MAFUS you are the best mate thank you so much. Everything is clear and it makes sense.
As you know in base 2 all odd numbers has the LSB (Least Significant Bit) set at 1:
0 : 0
1 : 1
2 : 10
3 : 11
4 : 100
5 : 101
[...]
On the other hand the number is given you as a string, aka a character sequence, and the characters are represented in ascii code, thats an integer. In the ascii table the digits representation starts with the 0, then 1, 2, and so on. The ascii code for '0' is 48, so while the digit is even his code is even too. That means I don't need to convert the character to its value to know if the digit is even or odd.
Well, I have an array of sums: sums[0] has the addition of all evens and sums[1] has the addition of all odds. I will use the digit itself to know if it is even or odd:
*digits - I take the digit of the string (his ascii code, remember)
& 1 - I take only his LSB. If it is 1 then the result of the operation is 1; If it is 0 then the result of the operation is 0. I use the result as the index of my array sums.
@MAFUS can you please explain how does code in the index works
I think:
9 10
910
91 - 2 digits
Te la has jugado con out[1]. malloc no pone a 0 los valores de la memoria adquirida.
It's true! I just realized now. Thanks.
This test appears only once. You badly interpret the output.
There is no error in tests:
For number: 170232833617690725 Got: 76, 7 (You returned 76, 7 - which is wrong)
For number: 170232833617690725 Expected: 0, 16 (It was expected 0, 16)
Error. Expected 0, 16 but got 76, 7 (Hence error with explanation)
Before posting issues look at the top of the page: 483 people passed the C kata... If there were errors somebody would have already seen them. Sorry. Cheers.
C lang. There is a badly planned test:
For number: 0 Expected: 0, 0
For number: 170232833617690725 Got: 76, 7
For number: 170232833617690725 Expected: 0, 16
Error. Expected 0, 16 but got 76, 7
The last two tests are the same but expect different solutions.
This comment is hidden because it contains spoiler information about the solution
Loading more items...