# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1609: I remember it well

From New Scientist #2774, 21st August 2010 [link]

I am a bit vague about my bank security number –

It is a four figure number (or possibly five);

It uses four different digits (or possibly five);

The first digit is four (or possibly five);

The second digit is four (or possibly five) and none of the other digits is smaller;

The number is a prime multiplied by four (or possibly five);

If you reverse the order of the digits you get a number which is the product of four (or possibly five) different primes;

In four (or possibly five) of these statements my first guess is correct.

What is my bank security number?

[enigma1609]

### One response to “Enigma 1609: I remember it well”

1. jimrandell 2 January 2012 at 11:46 pm

The following Python program runs in 128ms.

```from enigma import irange, is_prime, factor

for n in irange(4444, 55999):

# A. is a 4 (or 5) digit number
s = str(n)
g1 = len(s)

# B. uses 4 (or 5) different digits
g2 = len(set(s))
if g2 not in (4, 5): continue

# C. starts with 4 (or 5)
g3 = s[0]
if g3 not in ('4', '5'): continue

# D. second digit is 4 (or 5)...
g4 = s[1]
if g4 not in ('4', '5'): continue
# ... and none of the other digits are smaller
if list(filter(lambda x: x < s[1], [s[0]] + list(s[2:]))): continue

# E. prime * 4 (or 5)
g5 = ''
if n % 4 == 0 and is_prime(n // 4): g5 += '4'
if n % 5 == 0 and is_prime(n // 5): g5 += '5'
if not g5: continue

# F. if you reverse the number, it is the product of 4 (or 5) different primes
r = int(s[::-1])
f = factor(r)
g6 = len(set(f))
if g6 != len(f): continue
if g6 not in (4, 5): continue

# G. 4 (or 5) of these statements yield 4.
# so, if there are 3 statements yielding 4 then the last one can yield 4 making 4 of them altogether.
# if there are 4 statements yielding 4 the last statement cannot be satisfied (G4 => G5)
# if there are 5 statements yielding 4 the last can yield 5 making 5 of them altogether
l = list(map(int, (g1, g2, g3, g4, g5, g6)))
g = l.count(4)
if g not in (3, 5): continue
print(n, l + [g], g)
```

Solution: The security number is 5468.