[Community Puzzle] Fix the spaces

I was not quite correct with what I wrote earlier. After identifying that the standalone ‘A’ must cover the 1st ‘A’, both of the remaining words (‘AB’ and ‘ABA’) each have two remaining candidate positions. To solve this with logic, I had to look at each of the uncovered letters in the original string. It turns out the last ‘A’ in the string can only be covered by a single candidate word, leading to the full solution with no guessing.

Just to be clear, I don’t recommend anyone do what I did. This puzzle is definitely a better fit for backtracking which provides a much more concise and fast solution. The logic approach was just fun!

1 Like

To break it you just have to try to put “two choices for each furthest_right and furthest_left” and insert some fun in the middle.

ABABABA
AB ABA BA

Expected solution
AB ABA BA

Your first logic won’t work since ABA_ocurrences = 1 < ABA_possible positions and same for AB and BA. The second logic won’t work since ABA and BA mess with the furthest_right and AB and ABA with the furthest_left.

Note that your current implementation doesn’t solve this one either:

ABABABA
ABA B ABA

Expected solution
ABA B ABA

Embrace the braindead backtrack my friend.

NB: Apparently I don’t know how to reply to a post? I just clicked the reply button under the comment but it doesn’t show the top box with the quote to the post I replied. Help.

2 Likes

Try selecting part of the text in the other post first, before you click Reply :wink:

1 Like

Reluctantly, I admit defeat. I see nothing I can do with this. Well played!

1 Like

Ended up adding two tests (yes… again…), nº12 (Actually solvable 4) and nº13 (Actually solvable 5). For the reasoning behind you can see the previous conversation . As usual sorry to anyone involved. The tests are nº12:

ABABABA
AB ABA BA

Expected solution
AB ABA BA

and nº13:

ABABABA
ABA B ABA

Expected solution
ABA B ABA

They might seem almost equal yet the second one can give a different result from the first in some implementations (I’m mainly talking about @Timinator’s, where the first gives unsolvable while in the second we get a “ValueError: min() arg is an empty sequence”).

And that will be all. Until a new contender appears I guess.

And what about real words ? :smile:

You still could build a sentence (albeit very artificial) with those edge cases.

WHATISADADADADISAFATHER
WHAT IS A DAD A DAD IS A FATHER

practically identical to test nº14, and as I just checked, timinator’s code will get a “ValueError: min() arg is an empty sequence”.

Ou en français:

TOUTESSAISONSETETEETHIVER
TOUTES SAISONS ET ETE ET HIVER

et à nouveau “ValueError: min() arg is an empty sequence”.

It’s impressive how fast you find a real sentence with the same traps.
I think it would be much more interesting than ABABABABA.

I finally bruteforced it with a simple recursive DFS. I pass all tests.

oke… good puzzle… i’have tried two methods but backtrack… got 93% in both… i think next time i will try backtrack :slight_smile:

Added another test (nº14, Actually solvable 6). I don’t think I can explain the rationale behind it without spoiling (even more than what I already have) the solution of the puzzle so I’ll just put the test here. If you are curious you can solve it in cpp and check if the solution that passes every test but this one is still there:

AABABAA
AA B A B AA

Expected solution
AA B A B AA

Also, you’d probably assume that it’s the case, but there’s a hidden constraint (that I should have stated somewhere, but I don’t see how, without, again, spoiling it even more) that the underlying graphs are simple enough to not timeout when backtracking.

Now I won’t add such a test because it’s supposed to be an easy puzzle, but if anyone wants to give it a try, here’s one that times out every python / cpp solution that I’ve tested (except for @Timinator’s solution, funnily enough) while respecting all the constraints (the expected solution is just the second line):

AAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAABAAAAAAAAAAAAABAAAAAAAAAAAABAAAAAAAAAAABAAAAAAAAAABAAAAAAAAABAAAAAAAABAAAAAAABAAAAAABAAAAABAAAABAAABAABAB
AAAAAAAAAAAAAAAAAAAA B AAAAAAAAAAAAAAAAAAA B AAAAAAAAAAAAAAAAAA B AAAAAAAAAAAAAAAAA B AAAAAAAAAAAAAAAA B AAAAAAAAAAAAAAA B AAAAAAAAAAAAAA B AAAAAAAAAAAAA B AAAAAAAAAAAA B AAAAAAAAAAA B AAAAAAAAAA B AAAAAAAAA B AAAAAAAA B AAAAAAA B AAAAAA B AAAAA B AAAA B AAA B AA B A B

I pass it with my logical solution ^^ solution updated, it will work if you add it.

1 Like

Nono I won’t add it. In all truth I don’t think the puzzle is solvable in that case, at least not with the 200 words constraint. It’s not hard to add a “non logically solvable” bit to the previous test to make the logical solution fail (like adding XYXYXYX to the end plus the words XY XYX YX as in test 12). The only fully working solution I see is to backtrack and then you are at the will of graph structure. Maybe you could add some clever heuristics along the way but even then I don’t see how you could entirely explore every possible remaining option in the allowed time limit.

And unless there is a very good reason, one should not keep editing a puzzle after it has been approved :wink:

1 Like

I’m not laughing. I’m grinning ear to ear! Who’s ready for the next logic challenge? With my puzzle “Killer Sudoku Extreme Challenge”, my goal all along was to create a puzzle that required significant amounts of logic before backtracking would even have a chance. For the hardcore, a solution with zero backtracking is indeed possible:

Killer Sudoku Extreme Challenge

Easy puzzle, seriously ?

1 Like

There are two solutions : STAR STARS TAR and STARS TAR STAR

Indeed can someone correct test 8 :slight_smile:
Debug messages… STARSTARSTAR
Debug messages… STARS TAR STAR

just cut after position 4 and 7 and you got it
so it’s not “Unsolvable”

Unsolvable because there are 2 possible solutions.
STARS TAR STAR
STAR STARS TAR