# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1451: Odds and evens

From New Scientist #2612, 14th July 2007

I have created a sum by adding a three-digit number consisting solely of odd digits to a three-digit number consisting solely of even digits to make a three-digit number in which odd and even digits alternate. The nine digits used are all different. If I tell you any of my three numbers you will be able to deduce with certainty what the other two numbers are.

What are the three numbers of my sum?

Enigma 1721 is also called “Odds and evens”.

[enigma1451]

### One response to “Enigma 1451: Odds and evens”

1. Jim Randell 15 March 2013 at 9:03 am

This Python program runs in 63ms.

```from itertools import product, permutations
from collections import Counter
from enigma import nconcat, split, printf

evens = (0, 2, 4, 6, 8)
odds  = (1, 3, 5, 7, 9)

# record the sums, and count uses of each number
sums = set()
used = Counter()
# t1 is 3 different odd digits
for s1 in permutations(odds, 3):
t1 = nconcat(s1)
# t2 is 3 different even digits
for s2 in permutations(evens, 3):
if s2 == 0: continue
t2 = nconcat(s2)
# their sum is a 3 digit number
r = t1 + t2
rs = list(split(r, int))
if len(rs) != 3: continue
# the digits used in numbers are all different
if len(set(rs).union(s1, s2)) != 9: continue
# and the sum alternates odd and even digits
if not((rs in evens and rs in odds and rs in evens) or
(rs in odds and rs in evens and rs in odds)): continue
printf("[{t1} + {t2} = {r}]")