Golomb Cages
Time limit1sMemory limit1024 MB
Fill each row and column with the given numbers once, so every two-cell cage matches its result under +, -, *, or /.
- Level
Medium6 of 10
- Topics
- Backtracking, Matrix, Brute force
- Solved
- No attempts yet
Problem
A Golomb Ruler is a set of integers in which all differences (e.g. |a-b|) are unique integers. The Atlantean game extends the Golomb Ruler to include sums, products, and quotients, where all results are positive integers. The set is an Atlantean Golomb Ruler that also satisfies the constraints of addition, multiplication, and division. For example, the numbers 2 and 10 from this set produce the results 12, 8, 20, and 5 on the operations +, -, *, and /, respectively. No other pair of numbers from the set produces these results.
Given an puzzle grid divided into cages, with a result for each cage, place the numbers from the set so that each row and each column contains every number from the set exactly once, and each cage resolves to its result under one of the four operations: addition, subtraction, multiplication, or division. The operands are not given.
Sample puzzle on the set

Resolves to this:

Input
The first line gives the grid size, the second line gives the number set, and the third line gives the number of cages. After that, each cage is given on its own line as its result, then the row and column of its first cell, then the row and column of its second cell. The first cell is at row 0, column 0.
Grid Size
Number Set
Number of cages
Result, grid location 1, grid location 2 (repeated for each cage)
The grid size is either 4 (4x4) or 6 (6x6). The number set is in ascending order and contains only positive integers greater than 1 and less than 100. Each cage has exactly two cells. A grid size of 0 marks the end of the input.
Output
Print the entire grid. Each number is written in a two-digit format, with a single space between numbers. Print a blank line between solution grids.