# Solving a Rullo Puzzle

How can I solve in a (relatively easy) way, a Rullo puzzle? (Screenshot below)

Rules: Enable or disable a circular number (pink is enabled) in order to make the row or column match the sum on the left / right or top / bottom

You can consider the circles with a darkened circumference have no special meaning.

My current strategy: Start solving rows / columns which require the least sum (10 in the case below - since it requires fewer numbers) then solve the ones with odd sums (17 and 15 - since odd + odd is even and even + even is even)

In the example below, once the 3 on row 4, col 4 is clicked, the board will be solved.

What algorithm / strategy can be used to solve such a puzzle? (the board will always be a square - eg. 3x3, 4x4, 5x5 etc)

The numbers inside will be between 1 (inclusive) and 19 (inclusive). Multiple solutions may be possible.

Source code for a brute-force program is allowed (provided it only takes a reasonable amount of time to solve a 8x8 board - eg. up to 10 minutes on your computer)

• In this example, the top row must include 7 (the rest doesn't even reach the required 15 for the row), and then the first column is forced. Then the second, third and fourth row are forced. In general, I'd look for rows/columns that have few ways to make the correct total (usually very high or very low total values), and check whether those few ways always include or always exclude a particular number. That included/excluded number then affects the ways its other row/column can be made, and so on. – Jaap Scherphuis Aug 12 '17 at 20:48

Using the below strategy, I was able to solve the above puzzle within two minutes:

• Choose Left to Right approach or Top to Bottom approach: choose across/down as the starting point and begin with the rows/columns having same sum (eg. 14 here in the 3rd and 4th row).
• For the 14 in the 3rd row, you need 9 and 5, you could choose 5 in 1st or 5th column. Say, you choose the 5th column. Maintain a queue and pop the first in (queues are First-In First-Out).
• So, we have 9 from Row 3, Column 4. We have solved row 3 already, let's solve column 4.
• So, we choose the 5 in the first row. Now, we move to the 5 in Row 3, Column 5 (remember we are saving in a queue). With the 5, the target sum 17 is possible with all other numbers(7,4,1) except 3. Now move to the 5 in Row 1, Column 4. Solve for 15 and so on.

So, basically you have a targeted sum and you're trying to reach the target with all possible combinations. Maintain a queue of the indexes of the numbers that solve that row and start by popping one out and solving the corresponding row/column.

Hope that helps.

We can get row 5 immediately:

 .....
.....
.....
.....
x98x7

(the sum must be 9+8+7, and column 3 tells us where the 8 is).

The 9 in row 5 gives the 5 in column 2:

 .....
.5...
.....
.....
x98x7


And then the 4 is row 2, column 3:

 .....
.54..
.....
.....
x98x7


We now know column 4 must have the 9 and 5 and no 3's:

 ...5.
.54x.
...9.
...x.
x98x7


Row 3 has no 3's:

 ...5.
.54x.
.xx9.
...x.
x98x7


Which gives columns 2 and 3:

 .x25.
.54x.
.xx9.
.64x.
x98x7


and the rest follows:

 7x251
354xx
xxx95
x64x4
x98x7


• My concern is that the OP seems to want a general strategy to solving Rullo puzzles, not just one that works in this instance – boboquack Aug 13 '17 at 9:47

Loop through all possible combinations of on/off for the numbers in a row, while respecting already established on/off locks. When a combination matches the targeted sum, keep track of which numbers are on and off. When you've looped through all possible combinations in that row, if a number is on in all possible correct combinations then lock it on, if a number is off in all possible correct combinations then lock it off. Move on to the next row, then do the same with columns. Repeat until the puzzle is solved or there is no more progress being made (some puzzles with multiple solutions).