### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,115)
- misc (2)
- project euler (2)
- puzzle (29)
- site news (43)
- tantalizer (29)
- teaser (3)

### Site Stats

- 166,357 hits

Programming Enigma Puzzles

15 October 2012

Posted by on **From New Scientist #2667, 2nd August 2008**

I drew a grid of squares with N rows and N columns and I wrote the numbers 1, 2, …, N² in the squares in the natural order (left to right; 1 to N in the top row, N+1 to 2N in the next, and so on).

I then cut up the grid into N pieces of various shapes, with each piece consisting of N squares. On each piece the total of the N numbers is less than 200 and is not divisible by 2, 3 or 5.

What is N?

[enigma1505]

Advertisements

%d bloggers like this:

I found it was fairly easy to write a program that gets the right answer, even if the program is incorrect. But I wanted to find all possible solutions, and came up with this recursive solution. It first finds how many possible pieces there are that satisfy the conditions, then finds subsets of these pieces that cover the board. It’s not as fast as I would like – it runs in 1m55s – but it does find all 203 solutions. (A similar approach that stops after it finds the first solution for each N runs in under 1s).

Solution:N = 6.