Compute 2018 #2

Find the highest 9 9 -digit number a b c d e f g h i \overline{abcdefghi} with distinct non-zero digits a , b , c , d , e , f , g , h , a, b, c, d, e, f, g, h, and i , i, such that a b c d + e f g h + i = 2018. \overline{ab} * \overline{cd} + \overline{ef} * \overline{gh} + i = 2018. Note: The asterisk sign means multiplying the two 2 2 -digit numbers.


The answer is 581647239.

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

Zeeshan Ali
May 16, 2018
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import itertools # https://docs.python.org/2/library/itertools.html#itertools.permutations
import numpy as np # http://www.numpy.org/

# set of all the possible 9 non-zero-digit numbers in decending order
permutations = list(itertools.permutations([i for i in range(9, 0, -1)], 9))

# for every p = (a, b, c, d, e, f, g, h, i) in above set
for p in permutations:
    # if all elements in p are unique
    if len(np.unique(p)) == 9:
        # if ab*cd+ef*gh+i equals 2018
        if (p[0]*10+p[1])*(p[2]*10+p[3])+(p[4]*10+p[5])*(p[6]*10+p[7])+p[8] == 2018:
            # print the elements or digits of that number 'p'
            print (p)
            # since the p's in permutations are in decending order therefore the first one satisfying
            # the condition is the larget such number, hence break (i.e. stop further search)
            break

(5, 8, 1, 6, 4, 7, 2, 3, 9)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...