Enigma Number 1628
Was reading through New Scientist and thought I’d have a go at their “Enigma” puzzle, which I’ve always glossed over since they’re pretty difficult maths. However, since I’ve got a computer I thought I’d see what the answer is anyway.
The question is this:
- Raising a number to the power of itself is like
5to the power of5, or5**5in Python. - A ‘reverse’ number is a number with its digits backwards, so
45is the reverse of54. - A number that ends with another means that the least significant digits of the former are the same as all of the digits of the latter in the same order.
Given this, what is the 2 digit number x such that:
xraised to the power ofxends withx- The reverse of
xraised to the reverse ofxends with the reverse ofx - The reverse of
xraised to the power ofxends with the reverse ofx - The digits in
xaren’t the same?
Translating this into Python is quite simple. We start with all of
the possible answers, ie. the numbers 00-99,
which we get via range(100).
Next we can split them into a pair of the “tens and units” as they
used to say in primary school. We do this with
[(a/10,a%10) for a in range(100)].
Next we can put these back into a list of numbers by undoing the
separation of the digits, like this
[x*10+y for x,y in [(a/10,a%10) for a in range(100)]].
Next we want to put our filters on this. Namely, the 2 digits
x and y cannot be equal, so x!=y;
the number raised to itself, (x*10+y)**(x*10+y), must ends
with itself, ie. ((x*10+y)**(x*10+y))%100==x*10+y; the same
must be true for the reverse, where we just swap x and
y; and the reverse to the power of the number,
(y*10+x)**(x*10+y), must end in the reverse,
y*10+x, so
((y*10+x)**(x*10+y))%100==y*10+x.
Putting it all together we get a list of answers:
[x*10+y for x,y in [(a/10,a%10) for a in range(100)] if x!=y and ((x*10+y)**(x*10+y))%100==(x*10+y) and ((y*10+x)**(y*10+x))%100==(y*10+x) and ((y*10+x)**(x*10+y))%100==(y*10+x)]Easy :)
PS: The answers are 16, 61 and 57