CGX Formatter puzzle discussion

There can be spaces in the original CGX content almost everywhere : before and after parenthesis, semicolons, and equal signs.
Everywhere a space can be, you can also encounter TABULATION (’\t’) ! I had a hard time figuring this, as you can pass all the test cases without handling tabulations, but not final tests.
Java
There are certainly many ways to solve this puzzle, so my solution is only an exemple. I never studied parsers or lexers, so my approche is probably quite “naive”, and lacks efficiency. But it gives a cool example of inheritance / polymorphism, very important concepts of OOP.

[no full code please]

[no ad please]

[no full code please]

Hope this code will help you.

Hi everyone,

I can’t pass the validator #6 (simple key/value with spaces), and I can’t really figure out why.

I have already read the posts mentionning this issue, but I still don’t really understand.

The examples are using this input :
["(‘key’=‘value’)"], which gives with my code the right result:
(
‘key’=‘value’
)

With my code, all this variant with spaces and tabs gives the same answer :["\t \t (‘key’ \t \t = \t \t ‘value’)"]

So I don’t really get which space can be misleading in the validator #6

Does anyone have a clue? :slight_smile:

Thanks!

hello
i have the same problem (#6) and I think it’s something like
(key=my key;)
without quotes but I am not sure

@V.Antoine @fireproof75
Re: validator #6 (simple key/value with spaces)
Do these comments help?
https://forum.codingame.com/t/cgx-formatter-puzzle-discussion/22/52
https://forum.codingame.com/t/cgx-formatter-puzzle-discussion/22/84

1 Like

@5DN1L thanks a lot for your answer!

I already had to look to those comments, but unfortunately it doesn’t seem to be the same issue:

With input ["(\n’key’= t\nr u\ne\n)"], (example from comment #1), I obtain:
(
‘key’=true
)
which seems to be the right answer.

So I’m really confused…

So I finally got 100% thanks to @5DN1L !

The case that made me realize my mistake is the following:
((tr ue)
;(f
alse) ; (0))

Once I fixed this issue, the validator #6 was ok :slight_smile:

3 Likes

Validator Empty string of characters with spaces (number 5) seems to have 3 lines. The line number 2 should have 2 spaces, then 2 quotes. Two other lines (line number 1 and line number 3) sould have between 1 and 3 spaces.

same here. any news one year later ?

For those getting 95% only failing the test Block with spaces containing a value, it is needed to ignore whitespaces and tab characters as well.
So for example for this block:

(tr u e)

The expected result is:

(
    true
)

while for this other block:

(tr\tue)

The expected result is:

(
    true
)

I hope this helps

Hi,

I think I have tested all the additional tests on this topic but I still can’t pass 2 validators:

  • validator #7 - Simple key/value with block
  • validator #14 - Block containing a string of characters without spaces

Do you have an idea of a test that would allow me to debug these validators?

Not sure if relevant/useful, but have you tried all the cases listed in the statement? A few of them are not included in the test cases.

Thanks for the proposal @5DN1L, indeed I had not seen that it was different.

I discovered that the last test did not pass. Unfortunately, after debugging, I realized that it was from the copy and paste. There are 3 characters that have a negative value (how is this possible!?).

Échec
Trouvé :     )
Attendu :     \-30\-128\-117)

So I adapted my code to ignore the negative characters but I get the same result in the validators.
So I’m still at the same point…

You may send me your code in PM and I’ll try to see if I can find the issue.

Thanks to @5DN1L who found a failed test with my code.

If validators #7 and #14 don’t work for you, here is the test that 5DN1L gave me and that allowed me to finish this puzzle:

1
(('string_of_chars'))
1 Like

Combining all the input lines into one to work with did it for me, I already had a working program but I didn’t consider this admittedly somewhat cruel case, thank you so much :partying_face:

Hi,

I am stuck at 95%. There is only one last validator that I didn’t managed to pass :

  • Validator #4 “Simple string of characters which must not be modified”.

I have tried all the tests suggested in this topic, and all passed successfully.
I really don’t understand what tricky case I missed.

Does anyone has an idea about what look like this validator #4 ?
Thanks for your suggestions

Maybe only the CG staff knows what the validators are like for this puzzle (as it is not created by the community)?

You may PM your code to me to have a look and try figuring out what may go wrong.

Think u missed parsing ‘=’ or ‘;’ inside primitive string. Like ‘blah blah =; blah blah’…

Test cases not covered case with semicolon inside string. Would be nice also have some name conditions for KEY_VALUE type, so I have not searched ‘=’ in key for example. Maybe it is obviously that key cant have ‘=’ but in such tasks I think must be name conditions…

In case some people have an issue with Validator 17 (Sequences of blocks and strings) or Validator 19 (CGX using every formatting rules), they may find the case below useful for debugging:

Input:

10
'users'=(null;'free';('id'=10;
'name'='Serge';
'roles'=('visitor';
'moderator'
));
721831;('id'=11;
'name'='Biales'
);
true
)

Output:

'users'=
(
    null;
    'free';
    (
        'id'=10;
        'name'='Serge';
        'roles'=
        (
            'visitor';
            'moderator'
        )
    );
    721831;
    (
        'id'=11;
        'name'='Biales'
    );
    true
)