[Community Puzzle] Crossword

https://www.codingame.com/training/medium/crossword

Send your feedback or ask for help here!

Created by @Humanosaure,validated by @IAmNoob,@CarlWalsh and @wlesavo.
If you have any issues, feel free to ping them.

Nice double problem. For me, print the solution was more complex than find them. :slight_smile:

3 Likes

Hi Caduchon, do you have some hint for this? :slight_smile: I can’t think of a way to find the solutions.
I was thinking to start by finding all the intersections but then it’s not clear to me what to do with them in very complex cases. Thank you.

Search the letters that match.

Hi nicola, yes thank you, that is what I meant for “intersections”, I’ve already got to that part. What is not clear to me is how you can determine the different solutions once you have all the letters that match.

Use brute-force.
There are only 4 ways to build a “#” by 2 horizontal and 2 vertical lines. Try out all of them to find the only way to make 4 common joints.

4 Likes

Yes, brute force.
My solution contains 4 for nested loops.

1 Like

I’d think about what it means to be a match, ie what is the criteria. Finding intersections are a good idea, that’s what I did and using the different sets of intersections, I went from there.

Hey there :wink:
Thanks for the puzzle.

I sadly have a problem, hope you can help and maybe specify.

in test case 12 I get the result:

........C..
.AWAAAAAXAA
BBYBBBBBZB.
..D.....C..
..D.....C..
..D........

But I get the message:

Failure

Found:
…C…
Expected:
0

should there be a condition that h1 comes before h2 and v1 left from v2?Preformatted text

The two horizontal words must be at least one row apart from each other.

If you don’t follow this rule you create multiple 2 letter words in the crossword grid as well as adding the words you were meant to add.

2 Likes

@RoboStac thanks, that helps.
Thought 1 row apart meant ‘not in the same row’ but this makes a lot of sense!

This puzzle is great ! Handling the indexes drove me mad, but it was good :smiley:
My solution nests 6 for loops. Maybe someone smart could rephrase it with 4 loops but it does not seem obvious.

1 Like

Great puzzle. I tried a recursive approach but wasn’t very successful, ended up nesting loops like everyone :smiley:

1 Like

One of my dirties solutions for sure.
For the output part I went nobrain, ended up putthing everything in a matrix with w, h = len(h1)+len(h2), len(v1)+len(v2) to make sure the dimensions are big enough,
and THEN killing empty rows and columns to adjust.

IMO this problem should belong to the Hard section.

1 Like

Super cool puzzle! Well done @Humanosaure! For anybody looking to eliminate some of those nested for loops, see if your language has a pre-built cartesian product function. Python’s itertools.product helped me clean things up a bunch.