### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 178,002 hits

Advertisements

Programming Enigma Puzzles

26 September 2012

Posted by on **From New Scientist #2675, 27th September 2008**

I drew a regular polygon that had X sides and a second regular polygon that had Y sides. Just as my second polygon had (Y−X) more sides than my first polygon, so each internal angle of the second polygon was (Y−X) degrees greater than each internal angle of my first polygon. (X+Y) was a perfect square.

How many sides did each of my polygons have?

[enigma1513]

Advertisements

%d bloggers like this:

The following Python code runs in 32ms.

Solution:The first polygon has 9 sides. The second polygon polygon has 40 sides.I know it hardly matters in such a small case as this, but once you’ve determined X, you don’t need a loop to determine Y. As XY = 360 you can do it much more efficiently in one step:

Thanks for the hint.

By using divmod, 0.0003793778259527398 seconds process time,

reduced to 0.00030953654724273616 seconds process time, without Y loop.