### Random Post

### Recent Posts

### Recent Comments

Jim Randell on Tantalizer 452: Snailspaces | |

Brian Gladman on Enigma 1061: Par is never… | |

Hugh Casement on Enigma 1061: Par is never… | |

Jim Randell on Enigma 1061: Par is never… | |

geoffrounce on Puzzle 47: Digits all wro… |

### Archives

### Categories

- article (11)
- enigma (1,175)
- misc (2)
- project euler (2)
- puzzle (44)
- site news (46)
- tantalizer (48)
- teaser (3)

### Site Stats

- 183,007 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().