CGX Formatter puzzle discussion

If you see the raw input, you can see, that there are not only tabs you have to look for there are also ‘newlines’ -> ‘\n’. I forgot to watch out for these and, in my case, to do nothing if they appear.

are you talking about test cases (and not validators)?
not my case :frowning: as I have troubles with validators
all test cases passed but not validators

You can see in my description above, that I’ve passed the tests too and only failed at two of the validations.
Which validations are failing when you try to submit?

I’m crazy!

All test passed, but the validator ‘CGX using every formatting rules’ not!!!
I don’t know how resolve this trouble !!!

Anybody have a hard test to i execute in my code?

(Sorry the bad english)

At submission I have an issue with only one test : Simple key/value with spaces
All the other tests are handled properly.

CvxFous gave the following test case :
( ’ ke y ’ = ’ va lue ’ )
But not the answer expected,
Should it be
’ ke y ‘=’ va lue ’
The space in the key name are kept unchanged (it should be treated like a standard string)
’ key ‘=’ va lue ’
The key name has to be cleaned up

Or did I miss something and the results should be different from the two cases I gave ?

Thanks for your help

As far as I remember you also have to deal with values containing spaces and line breaks but no quotes.

For example

    'key'=        t
   r      u

should output


Thank you for your help that was exactly my issue here

I have issue with “Sequences of blocks and strings”. Any idea how those tests looks like or what I should focus on? All other tests except “CGX using every formatting rules” passes. Could I miss any rule?

1 Like

something like that : [ \t true \t ] and [ \t ’ i like cookies \t ’ \t ]

I started by compiling the input into a proper tree, remembering stuff I learned from my university days. After failing to write a compiler and thinking more about the problem, I realised the whole thing can be done by string manipulation only.

The only thing I had to identify from the input is the string literals (since I don’t want to change any spacing within a string). The rest of the puzzle is solved just by adding line breaks and indentations. :slight_smile: My solution is only about 70 lines long, without any subroutines and extra data structures.

1 Like

The Q&A here has been very helpful in finding my own blind spots. I seem to still have one lingering out there, though. Of the 20 final validators, I am stuck on #4 “Simple string of characters which must not be modified”.

If the “simple string” contains a newline character (which must not be modified), how is it to be presented? It seems that if it is part of a block, text after the newline should also be indented. But then that modifies the simple string.

I have tried both indenting and not indenting text after a newline buried in a “simple string”, and neither case is liked by the #4 validator. Of course, perhaps text inside a pair of quotes with a newline in between would no longer be “simple”. But I can’t figure out why the heck this simple case, of all others, fails. :slight_smile:


I started thinking about “\n” appearing in the INPUT, but the instructions say that all characters are ASCII, thus you would not see a “\n”, but rather text on the next line.

An example I am chewing on:


possible output
// the implicit newline is made explicit


// the implicit newline is removed

I tried both ways and I could not get #4 to pass. Again, this is assuming that a string with a newline is “simple”. If not, this point is moot, but I have no idea why #4 is failing for me.

I pass all validators except “Block containing a sequence of key/value”. Any idea what could be wrong?

Edit: Found it, I had ignored “;” after booleans and null.

1 Like

Indeed i was also at 95%, i was failing at the test Block without spaces not containing a value
I was not handling the following properly:
( ) <= that’s many spaces between the brackets
was giving me:

instead of:

100% now :slight_smile:


Hello everybody,

in the description it writes that we work with regex to resolve it.
But i resolve it without regex. Someone resolve it with One regex?


Same as @psvilela for me. Pass all the others validators and test cases but this one.
Any strong or difficult debuggable test cases would be really appreciated ! :grinning:


Now sloved at 100%. Think about empty strings…

I took this as an opportunity to try out my skills on regexes, used several of them in perl PCRE. Will try POSIX Extended RE later. No problems while submitting, the regex resolved the special cases for me :slight_smile:

I get 95% complete. I can’t get the “Block with spaces containing a value” to pass. Can anyone think of what is meant?

Thanks in advance.

Can’t pass the last test because my code is too slow.
Tried in IDE and it takes 1.4 sec to execute.
Am I the only one looping char by char? :frowning: