# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1371: Odd big base

From New Scientist #2530, 17th December 2005

If you want to work in a base higher than 10 you need some new symbols for the higher “digits”. Today I am working in such a base and my “digits” are (in the usual increasing order): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A (= 10), B (= 11), C (= 12), … and so on, using just as many letters of the alphabet as needed.

This means that some numbers look like words. For example, if I were working in base 15 then in my new notation the number BAD would represent the decimal number 2638 (= 11×15² + 10×15 + 13).

I have been looking at some numbers in my new system which do not use any of the traditional digits 0-9, such as ODD, BIG, BASE, NAB and PRIME. In fact more than one of those five numbers is prime.

What is my base?

[enigma1371]

### 2 responses to “Enigma 1371: Odd big base”

1. Jim Randell 19 November 2013 at 8:15 am

Assuming that we are considering bases up to 36 (after which we run out of letters), then we can find a unique solution. This Python program runs in 39ms.

```from itertools import count
from enigma import irange, nconcat, is_prime, printf

# digits used
digits='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# the numbers we're interesting in (as strings)
numbers = ('ODD', 'BIG', 'BASE', 'NAB', 'PRIME')

# convert the numbers into digits and find the maximum digit used
(ns, md) = (dict(), 0)
for n in numbers:
ds = tuple(digits.index(d) for d in n)
md = max(md, max(ds))
ns[n] = ds

for b in count(md + 1):
# calculate numbers in base b, and record the primes
ps = dict()
for (n, ds) in ns.items():
p = nconcat(ds, base=b)
if is_prime(p):
ps[n] = p
# are there 2 or more primes?
if len(ps.keys()) > 1:
printf("base={b} primes={ps}")
# only consider up to base 36
if b == 36: break
```

Solution: The base is 30.

I think the puzzle certainly implies (although it is not explicitly stated), that we are looking at bases up to 36. However, we can calculate the values of the given numbers in bases larger than 36, and we find there are many possible bases in which more than one of the given numbers are prime. If we remove the final line of the program then it will start to find larger bases that give solutions (75, 120, 148, 190, 228, 250, 280, 327, 340, 394, …). And if you replace the call to is_prime() to is_prime_mr() (a fast Miller-Rabin primality test, the implementation of which was provided by Brian Gladman), then you can find large bases even quicker (e.g. base 250,000 is a solution).

By considering the parity of the base we see that ODD and NAB are odd if the base is even (and even if the base is odd), and BIG and BASE are odd if the base is odd (and even if the base is even). PRIME is always even. So we only need to test up to two numbers in each base.

2. Naim Uygun 20 November 2013 at 10:16 am
```
def asal(n):
x=int(n**0.5)+2
ok=True
for i in range(2,x):
if n%i==0 :
ok=False
break

return ok
"""
ODD = 22003  BIG = 10456  BASE = 306854  NAB = 21011  PRIME = 20995874
alphabet=[chr(i) for i in range(65,91)]
number=[i for i in range(10,37)]
for i in range(0,26):
print((alphabet[i],"=",number[i]),end="")
"""
#Check for each base
for taban in range(36,10,-1):
odd=24*taban**2+13*taban+13
big=11*taban**2+18*taban+16
base=11*taban**3+10*taban**2+28*taban+14
nab=23*taban**2+10*taban+11
prime=25*taban**4+27*taban**3+18*taban**2+22*taban+14
kume=[asal(odd),asal(big),asal(base),asal(nab),asal(prime)]

if kume.count(True) > 1:
print("\nBase=",taban)
print("ODD =",odd," BIG =",big," BASE =",base," NAB =",nab," PRIME =",prime)
break
```