Relax output checking to ignore trailing spaces

In many problems the output is a list of n elements which must be output as follows:

X1 X2 X3 ... Xn

(each element being separated from the next one by a space character)
Depending on the language, producing the required output can be painful (e.g. easy in python/ruby, painful in C/Java). The easiest way to code this is to add a space each time an element is output in the loop:

    print(X[i] + " ");

Obviously this kind of code adds an additional space at the end.
Obtaining the strict output is not difficult but requires time and more code to write (code which is not fun to write and which brings nothing to the user).
This is penalizing in CoC (in all modes : speed, size and even reverse) and boring in practice puzzles.

A simple solution would be to ignore trailing spaces when checking the solution. This is very simple to implement on the server and would make a lot of people happy :wink:

1 Like

Use trim in most languages. Also use Join for joining lists onto strings.

Thank you for your answer and your proposal solution. But this requires to create a String. BTW trim() (in Java) removes leading AND trailing spaces (this is not good an ASCII art puzzles). Anyway, this kind of solution is both time/space consuming and do not bring anything from the algorithmic point of view, That’s the point :wink:
I would prefer the trim (of trailing spaces) be done on the server side…

Some (bad) community puzzles have a space at the end of the answer. I don’t like ASCII art puzzles so if you want my own opinion we should remove them from codingame.

But, since this kind of puzzle exists, codingame just can’t always trim outputs.

@Magus I didn’t see puzzles expecting spaces at the end (even in ASCII art puzzles). I suppose this is very confusing for players (since spaces at the end cannot be shown in the statement examples). This is an additional reason to remove trailing spaces BOTH in submitted solutions (as I mentioned in my first post) but also in submitted problems (ie. in the expected outputs).

Correct output is a good practice. If the problem ask you to output a space at the end then that’s the correct way. If it says no spaces at the end , that’s the correct output.

This post can be closed, thank you. :grin:

With your argument you can keep everything as it is now. Thus a forum called “Platform evolution” does not make sense. Intelligent answer is a good practice too…

Oh god, I wholeheartedly agree with you.
Codingame should propose an option to relax check spaces.
Like 90% of the puzzles need you to print space separated list, it’s a pain in… when you need to check those line endings.
If trailing spaces are part of the answer, it should be fully disclaimed in the puzzle description.

We don’t want to promote sloppy coding. If no space is expected at the end, no space should be added.


Is “sloppy coding” really a concern in CG ! Especially in CoC !
CG is based on “output checking”. The written code is never studied, only output concordance is checked. This is perfectly admissible for a site like CG, but it has no way to check for “sloppy coding”.
For example, I thank that “hardcoded soutions” are much more “sloppy” than accepting extra spaces at the end of the outputs…

Most puzzles are in a mindset of “spaces at the end of the answers are totally irrelevant to the challenge at hand.” As they should.

Making each puzzle a formatting challenge independently of its main topic sounds like a plan to remove a lot of the “game” from “codin”.

Most puzzles I/O are already inconsistent, in that a lot of them do not \n-terminate the last line of expected output, as opposed to all others. Conversely, most of the CoC shortest solutions rely on the fact that a \n is not needed for most single-line outputs.

I wish we could just ban ASCII art low quality posts and have an appropriate class of output matching on a puzzle-by-puzzle basis. But that’s not happening anytime soon, is it?

In programming “abc” is not the same as "abc ". So one of them is valid and the other is not. I did some competitive programming at UVA online judge and they do not allow extra spaces, they want the exact solution.

And codingame is not a mmorpg. Is a job oriented system. If you want to be a proffesional programmer you should know that if the analyst tell you to output something (with or without spaces) then you should do that. And if it is boring is because much of the time programming is not fun or daring. It’s tedious.

I’ve never had a job as a programmer, and probably never will. But i know it.

So if I summarize your argument,

  • you don’t know what professional programming is like,
  • you’d like CodinGame to be tedious because that’s what you think programming is like,
  • you think in absolutes,

is that correct?

I mean, you’re entitled to your opinion as much as anybody else, but I differ in most every aspect of that reasoning, as well as the validity of either your abc or your analyst claims.

I always forget why i don’t write in forums, or chats, or speak with people. My bad.
So if you want ask for magical things , do it. It won’t happen anyway.

You’re welcome! :smiley:

The logically correct word ordering was: “if you don’t ask for things, they won’t magically happen.”

I fully agree with JBM. Programming is most of the time funny / interesting / challenging /… It is sometimes tedious (like anything done professionally, e.g. think to sport). But recall the CG slogan: coding is a game. This site is here to motivate people to learn programming and to improve their coding skills not to discourage them with an invisible trailing space… If we can “remove” tedious tasks without altering the core of the algorithm to write, let’s do it !

An alternative option, would be to let the puzzle’s author to decide if extra spaces are allowed. This could be done with an on/off flag (whose default value would be ON). This information would appear in the “constraints” part of the problem statement.

1 Like