# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1481: No calculator, please!

From New Scientist #2643, 16th February 2008

I had 10 different cards, each bearing one of the digits 0 to 9 (6 was distinguishable from 9). I selected six cards with consecutive digits and formed three two-digit numbers. I wrote down a number which was not 1 but was a factor of each of the three two-digit numbers. I multiplied the three two-digit numbers together and noticed that their product was odd. I found that the product had as a factor the cube of a number that was not 1 and was not the number I had written down.

Without any serious multiplications, tell me which three two-digit numbers I formed, in ascending order.

[enigma1481]

### One response to “Enigma 1481: No calculator, please!”

1. Jim Randell 27 November 2012 at 2:24 pm

Here’s a Python program which finds the solution “without any serious multiplication” (i.e. it never computes the product of the three two-digit numbers). In fact the algorithm should work entirely on integers that don’t exceed 100.

But as we only need to find the product so we can find the divisors of it, we can just use the fact that the divisors of the product are the concatenation of the divisors of the numbers that are multiplied together to make up the product.

It runs in 42ms.

```from itertools import permutations, combinations
from collections import defaultdict
from enigma import irange, divisors, factor, flatten, subseqs, multiply, printf

# group solutions by the answer
r = defaultdict(int)

# consider 6 consecutive digits
for m in irange(6, 9):
ds = list(irange(m - 5, m))
# permute the digits
for (d1, d2, d3, d4, d5, d6) in permutations(ds):
# the eventual product must be odd
if any(d % 2 == 0 for d in (d2, d4, d6)): continue
# form the 3-digit numbers
(n1, n2, n3) = (10 * d1 + d2, 10 * d3 + d4, 10 * d5 + d6)
if not(n1 < n2 < n3): continue
# determine cubic divisors of the product
# (without determining the product)
fs = factor(n1) + factor(n2) + factor(n3)
f3 = flatten([f] * (fs.count(f) // 3) for f in set(fs))
# there must be a common divisor (d)
for d in divisors(n1):
if d == 1 or n2 % d or n3 % d: continue
# and a cubic divisor of the product (d3)
for fs in set(subseqs(f3, 1)):
d3 = multiply(fs)
if d3 == d: continue
r[(n1, n2, n3)] += 1
printf("({n1}, {n2}, {n3}) [d={d} d3={d3}]")

print("SOLUTIONS:")
for (k, v) in r.items():
printf("{k} [{v} solutions]")
```

Solution: The three two-digit numbers are 27, 45 and 63.

There are two ways to arrive at the solution. The first is if the number 3 is written down, then the cubic divisor of the product is 93 = 729. The second is if the number 9 is written down, then the cubic divisor of the product is 33 = 9.

This site uses Akismet to reduce spam. Learn how your comment data is processed.