[Community Puzzle] 7-segment scanner

https://www.codingame.com/training/easy/7-segment-scanner

Send your feedback or ask for help here!

Created by @tutubalin,validated by @Djoums,@LastRick and @Dridriun.
If you have any issues, feel free to ping them.

Nice easy puzzle. Stub for input should be changed from string maxlength of 300 to 900, because last ide test is 300 digits = 900 chars per line in display.

3 Likes

Hello everyone.
I tried solving this problem using C. I found a bug where when the first line starts with a space character, that character gets skipped when reading with either of:

  • fgets
  • scanf("%c", …)
    This bug seems only to happen with “CUSTOM” inputs, when running the test cases, it seems to work correctly.
1 Like

I observed this phenomenon also in Python. This is most probably not a C problem.

They probably apply some kind of chomp for custom testcases to deal with \n\r problems.

A side effect is that it removes spaces too.

Has anyone ever solve this using Lua

If you have troubles solving this puzzle with Lua, directly ask your precise question, if somebody can help you, he will. But if you just want to know if someones solved it with Lua, consider I haven’t said nothing. :wink:

I just translated my Python solution to see if there was any problem in Lua, it worked fine.
You can use a table digit = {}, and associate any string representing a digit to its value, for example digit[" _ | ||_|"] = 0.
Then it’s just about slicing the input with string.sub and displaying the digits (note that unlike most languages, indexes start at 1 instead of 0).
You can display digits one by one on the same line by using io.write instead of print.

1 Like

Hey, I’m stuck in the last testcase using PHP.
I tried to debug the input lines for the super long number, but I think it might be broken?
I’m just printing the content of the lines as debug vars, but I can’t see any ascii numbers (when if I run the same code for the first tests it outputs the proper number).

Thanks!

The console is limited in size, and will not display too long outputs. But you can see the tests inputs by clicking on the list icon above the test zone.

2 Likes

I finally solved it. Even tho the puzzle description stated that the max string length was 300, I had to increase the default snipet they left for us to read up to 900 characters (aparently, when it says 300, it means 300 digits instead of chars). So beware about that, the default fread should probably be changed. (I posting this because I don’t think that’s part of the solution intended to be found).

3 Likes

You’re right. That can be a problem in some languages…
I will edit the statement to make it clearer on that point.

2 Likes

Hey, I had the same problem so I changed the stream_get_line as below:

$line1 = stream_get_line(STDIN, 900 + 1, “\n”);
$line2 = stream_get_line(STDIN, 900 + 1, “\n”);
$line3 = stream_get_line(STDIN, 900 + 1, “\n”);