Teaser 2520: [Phone number]
From The Sunday Times, 9th January 2011 [link] [link]
I have a brand-new 11-digit phone number. The first and last digits are zero and the middle section uses each of the digits 1 to 9 once. If you called the number by pressing the buttons on the standard keypad of a modern phone, you would find no two consecutive digits of the number in the same row or column. Looking at the fifth and sixth digits, I see one is double the other. The second and third digits differ by two, the seventh is lower than the sixth and the 10th is odd, and one more than the eighth.
What is my number?
This puzzle was originally published with no title.
[teaser2520]
Jim Randell 9:40 am on 27 May 2025 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library.The following run file executes in 77ms. (Internal runtime of the generated program is 170µs).
Solution: The number is: 03594816270.
LikeLike
Ruud 3:02 pm on 27 May 2025 Permalink |
Very brute force, but still vey fast:
row = {0: 0, 1: 1, 2: 1, 3: 1, 4: 4, 5: 4, 6: 4, 7: 7, 8: 7, 9: 7} column = {0: 2, 1: 1, 2: 2, 3: 3, 4: 1, 5: 2, 6: 3, 7: 1, 8: 2, 9: 3} for n in itertools.permutations(range(1, 10)): if ( ((number:=(None,0)+ n + (0,))[5] == 2 * number[6] or number[6] == 2 * number[5]) and abs(number[2] - number[3]) == 2 and number[7] < number[6] and number[10] % 2 == 1 and number[10] == number[8] + 1 and all(row[number[i]] != row[number[i + 1]] and column[number[i]] != column[number[i + 1]] for i in range(1, 11)) ): print("".join(str(number[i]) for i in range(1, 12)))LikeLike
Frits 6:29 pm on 27 May 2025 Permalink |
#! python3 -m enigma -rr SubstitutedExpression # the number is: 0ABCDEFGHI0 --digits="1-9" # for A-I # a keypad is laid out as: # # 1 2 3 # 4 5 6 # 7 8 9 # 0 # # map digits to (<row>, <col>): # 0 1 2 3 4 5 6 7 8 9 --code="row = [4, 1, 1, 1, 2, 2, 2, 3, 3, 3]" --code="col = [2, 1, 2, 3, 1, 2, 3, 1, 2, 3]" --invalid="1|3|5|7|9,G" # G is even --invalid="1|3|5|6|7|9,DE" # {D, E} is either {2, 4} or {4, 8} --invalid="8|9,F" # F < E and E is 2, 4 or 8 --invalid="4,ABCFGH" # either D = 4 or E = 4 --invalid="2|4|6|8,AB" # D, E and G are even, so A and B can't be even --invalid="1|9,AB" # A and B not both on same row --invalid="5,CDEFGH" # {3, 5, 7} remains for A and B --invalid="2|5|8,A" # not adjacent to "0" button --assign="B,5" # either A = 5 or B = 5 but also A != 5 --invalid="2|4|6|8,AC" # not on same row/col as B(5) # no digits share row or col with an adjacent digit --code="check = lambda x, y: col[x] != col[y] and row[x] != row[y]" "check(A, B)" "check(B, C)" "check(C, D)" "check(D, E)" "check(E, F)" "check(F, G)" "check(G, H)" "check(H, I)" # parity of F and H is unknown "45 - (A + B + C + D + E + F + G + I) = H" # one of 5th or 6th digits is double the other "(D == 2 * E) or (E == 2 * D)" # 2nd and 3rd digits differ by 2 "abs(A - B) = 2" # 7th digit is lower than 6th "F < E" # 10th digit is odd, and one more than 8th "G + 1 = I" --template="0 A B C D E F G H I 0" --distinct="ABCDEFGI" --solution=""or
N = 3 r = lambda i: (i - 1) // N c = lambda i: (i - 1) % N if i else 1 forbidden = {i: set(j for j in range(10) if j != i and (r(i) == r(j) or c(i) == c(j))) for i in range(10)} def solve(k=9, ns=set(range(1, 10)), ss=[0]): if k == 0: # check 10th number if 0 not in forbidden[ss[-1]] and ss[-1] == ss[-3] + 1: yield ss + [0] else: match(10 - k): case(3): if abs(ss[-1] - ss[-2]) != 2: return case(6): if not (ss[-1] == 2 * ss[-2] or ss[-2] == 2 * ss[-1]): return case(7): if ss[-1] > ss[-2]: return case(8): if ss[-1] % 2: return for n in ns: if n not in forbidden[ss[-1]]: yield from solve(k - 1, ns - {n}, ss + [n]) for s in solve(): print("answer:", ''.join(str(x) for x in s))LikeLike