### Random Post

### Recent Posts

### Recent Comments

Hugh Casement on Enigma 1070: Time to work | |

Jim Randell on Enigma 1070: Time to work | |

Jim Randell on Enigma 1070: Time to work | |

geoffrounce on Enigma 440: Three X | |

Jim Randell on Enigma 1588: As easy as 1… |

### Archives

### Categories

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

### Site Stats

- 177,567 hits

Advertisements

This Python program calculates the centre of mass for each arrangement of tubes, and then determines the smallest of the numbers corresponding to balanced discs. Since it’s using Python’s

floatsit checks the centre of mass is “close enough” to the centre of the disc. For a completely accurate (but slower) solution, you can importsin, cos, pifromsympy(instead ofmath), and check of the centre of mass corresponds exactly to the centre of the disc – you get the same results.The Python program below runs in 291ms (under PyPy).

Solution:The smallest 11-digit number is 10145892367.Here is a version that avoids the approximations involved in using floating point arithmetic by using complex integers (x + i.y with x and y integer) to represent the algebraic cosine and sine values.

Here is another variation. The reasoning behind the code is in a

Blog postThis is a recursive Python solution that uses the analysis that opposite pairs of adjacent weights sum to the same value (i.e if the weights are numbered from w0 to w9 around the circle, then w0 + w1 = w5 + w6, w1 + w2 = w6 + w7, w2 + w3 = w7 + w8, w3 + w4 = w8 + w9, w4 + w5 = w9 + w0).

It runs in 35ms – much faster than computing the centre of mass of all combinations.