### Random Post

### Recent Posts

### Recent Comments

Hugh Casement on Enigma 1049: Know-all | |

Jim Randell on Enigma 1049: Know-all | |

Jim Randell on Enigma 460: Tear me off a… | |

Jim Randell on Puzzle 42: Football – fo… | |

Jim Randell on Enigma 1050: Find the lin… |

### Archives

### Categories

- article (11)
- enigma (1,199)
- misc (3)
- project euler (2)
- puzzle (50)
- site news (47)
- tantalizer (52)
- teaser (3)

### Site Stats

- 188,171 hits

Advertisements

This Python program examines all 5-digit multiples of 581 to find the solution. It runs in 35ms.

Solution:It is possible to end up with a whole number answer in two ways. You can arrive at 158 by choosing AB=91 and C=7, and this is the published solution. But by choosing AB=83 and C=0 (which is not disallowed by the problem statement) you can also get the answer of 143.Here is a different approach:

It does find the answer (and if you remove the assumption that C is non-zero it finds the second solution). But it also assumes that A, B and C are all different digits, which is the case in the answer, but it isn’t a requirement given in the puzzle statement.

(I’d also just use the

%operator to check for divisibility in line 10:and that would make the program work in Python 2 as well).

This solution finds both answers of 91798 and 83083;

I think the problem with using

itertools.permutations()is that it only looks at cases where the digits in AB and C are all different, which isn’t required by the problem statement. (Although it does turn out to be the case in the answer(s)).Instead you could use

itertools.product(), which would check 1000 possibilities for (A, B, C), rather than the 720 checked by usingitertools.permutations().