Question

Here is the problem I am trying to solve: http://www.hpcodewars.org/past/cw16/problems/2013ProblemSetFinalPost.pdf go to problem number 20. It is called Waffle Stacking.

You have a 5x5 square grid. On each square of the grid you can build a stack of waffles, with its height ranging from 1 to 5. Around the edge of the grid are some numeric clues. Your task is to build a stack of waffles on every square, in such a way that:
• Each row contains every possible height of the waffle stack once
• Each column contains every possible height of the waffle stack once
• Each numeric clue describes the number of waffle stacks that can be seen if you look into the row or column from that direction, assuming that shorter waffle stacks are hidden behind taller ones. For example, a clue marked ‘5’ indicates that the five waffle stacks must appear in increasing order (otherwise you would not be able to see all five waffle stacks), whereas a clue marked ‘1’ indicates that the tallest waffle stack (the one marked 5) must come first.

Input:
enter image description here

Output:
enter image description here

The first line of input shows the clues for the top of each column. The next 5 lines of input show the clues for the left and right sides of the diagram for each row. The final line of input shows the clues for the bottom of each column.
2 2 3 2 1
4 1
1 4
3 2
2 2
3 2
3 2 1 3 4
Your program should print the 5x5 grid, with a space between each square in a row.
1 3 2 4 5
5 2 4 3 1
2 1 3 5 4
4 5 1 2 3
3 4 5 1 2

I have started by saying that if there is a 1, the 5 must be right next to it, so I immediately place the 5 in a solution grid. After that, I am stuck! I have tried brute force, but it takes too long to be practical in a contest setting.

Is there any viable solution to this problem?

Thanks

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top