On Sue's mobile phone the buttons can be used for more than one letter, and the machine predicts her intended word. So, for example, to text “STOP” if Sue types the buttons shown below, but the machine could also interpret that as “SUMS”.
+---------+ +---------+ +---------+ +---------+
| P Q R S | | T U V | | M N O | | P Q R S |
+---------+ +---------+ +---------+ +---------+
This desire for compact gadgetry has spread to calculators. The digits of Sue are on just five buttons, A to E, as shown:
Button A Button B Button C Button D Button E
+------+ +------+ +------+ +------+ +------+
| 0 1 | | 2 3 | | 4 5 | | 6 7 | | 8 9 |
+------+ +------+ +------+ +------+ +------+
So when Sue types in a number the machine has to predict what she wants. Recently Sue pushed buttons intending to display a three-figure prime number, but the machine displayed a different three-figure prime. Then she pushed some more buttons intending to display a three-figure square, but the machine displayed a different three-figure square.When typing these two numbers Sue had pushed each button at least once.
Which six buttons, listed in order, did Sue push?
Note: Adapted from Enigma Number:1681 by Susan Denham, which appeared in New Scientist on 29 February, 2012.
DAE BBC [619, 709, 719] [225, 324]
DAE could be any of 3 primes
BBC could be either of the two squares 225 or 324
---------
def buttonPattern(n):
s = str(n)
ans = ''
for ch in s:
if ch in '01':
ans += 'A'
elif ch in '23':
ans += 'B'
elif ch in '45':
ans += 'C'
elif ch in '67':
ans += 'D'
elif ch in '89':
ans += 'E'
return ans
for p in primes:
bp = buttonPattern(p)
if bp not in prime_dict:
prime_dict[bp] = [p]
else:
prime_dict[bp].append(p)
for sq in squares:
bp = buttonPattern(sq)
if bp not in square_dict:
square_dict[bp] = [sq]
else:
square_dict[bp].append(sq)
ppats = prime_dict.keys()
spats = square_dict.keys()
for p in ppats:
if len(prime_dict[p]) < 2:
continue
for s in spats:
if len(square_dict[s]) < 2:
continue
if len(set(p+s)) != 5:
continue
print(p,s, prime_dict[p], square_dict[s])
|
Posted by Larry
on 2024-09-24 13:22:44 |