# The London safes and their mysterious combinations

Here's the first riddle I invented for Puzzling SE. Hope you'll enjoy solving it.

This story takes place during World War II. A German spy is assigned the task to sneak overnight into a military base near London and steal secret documents of utmost importance.

The documents are kept inside 30 safes of reinforced unbreakable steel, and each safe is protected by a numeric secret code. Therefore the only way to get the documents is to open each safe with the correct code. If the wrong code is entered, the safe will immediately trigger a siren which will alert all military personnel, so the spy has only one try available.

German Intelligence was able to provide the spy with the following information:
First, it looks like the codes were not chosen at random, but instead follow some unknown pattern. Second, they intercepted half of the safes' codes, which they communicate to the spy:

Safe   Code
#1     2
#2     4
#3     6
#4     8
#5     10
#6     12
#7     14
#8     16
#9     18
#10    20
#11    22
#12    24
#13    26
#14    28
#15    30


The second half of the safes' codes is still unknown. German Intelligence advises the spy to delay the mission until all codes have been discovered; however, the spy believes that the pattern is obvious, as a safe's code appears to be the double of the safe's number.

That same night, the spy enters unseen the military base, finds the safes, silently opens each one of them with the correct code and steals the documents. Everything goes well from safe #1 to #17.

However, when the spy enters the code 36 on safe #18, the safe doesn't open; its alarm triggers, and the spy is captured.

Can you find why? If not, continue reading.

A few weeks later, the military base has sixty more safes delivered. The codes on these safes are programmed following the same pattern.

After the end of the war, the commander of the base is asked by the High Command to compile a list of all safes and codes. He produces the following document:

Safe   Code   Safe   Code   Safe   Code   Safe   Code   Safe   Code   Safe   Code
#1     2      #16    32     #31    28     #46   -42     #61    34     #76    46
#2     4      #17    34     #32    30     #47   -40     #62    36     #77    48
#3     6      #18    25     #33    32     #48   -38     #63    38     #78    50
#4     8      #19    38     #34    34     #49   -36     #64    40     #79    52
#5     10     #20    40     #35    36     #50    30     #65    42     #80    25
#6     12     #21    42     #36    38     #51    32     #66    44     #81    27
#7     14     #22    44     #37    40     #52    34     #67    46     #82    29
#8     16     #23    46     #38    42     #53    36     #68    48     #83    31
#9     18     #24    48     #39    44     #54    38     #69    50     #84    33
#10    20     #25    50     #40   -54     #55    40     #70    34     #85    35
#11    22     #26    52     #41   -52     #56    42     #71    36     #86    37
#12    24     #27    54     #42   -50     #57    44     #72    38     #87    39
#13    26     #28    56     #43   -48     #58    46     #73    40     #88    41
#14    28     #29    58     #44   -46     #59    48     #74    42     #89    43
#15    30     #30    26     #45   -44     #60    32     #75    44     #90    38


Can you find now how the codes were chosen - and hence why the spy failed?

Hint 1

There is an unique solution for the riddle. Don't try to find overcomplicated formulas. There is more than just mathematics -- in fact, although there is quite a bit of calculations, the mathematics involved are very basic. To crack the code, you'll have to do some lateral thinking.

Hint 2

Language is important. The story takes place in Great Britain because the riddle is related to the English language. The nationality of the spy is irrelevant.

Hint 3

Observe how the British chose the secret algorithm to fool spies. "Code of safe $$n = 2 \times n$$" is a red herring -- it looks like it is the solution, but is valid only up to safe #29 with the exception of safe #18. The units for each "ten" follow a pattern, but each "ten" breaks the pattern. Where would you find such a pattern?

