[Community Puzzle] Detective Pikaptcha EP1

Please don’t share (almost) working code.
I see that your algorithm is working, and I guess your issue come from a bad interaction between C++ streams and your C-like code (Mostly from the char arrays).
I haven’t investigated much, but I’m almost sure that if you try the same, simply replacing the char arrays by strings, this is gonna work.

1 Like

By the way @Thalken , in your code you do ai_map[i][j] = char(int(ai_map[i][j]) + 1); on the cells that initially hold ‘0’. This is useless and makes me suppose you didn’t quite understand what ‘char’ is, so I’ll commit a little explanation:

‘char’ is an integer type, like ‘int’, but its numeric value can be interpreted as a character, following the ASCII table, in some cases. So keep in mind that your cell doesn’t contain 0, but 48, which is the ASCII code of the ‘0’ character. When you do int(ai_map[i][j]) in your code, you don’t convert the ‘0’ character to the 0 integer, you convert the 48 integer to… an integer (the difference is that ‘int’ can hold bigger numbers). Then you increment it by one, giving 49 which is the ASCII code of the ‘1’ character, and finally convert it back to a ‘char’. Knowing that, you can simply do ai_map[i][j]++; which give the exact same result, in less steps.

To convert a digit character to the corresponding integer, you can subtract ‘0’ to it (The character, not the integer, so 48 :stuck_out_tongue: ), like this: ai_map[i][j] - '0'. The atoi() function do the same, but isn’t standard, and so not supported by every compiler.

Hope it’s clearer.

1 Like

Thank you for the explanation, it worked. Coming from Python, I have to look up a lot of things regarding data types and pointers. I thought I had to create an iterator if I wanted to use strings. It seemed easier to use an array, especially if its size was known at the begining.