[Community Puzzle] Optimized coloring - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @flopy78,validated by @David_Augusto_Villa.
If you have any issues, feel free to ping them.

Image1

What is a ‘zone’ seems to be undefined.
It seems to me that the yellow area is a zone and the two green areas are two other zones.
But disappointingly using this common sense zoning will arrive at an answer different from the ‘correct’ one.

1 Like

I believe the rules could be more precise, especially regarding how ASCII characters should translate into exact shapes or zones on paper. Here are some example questions to illustrate the ambiguities I’m facing:

What is the difference between - and _?
Can I assume that each ASCII character corresponds to one cell on the paper sheet?
Can I use repeating characters like ||||, and if so, should I interpret there to be a boundary or “zone” between each pair of lines?
Is it possible to have a zone that doesn’t contain any spaces?
For example, given the following image:
image
Do lines 3-4 create a continuous boundary, similar to 5-6?
I find it clear that 11-12 forms a continuous boundary, but the distinction is less clear for pairs like 8-9. Additionally, text patterns like \__/ seem to imply a continuous border, as does \--/, but when drawn on paper, they might not look the same.
For a structure like 14-15, how should I interpret the number of zones within it?
In general, there are several unanswered questions, so I would appreciate if the rules could be made more precise overall.

A detailed example would be incredibly helpful—perhaps a complex ASCII drawing alongside a corresponding paper sheet illustration with clearly labeled zones (colored and numbered). Additional test cases, especially with minimal examples focusing on individual rules, would also be useful.

1 Like

If you look closely, the spaces you filled in yellow above the wheels are empty ! the “-” are adjacent, so you can’t go through it : the “yellow” zone is so not 1 but 3 areas…

I hope this will help you !

The areas are made of spaces, so there is no zones in ||||.
The 3-4 and 5-6 separately form continuous lines.

The difference between - and _ is just estethic, there should be no difference in the way they are processed.

You will never find a structure like teh 14-15 one. Though, there is no zone because there’s no spacing between the +.

I’ve added some precisions in the statement : I hope it will be clearer now

1 Like

Thank you!

You’re welcome !

I hope I was clear enough…

Finally I passed all tests, although I passed them after change in code, that I think is incorrect. In my view the problem is in adjacency of zones.
Here is image divided into zones (lower zones have id+10).
If I assume that zone 12 is adjacent to zone 11 and 14, then answer should be 4.
And for me this is the correct answer according to example of two adjacent zones (rectangulars) in problem description.

+---+       
|   +---+   
+---|   |    
    +---+  
--- +-------------------------------------------------+
--- |0000000000000000000000000000000000000000000000000|
--- |000000000----------------------000000000000000000|
--- |00000000/11111111|2222222|33333\00000000000000000|
--- |0-------\11111111|2222222|333333\0000000000000000|
--- |/44444444----------------+--------------------+00|
--- ||4444444444-----555555555+555555-----666666666|00|
--- |\444444444/7___8\55555555555555/9___0\66666666/00|
--- |1----------/222\----------------/333\--------/000|
--- |11111111111\___/4444444444444444\___/000000000000|
--- +-------------------------------------------------+
--- graph of adjacent zones
---    01234 56789 01234
--- 0  01111 01000 10010
--- 1  10101 10000 00000
--- 2  11010 10000 00000
--- 3  10100 10000 00000
--- 4  11000 00100 01000
--- 5  01110 00011 00001
--- 6  10000 00000 10000
--- 7  00001 00000 01100
--- 8  00000 10000 00101
--- 9  00000 10000 00011
--- 10 10000 01000 00010
--- 11 00001 00100 00100
--- 12 00000 00110 01001
--- 13 10000 00001 10001
--- 14 00000 10011 00110

Either I am wrong (then I would like to explain what is wrong in my understanding) or I passed all tests due to their incompleteness. I would like to see how to color the car image with 3 colors.

How to colour the image with 3 colours:

+-------------------------------------------------+
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|
|AAAAAAAAA----------------------AAAAAAAAAAAAAAAAAA|
|AAAAAAAA/BBBBBBBB|CCCCCCC|BBBBB\AAAAAAAAAAAAAAAAA|
|A-------\BBBBBBBB|CCCCCCC|BBBBBB\AAAAAAAAAAAAAAAA|
|/CCCCCCCC----------------+--------------------+AA|
||CCCCCCCCCC-----AAAAAAAAA+AAAAAA-----BBBBBBBBB|AA|
|\CCCCCCCCC/A___B\AAAAAAAAAAAAAA/B___A\BBBBBBBB/AA|
|A----------/CCC\----------------/CCC\--------/AAA|
|AAAAAAAAAAA\___/BBBBBBBBBBBBBBBB\___/AAAAAAAAAAAA|
+-------------------------------------------------+

And the graph of adjacent zones:

---    01234 56789 01234
--- 0  01111 01000 00000 <-
--- 1  10101 10000 00000
--- 2  11010 10000 00000
--- 3  10100 10000 00000
--- 4  11000 00100 01000
--- 5  01110 00011 00001
--- 6  10000 00000 10000
--- 7  00001 00000 00100 <-
--- 8  00000 10000 00100 <-
--- 9  00000 10000 00010 <-
--- 10 10000 01000 00010
--- 11 00001 00000 00000 <-
--- 12 00000 00110 00000 <-
--- 13 10000 00001 10000 <-
--- 14 00000 10000 00000 <-
1 Like

Hi there !
I pass all the validators but the 7th (“Draws!”). As I passed the 7th test, I don’t understand my mistake… Is there someone who can relate or who can help me understand ?

If you want, you may send me your code in private message and I’ll take a look.

Hi. I can’t understand why there are 3 colors in the second test and not 4. Can you explain to me?

1
According to the screenshot, there are 4 colors

You can colour the lower right region as 1, and the lower left region as 2, so that you don’t have to use colour 3.

1 Like

Continuing the discussion from [Community Puzzle] Optimized coloring - Puzzle discussion:

I have written two solutions - one with a greedy approach and one with a backtracking approach - that solve all the test cases correctly; and all the validation cases correctly with the exception of the validation case “05 GRID”. However, the validation case does not provide any output, so I am not sure what’s my error for the validation case.

Could anyone help me?

Other than that: loved the puzzle. Thank you @flopy78 and @David_Augusto_Villa

Guys, stop this “Continuing the discussion from…” nonsense. Just post in the relevant puzzle thread, no need to make a new one for a single puzzle-related question.

You’d better send me your solutions !

This way I could see what’s wrong…

Thank you flopy78 for offering to help. This is much appreciated.

Here is my code. It works for all validation cases, except 05 GRID.

[Mod edit: Please avoid posting a full code or a link to a full code on the forum. You should send that via private message instead.]

Thanks