• @dr01 Does it have something to do with time? like 60 is represented as 00 or some other number? Also does the year have any significance or it will have no impact on the puzzle? Sep 23, 2015 at 15:52
• I'm going to assume that safe #30 isn't a safe that automatically sets off the alarm no matter what, even though that would be a brilliant security system. Sep 23, 2015 at 16:00
• I'm concerned that this is a question which is too broad -- ie. where we're (unintentionally) expected to read your mind. There are several plausible answers below and specifically APrough's is still valid according to the text right now. I think the puzzle needs some extra detail and narrowing down so that the wrong answers are wrong because of information that's contained in the puzzle, not just because it doesn't match the answer you had in mind. Sep 23, 2015 at 19:05
• @dr01 I think the title is too generic, may I suggest a rename: $$\mathbf{Safes\ and\ Codes:\ German\ Doubling}$$ Or something else that you might like, but the present title is quite terrible. Sep 27, 2015 at 20:58
• While I enjoyed watching the solution, there is ZERO chance one could've solved this based on the initial given info for the riddle... Sep 30, 2015 at 15:55

To get the code of a safe, write down the safe's number as a word, replace the letters with numbers using the following matching, and finally add them together.

 e: 0    f: 5    g: -62  h: 67
i: 0    l: 8    n: 9    o: -7
r: -72  s: 0    t: 11   u: 82
v: 5    w: 0    x: 12   y: 9 
(the other letters do not appear in the numbers)

How I got there:

After the last hint (and all the comments and thinking before) it was pretty clear to me, that each letter in the word had to have some value which then would add up to the safe's code. Obviously the usual matching a = 1, b = 2, ... would not fit, so I had to do some calculations based on the assumption that t+y = 20 which I guessed after hint 5.

 t+y = 20
t+w+e+n+t+y = 40 => t+w+e+n = 20
t+e+n = 20 = t+w+e+n => w = 0
t+w+o = t+o = 4, t+e+n = 20 => t+t+o+n+e = 24
t+t+o+n+e = 24, o+n+e = 2 => t+t = 22 => t = 11
t+y = 20, t = 11 => y = 9
t+e+n = 20, t = 11 => e+n = 9
e+n = 9, o+n+e = 2 => o = -7
n+i+n+e = 18, e+n = 9 => n+i = 9 => i = e
n+i+n+e+t+e+e+n = 38, n+i+n+e = 18 => t+e+e+n = 20
t+e+e+n = 20 = t+e+n => e = i = 0, n = 9
f+i+f+t+y = 30, t+y = 20 => f+i+f = f+f = 10 => f = 5
f+i+v+e = f+v = 10 => v = 5
s+e+v+e+n = s+v+n = 14 => s = 0
e+l+e+v+e+n = l+v+n = 22 => l = 8
s+i+x = s+x = 12 => x = 12
f+o+r+t+y = -54 => r = -72
f+o+u+r = 8 => u = 82
t+h+r+e+e = t+h+r = 6 => h = 67
e+i+g+h+t = g+h+t = 16 => g = -62

I hope that helps to understand the way I found the solution and also how the codes are calculated.

• I wanted to say that the error in the original question threw us a bit off and that the number replacements are too weird, but I'm entirely too baffled from seeing that this actually works somehow. Sep 30, 2015 at 14:15
• Nah, not for me at least. I definitely wouldn't have figured it out all the same. Sep 30, 2015 at 14:22
• @Aioros, after 20 it is not a surprise it works (since "Y" appears for the first time in "twenty" and 0-9 repeat all the time), but it is interesting how with just 16 letters (12 non-zeros) you can get all of the first 20 numbers (I assume this is why the OP had to multiply by 2?). Very nice indeed. Sep 30, 2015 at 14:28
• @dr01, yeah I guessed that's why you multiplied by 2. Still, it was very close for the system to be unsolvable, which is what makes your problem so nice. Sep 30, 2015 at 15:03
• @ArturKirkoryan Unfortunately it's not possible to fit 18 in the pattern: T is supposed to be 0 because of EIGHTEEN=EIGHT+TEN, but it was previously set as 11 by other constraints.
– dr_
Sep 30, 2015 at 15:09

