# Enigmatic Code

Programming Enigma Puzzles

## Puzzle #16: Clever code

From New Scientist #3242, 10th August 2019 [link] [link]

Rashmi told us that she had to make up some codes, ones that preferably have a unique quality to them.

“For a four-digit code, I chose 2020, because it has two 0s, zero 1s, two 2s and zero 3s. I chose 3211000 for a seven-digit code.”

She then told us that she used the same idea for a 10-digit code.

[puzzle#16]

### One response to “Puzzle #16: Clever code”

1. Jim Randell 10 August 2019 at 8:32 am

We investigated the base 10 autobiographical numbers in Enigma 476 and generated a complete list of them.

There is only one autobiographical number with 10 digits.

Solution: The code is 6210001000.

Note that 1210 is also a 4-digit autobiographical number, and there are no autobiographical numbers of length 6.

Using the recipe given with Enigma 476 we can generate autobiographical sequences with length 10, and turn them into numbers.

Run: [ @repl.it ]

```from enigma import nconcat, printf

# generate autobiographical sequences up to length n
def generate(n=None):
for s in ((), (1, 2, 1, 0), (2, 0, 2, 0), (2, 1, 2, 0, 0), [3, 2, 1, 1, 0, 0, 0]):
if n is None or not(len(s) > n):
yield tuple(s)
while n is None or len(s) < n:
# insert an additional 0
s.insert(3, 0)
s[0] += 1
yield tuple(s)

# check a sequence is autobiographical
def is_autobiographical(s):
return all(x == s.count(i) for (i, x) in enumerate(s))

# generate sequences up to length 10
for s in generate(10):
assert is_autobiographical(s)
if len(s) == 10 and all(x < 10 for x in s):
n = nconcat(s)
printf("{s} -> {n}")
```

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