You are right but this site is about computer solutions using Python. The site at https://sites.google.com/site/sundaytimesteasers/ is one where non-computer solutions are discussed.

]]>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from itertools import permutations # a list for potential solutions l = [] # the lowest digit of the sequence of digits for b in range(7): # if b is divisible by 3, then all numbers formed from the # digits b .. b + 3 in any order are also divisible by 3 if b % 3: # permute the four consecutive digits for p in permutations('0123456789'[b : b + 4]): # form the number ns = ''.join(p) n = int(ns) # ensure that it is not divisible by # any number from 2 to 11 inclusive if all(n % q for q in (2, 5, 7, 11)): l += [ns] for p in range(4): # for each digit value, compile the list of # numbers with this digit in position 'p' t = [[int(x) for x in l if x[p]==str(d)] for d in range(10)] # now list any numbers that are unique for any digit values t = [x[0] for x in t if len(x) == 1] if len(t) == 1: print('The number is', t[0]) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from itertools import permutations as perm from fractions import gcd candidates = [p for start in range(7) for p in perm(range(start, start+4)) if gcd(sum([p[i]*10**(3-i) for i in range(4)]),2*3*5*7*11)==1] for pos in range(4): solutions=[] for i in range(10): s = [c for c in candidates if c[pos]==i] if len(s)==1: solutions.append(s) if len(solutions)==1: print solutions[0][0] |

For your explanations, 2013 times “Thank you”

and I wish a happy new year to you.

If we list the numbers according to their top digit we have:

1423,

2143, 2341, 2413, 2543

4231, 4253, 4321, 4523, 4567, 4657

5647, 5867, 6547, 6857,

8567

So if we knew that the top digit is 1 we would then know the number is 1423. Similarly, if the top digit is known to be 8 we would then know that the number is 8567.

But since, in this case, there are two answers, we can’t tell which is correct unless we know the top digit.

But if we now list the numbers with the same second digit, maybe there will be only one answer so we don;t need to know the digit. And we can build lists for the third and the fourth digits as well.

And, hopefully, one of these lists will have only one possible answer.

]]>How could we deduce the number from the output of this program if we knew the digit in a particular position?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from itertools import permutations # possible consecutive numbers L = [1234, 2345, 3456, 4567, 5678, 6789] # there are 6 elements in the list L for c in range(0, 6): for p in permutations(L[c]): n = int(''.join(p)) durum = True # checking the divisibility for i in range(2, 12): if n % i == 0: durum = False break if durum == True: print(n) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
nbr_list = [] for p in permutations('0123456789', 4): if p[0] == '0': continue ns = ''.join(p) n, ns = int(ns), sorted(ns) if int(ns[3]) == int(ns[0]) + 3: if all(n % a for a in (2, 3, 5, 7, 11)): nbr_list += [n] for pos in range(4): cnt = list(sum(1 for x in nbr_list if str(x)[pos] == str(v)) for v in range(10)) if cnt.count(1) == 1: print(nbr_list[cnt.index(1)]) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from itertools import permutations from collections import defaultdict # a dictionary for each of the four digit positions that will # list the numbers that have each digit in this position d4 = [defaultdict(list) for x in range(4)] # the lowest digit of the sequence of digits for b in range(7): # permute the four consecutive digits for p in permutations(range(b, b + 4)): # form the number n = int(''.join(str(x) for x in p)) # ensure it has four digits and is not divisible # by any number from 2 to 11 inclusive if p[0] and all(n % q for q in (2, 3, 5, 7, 11)): # now put this number into the four dictionaries # indexed on the digits in each position for d_pos, digit in enumerate(p): d4[d_pos][digit] += [n] # we now need to find one of the four dictionaries in # which only one digit value points to a single number for dct in d4: # find dictionaries with only one entry of length one if sum(1 for x in dct.values() if len(x) == 1) == 1: # find the entry that points to a single number t = [x[0] for x in dct.values() if len(x) == 1] print('The number is', t[0]) |