The code should have been

0

I believe that the codes for each safe are equivalent to

$($The next safe # in the sequence $\times 2) -2$. Since Safe 30 is at the end of the sequence, technically Safe 1 would be next in sequence $(1 \times 2) -2 = 0$

• Too easy. Sorry, wrong answer. :)
– dr_
Sep 23, 2015 at 16:05
• @dr01 Is it the wrong answer because you say it's the wrong answer, or is there enough information in the question to deduce that it's the wrong answer? That's the hallmark of a great puzzle (i.e. not one with multiple 'correct' answers, where the 'one answer to rule them all' lies with the Asker going "because I say so") Sep 23, 2015 at 16:06
• @MattTaylor The riddle would still work with 50 safes, but in this case this answer wouldn't make sense.
– dr_
Sep 23, 2015 at 16:10
• @dr01 In that case, would it make sense to extend the Puzzle as such? If that doesn't change the solution or its validity, then isolating the correct answer from those which are plausibly correct given the information (such as this one) can only be a good thing. Sep 23, 2015 at 16:12
• @dr01 It's not a hint I'm asking for, just improving the puzzle so that the fact that this answer is wrong is clearer in the question, as otherwise the engineer in me just wants to go "It's correct according to the specification of the puzzle, therefore it's correct (ner nerny ner ner)" =P Sep 23, 2015 at 16:18

The code should have been

2

Explanation:

The story plays in the leap year 1944. The British picked the codes day by day, and simply doubled the number of the current day. The numbering started on Feburary 1 (code $2*1=2$), Feburary 2 (code $2*2=4$), $\ldots$, Feburary 29 (code $2*29=58$), March 1 (code $2*1=2$).

• I like this, but based on the fact that the OP originally had 1943 as the year (then removed it), and stated "The year is specified only to add some atmosphere", I don't think this is the answer. Sep 23, 2015 at 16:59
• Wrong, please try again. Date or time have no influence on the code.
– dr_
Sep 29, 2015 at 7:55

The code has something to do with the digits of the safe number. If the code to safe $n$ is denoted by $C(n)$, then we can see that:

$$C(n) = 2\left[f\left(\left\lfloor\frac{n}{10}\right\rfloor\right) + (n~\text{mod}~10)\right]$$

(The multiplication by two is because all code values are even.)

We know the values of $f$ for $0$ through $6$:

\begin{align} f(0)&=0\\ f(1)&=10\\ f(2)&=20\\ f(3)&=13\\ f(4)&=-27\\ f(5)&=15\\ f(6)&=16\\ f(7)&=17 \end{align}

We are hinted that the answer has to do with the location of the safes, which leaves me to believe that $f$ is related to the English spelling or pronunciation of the numbers. In particular, it seems to me as if there is some relationship between thirty/thirteen, fifty/fifteen, etc., although $f(4)$ breaks this pattern.

• Forty is spelled differently from fourteen, maybe.
– f''
Sep 25, 2015 at 20:37
• @f'' Good catch! I actually never noticed the missing "u" before! Sep 25, 2015 at 20:39
• +1 for getting close to the solution! Hint: the solution doesn't involve complex mathematical formulas.
– dr_
Sep 26, 2015 at 8:24
• @dr01 Is that a hint that my $C(n)$ is wrong? Sep 27, 2015 at 17:01
• @2012rcampion Yes, the secret pattern can't be found by a mathematical function alone. (Or, at least, that would surprise me!) Your post contains the solution; take some time to develop it. Tomorrow I'll post another hint if nobody has made any progress.
– dr_
Sep 27, 2015 at 19:57

I think this is too broad.

Anyway, the code might have been

0 or 1.

According to the formula:

$code=2*num\pmod{59}$
or
$code=2*num\pmod{60}$

• Agree this is too broad. Perhaps the answer is 1:00 because --- I don't know, clocks or something. Sep 23, 2015 at 18:31
• Wrong, please try again. Date or time have no influence on the code.
– dr_
Sep 29, 2015 at 7:55

