[Community Puzzle] Optimized coloring - Puzzle discussion

I think there’s still some misunderstanding. The statement mentions:

Each ASCII character fills a “cell” of the sheet of paper : the shape of the characters have no importance, it’s just aestethic.

Yes I understand that.
That’s why I replaced the symbols with the same as the statement, to compare the “Draws!” test case with the top first example:

If you turn the top first example 90 degrees clockwise, they have the same patterns. But zones 11 and 7 are not considered adjacent in the test case, so the top first example is wrong. It doesn’t show two adjacent zones

The top first example is like that (if you replace spaces with ‘o’ and borders with ‘#’:

#####
#ooo#####
#####ooo#
    #####

If you turn it 90° clockwise:

 ###
 #o#
 #o#
 #o#
####
#o#
#o#
#o#
###

Now crop the first and last 3 lines, replace last line space with a border:

 #o#
####
#o#
###

Do the same for the previous example with zones 7 and 11:

 #7#
####
11#
###

You can see they are the same

1 Like

I think @Malleek has found a legitimate inconsistency. As written, my solution would not identify these two zones as adjacent. As I look through all the test cases and validators, this situation is never tested. (Which explains why I can pass all the tests and validators, of course.)

@Malleek - I can’t say that the statement example is right or wrong, since it does not appear to show up in any test cases or validators. You have said it is wrong because they “don’t share a border”. @flopy78 uses the phrase " if they share, at least partially, a border". What exactly does it mean to “partially” share a border in terms of corners? I don’t think there is enough information to answer that question. And, without new tests/validators, I’m not sure the answer matters.

I vote to make a slight adjustment to the statement example. That’s a lot easier than adding test cases and/or validators that break some solutions (including mine :cry:). Unless somebody else has another idea, these are the only two paths I see to eliminate the inconsistency.

@DavidAugustoVilla, @flopy78 - any thoughts?

Yes it is tested! It’s the purpose of my previous posts! In the test case “Draws!”, here are the 2 zones highlighted 7 and 11 (the numbers replace spaces):

+-------------------------------------------------+
|                                                 |
|         ----------------------                  |
|        /        |       |     \                 |
| -------\        |       |      \                |
|/        ----------------+--------------------+  |
||          -----         +      -----         |  |
|\         /7___ \              / ___ \        /  |
| ----------/   \----------------/   \--------/   |
|         11\___/                \___/            |
+-------------------------------------------------+

After replacing symbols with ‘#’, it gives the small example of my previous post:

+-------------------------------------------------+
|                                                 |
|         ----------------------                  |
|        /        |       |     \                 |
| -------\        |       |      \                |
|/        ----------------+--------------------+  |
||          -----         +      -----         |  |
|\         #7#__ \              / ___ \        /  |
| --------###   \----------------/   \--------/   |
|         11#___/                \___/            |
+---------###-------------------------------------+

They should be considered as “partially shared” borders according to the statement top first example. If you highlight “partially shared” borders, it may be clearer:

 #7#
#@@
11#
###

+---+
|   @---+
+---@   |
    +---+

1 Like

I stand corrected. It is tested. And, now the answer to Test Case 7 should be 4 instead of 3, right?

You’re right to point out the inconsistency. I stand corrected.

I don’t think this is the biggest issue. The statement specifies:

Each ASCII character fills a “cell” of the sheet of paper : the shape of the characters have no importance, it’s just aestethic.

From this, I’d interpret that two zones share a border as long as they have more than one “border character” in common, whether at a corner or along an edge.

The bigger issue, in my view, is how the border of a zone is actually defined. The statement is silent on this point. For example, in Test 7, should the two areas marked A below be considered having a shared border or not or just touching diagonally? It depends on whether the \ character below the leftmost A is treated as the border of the bigger area or not:

||          -----         +      -----         |AA|
|\         / ___ \              / ___A\        /AA|
| ----------/   \----------------/   \--------/AAA|
|           \___/                \___/AAAAAAAAAAAA|
+-------------------------------------------------+

My revised code does give 4, while the answer to the following custom case is 3 in my view:

13
8
+-----------+
|           |
| +---+     |
| |   +---+ |
| +---|   | |
|     +---+ |
|           |
+-----------+

But I hesitate to revise any cases because that would involve revising the author’s solution too.

If we don’t want to change the cases, then we’ll have to work on revising the statement.

1 Like

I never look at borders. I only look at empty space in zones. For each combination of two zones, the zones are neighbors if the following is satisfied for at least one combination of twos cells, one from each zone:

My original test:

(abs(r1 - r2) == 2 and c1 == c2) or (abs(c1 - c2) == 2 and r1 == r2)

My new test:

(abs(r1 - r2) == 2 and abs(c1 - c2) <= 1) or (abs(c1 - c2) == 2 and abs(r1 - r2) <= 1)

Assuming the following figure is valid, are A and B adjacent?

+--------+
|   A    |
|  +-----|
|--+|    |
|  \B\   |
+--------+

No, not for my original test, nor my new test. There is only one open space in B and that space doesn’t satisfy either of my two rules above with any of the spaces in A.

1 Like

I propose the following:

  • No changes to the cases so that the author’s code need not be revised and the existing submitted solution codes won’t become broken.

  • Changes to the statement to avoid any mentioning of shared borders/corners / diagonal touching:

    Original

    Two zones are considered as adjacent if they share, at least partially, a border.

    For instance, these pairs of zones are adjacent :
    
    +---+         +---+
    |   +---+     |   |
    +---|   |     +-+-+-+
        +---+       |   |
                    +---+
    
    Warning : two zones touching diagonally are not adjacent.
    
    For instance, these zones are not adjacent :
    
    +---+
    |   |
    +---+---+
        |   |
        +---+
    

    Revised

    Two zones are considered adjacent if there is at least one pair of spaces, one from each zone, such that they are separated either horizontally or vertically by a single non-space character.

    Below are two examples of adjacent zones:
    
    +---+
    |   |         +---+
    |   +---+     |   |
    |   |   |     +-+-+-+
    +---+   |       |   |
        |   |       +---+
        +---+
    
    Below are two examples of zones which are not adjacent:
    
    +---+         +---+
    |   +---+     |   |
    +---|   |     +---+---+
        +---+         |   |
                      +---+
    
    

Please let me know if you have any feedback, and I’ll modify the statement next week.

3 Likes