Mayan Calculation puzzle discussion


#1

Feel free to send your feedback or ask some help here!


#3

It seem there is a bug because when i run tests then all tests are OK,
but when i submit the code then the result says that test ‘Base20’ fails.
I don’t know why this happens.


#4

Validation tests are slightly different. Check your code again


#5

My code passes all the tests but I have 0% when I submit. I know that the validation tests are slightly different but I would assume to at least pass the first ones.


#7

This seems to be solved. Thank you very much!


#8

Hello, there seems to be in issue in C with the starter code:

char operation[1];
    scanf("%s", operation);

of course this will provocate a buffer overflow error, the character buffer needs more space for the trailing zero and the newline characters. It works correctly when increasing the buffer space:

char operation[128];

But in general, it could be better to drop the scanf( “%s”, … ) altogether in favor of a solution using getline instead, in order to avoid completely the possibility of any buffer overflows.

Regards,


#9

I have no error when I run the provided code in C.


#10

Really? If i add the following debug printing line, after the 2 lines of code above:

fprintf( stderr, “L %d H %d S1 %d S2 %d operation %c\n”, L, H, S1, S2, operation[0] );

we see in the console “S2 0”, despite the operation parameter “seems” to be parsed correctly. Funny thing, if we try to print S2 before the 2 lines of code from my post, it shows “S2 4”. There are however no assignments to the variable S2 in the code, which means that there is a buffer overflow issue (contents on the stack are being corrupted by the instruction).

Are you sure there is no problem with the starter code for this?


#11

Actually he just said

Which means that it didn’t provoke a compilation error, but it sure will overflow because of the reasons you said.

But technically it’s not an error, it’s a bug, it doesn’t prevent the program from running, and in some times, it even helps to do trickery (like in code golfing).

Anyway, you’re right about the fact that the default code should be more secure than that.


#12

Need some help here to clarify the Missing Power test case. How do I know when power is supposed to be applied to the translation from Mayan numbers to regular numbers?

Can’t seem to find anything in the problem description that indicates this.


#13

There are zeroes when needed, look at the data in the test.


#14

Thanks… solved.


#15

I wrote code at PHP but Base20 fails while validation. Is there any problem with validation?


#16

Hi, i have a little bug …

At the beginning, i have :

int S2;
    char nb2[1000][20] = {0};
    scanf("%d", &S2);
    for (int i = 0; i < S2; i++) {
        scanf("%s", nb2[i]);
        fprintf(stderr, "%s et i = %d\n", nb2[i], i);
    }`

And it display :

o… et i = 0
… et i = 1
… et i = 2
… et i = 3

It’s good. But just after, i do :

int i = 0;
    while (i < S2)
    {
        fprintf(stderr, "%s et i = %d\n", nb2[i], i);
        i++;
    }

And it display :

et i = 0
… et i = 1
… et i = 2
… et i = 3

I lost the first line… Why ?? I do nothing between this two parts…

EDIT : It’s ok. It was the operation[1] which do this bug. I change it in operation[128].


#17

This puzzle could use an achievement for not using the build in functions to convert from base 20 to base 10. If you use one of these functions there is no puzzle left, only input parsing and output.


#18

Do you mean an achievement for people who write these conversions themselves instead of using built-ins (which do not exist in every language anyway), or for people who carry the operations directly in base 20?


#19

I think the intention of the puzzle is to do the conversion from base 20 to base 10 yourself. So it should be rewarded if you do it.

Not every language having the build in functions is another point. An achievement for doing it “the right way” would remove this disadvantage.


#20

I think that it’s easier to write it oneself than using built-in functions.


#21

I’m not coming up with the right output for great multiplication. Could this be an integer overflow issue?


#22

I have the same issue. There is probably something wrong in my code but it is hard to spot so I wonder if someone else had the same error and what was his issue ? Or if someone has extra “base20” validation code ?
Thx