I think I know how the code works but can't figure out the critical bits. Basically if you assume that values one to twenty are C(n)=2*n then every safe after that has a code that is equal to the sum of the codes of the constituent parts i.e. code(twentyone) = code(twenty)+code(one) code(thirtyone)=code(thirty)+code(one) and so on It would be nice to know how code(thirty), code(forty), code(fifty) and code(sixty) are calculated

• +1 because you're on the right path. The answer to your last sentence is contained in hint #2. Once you find it, you have solved the riddle.
– dr_
Sep 29, 2015 at 7:50
• Another possible clue is that the only true outliers are 40(-56) and 80(25). You could argue that all other Code(x:ty) =Code(x:teen). Forty and eighty are written and pronounced differently than fourteen or eighteen and I think that has something to do with how their codes are calculated Sep 29, 2015 at 19:18
• Good insight. That's an effect of the pattern.
– dr_
Sep 30, 2015 at 6:56

I think the code is

62

Based on the idea that the code is

Each safe number ($n$) is mapped onto double the $n$th number that is not the sum of 4 distinct nonzero squares. This would mean the 30th safe was mapped to 62.

It could also be that the code is

Each safe number ($n$) is mapped onto double the $n$th number that has 2 or fewer distinct prime factors. Then $n=1,\ldots,29$ maps to $2n$ and 30 maps to 62.

Or it could be:

Each safe numbered ($n$) maps to double the $n$th number that cannot be expressed in form $p+q^2+r^3+s^4$, where $p, q, r, s$ are primes. Then $n$ maps to $2n$ for $n\in{1,\ldots,29}$ and 30 maps to 64

Obviously I used oeis.org to find the above, but it does suggest that the question is a bit broad

• It doesn't say the 30th safe, it says : at safe #30, the alarm triggers, and the spy is captured. Sep 23, 2015 at 18:17
• It's a minor change. Sep 23, 2015 at 18:21
• Changing a puzzle's wording to fit your answer is not "minor" in my opinion. Sep 23, 2015 at 18:23
• I'm saying changing my answer is a minor change. Sep 23, 2015 at 18:24
• The 30th safe is safe #30, point. There are no wordplays or tricks in the riddle. You can imagine that each safe has a label on it with its number.
– dr_
Sep 23, 2015 at 21:38

Safe number 1 starts with code = 2. Stepsize between safes is 2, except when exception fits as described hereunder.

Exeption-check:

When safe number written as English word ends with "y", replace "y" by "een" and look for that English word in the previous safe numbers. If found, take the code of that safe number. If not found, but there exists a word with a difference of only one letter, the following rule will apply:

• fetch previous replacement's safe number, i.e. of the "een" word (not safe's code)
• substract this safe number from actual safe number
• take code of the safe found this way
• multiply by -1 (because initial search was negative)
• It's not quite clear what you mean by all of this. Could you rephrase it?
– Deusovi
Sep 29, 2015 at 16:32
• Also, i've not heard of 'twenteen'. Sep 29, 2015 at 21:55
• Too complicated.
– dr_
Sep 30, 2015 at 6:54

The code should have been

26

Partial explanation

Each ten breaks the pattern, except 1-29. Instead of the expected thirty * 2 the code uses thirteen (very similar in pronunciation): thirteen * 2 = 26. The same applies for fifty fifteen * 2 = 30, sixty sixteen * 2 = 32, seventy seventeen * 2 = 34, ninety nineteen * 2 = 38. This didn't work for eleven and twelve, which is why safes #1-29 follow a regular pattern.

However, I'm still in the dark on #40 and #80.

• Sorry, this doesn't really answer the question of what is the secret algorithm used to create the codes :) . Note that the algorithm must work for all safes; trying to explain why some of the safes have that code won't work.
– dr_
Sep 30, 2015 at 12:55