Just 9 digits

Find a nine digit positive integer, containing distinct digits from 1 to 9 such that ;

(i) Sum of any two consecutive digits is prime.

(ii) Sum of whose first 4 digits is equal to the sum of last 3 digits.

(iii) Sum of first, fourth and eighth digit is 13.

(iv) First, fourth and eighth digits are in increasing order, and one of them is 1.


The answer is 129476583.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Fletcher Mattox
Apr 21, 2021
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from itertools import permutations

def ok(t):
    primes = [2, 3, 5, 7, 11, 13, 17, 19]
    for i in range(len(t)-1):
        j = i+1
        if not t[i]+t[j] in primes:
            return False
    return True

def ok2(a, d, h):
    return 1 in [a,d,h] and a<d<h

for t in permutations(list(range(1,10))):
    a,b,c,d,e,f,g,h,i = t
    if ok(t) and a+b+c+d == g+h+i and a+d+h == 13 and ok2(a, d, h):
        print(''.join(list(map(str, t))))

1
129476583

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...