Equal Representation

Consider the following formula:

ABCDE
+BCDE
+ CDE
+  DE
+   E
-----
FGHIJ

Where each letter represents a unique decimal digit, and there are no leading zeroes for any number in the formula.

If A + B + C + D + E A + B + C + D + E is minimal, what is the number A B C D E F G H I J \overline{ABCDEFGHIJ} ?
(The string of digits, not the product.)


The answer is 3817246590.

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.

9 solutions

Thaddeus Abiy
Aug 9, 2014

Some Lazy python code,takes less than a second on my machine.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
All = []        
Minimum = 'inf'
for ABCDE in range(10000,100000):
    FGHIJ = sum( ABCDE % pow(10,i) for i in range(1,6) )
    i = str(ABCDE) + str(FGHIJ)
    if len(set(i)) == 10 and (i[-1]=='0' or i[4]=='0'):
        Sum = sum(map(int,i[0:4]))
        if Sum < Minimum:
            Minimum = Sum
            Answer = i

print Answer

bantog ra. tikasan man diay

Cabanting Perez Francis - 6 years, 6 months ago
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
count, ans = 100, ""
for a in range( 1, 10 ): 
    for b in range( 1, 10 ): 
        for c in range( 1, 10 ): 
            for d in range( 1, 10 ):
                for e in range( 1, 10 ):
                    res = str( (10000 * a) + ( 1000 * (2 * b) ) + ( 100 * (3 * c) ) + ( 10 * (4 * d) ) + (5 * e) )
                    if ( len( res ) == 5 ) and ( sorted( [ a, b, c, d, e, int( res[0] ), int( res[1] ), int( res[2] ), int( res[3] ), int( res[4] ) ] ) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ) and ( (a + b + c + d + e) < count ):
                        count = a + b + c + d + e
                        ans = str( a ) + str( b ) + str( c ) + str( d ) + str( e ) + res
print ans

Here

It's run in 0.443909168243 seconds.

Fariz Azmi Pratama - 6 years, 9 months ago
Chew-Seong Cheong
Aug 10, 2014

I used Python coding. Note that A , B , C , D A, B, C, D and E E are 0 \ne 0 . The results should that A + B + C + D + E = 21 A+B+C+D+E=21 is minimum and the answer is 3817246590 \boxed{3817246590} .

for a in range(1,10):
for b in range(10):
    if b==a:
        continue
    for c in range(1,10):
        if c==a or c==b:
            continue
        for d in range(1,10):
            if d==a or d==b or d==c:
                continue
            for e in range(1,10):
                if e==a or e==b or e==c or e==d:
                    continue
                n1 = 10000*a+1000*b+100*c+10*d+e
                n2 = 10000*a+2000*b+300*c+40*d+5*e
                s = str(n1)+str(n2)
                if len(s) < 11:
                    OK = "Y"
                    for i in range(9):
                        for j in range(i+1,10):
                            if s [i]==s[j]:
                                OK = "N"
                    if OK == "Y":
                        print a+b+c+d+e, s

27 1476920385

23 1487320695

24 2489130765

21 3817246590

23 6493170825

27 6539471280

28 8675294310

27 8742695310

Haroun Meghaichi
Aug 9, 2014

Runs in two seconds on my 2 cores old computer.

 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
def test1(x):#tests whether x has 0 as a digit.
    p=True;s=str(x);
    for i in range(0,len(s)):
        if s[i]=='0':
            p=False;
            break
    return p;
def test2(x):#tests whether x have a repeated digit.
    p=True;
    for i in range(0,len(x)):
        for j in range(i+1,len(x)):
            if x[i]==x[j]:
                p=False;
                break
    return p;
min_sum=99 #we know that the sum of the digits<50.
for x in range(10**4,10**5):    
    if test2(str(x)) and test1(x):
        y=sum(x%10**(4-i) for i in range(0,4))+x;
        if len(str(y))==5:
            if test2(str(x)+str(y)):
                if sum(int(str(x)[i]) for i in range(0,5))<min_sum:
                    min_sum=sum(int(str(x)[i]) for i in range(0,5));
                    result=str(x)+str(y);
print(int(result));
print(time()-t);

Daniel Ploch
Aug 6, 2014

There are 14 solutions to the equation:

10000 A + 2000 B + 300 C + 40 D + 5 E = 10000 F + 1000 G + 100 H + 10 I + J 10000A + 2000B + 300C + 40D + 5E = 10000F + 1000G + 100H + 10I + J

Subject to the restriction:

{ A , B , C , D , E , F , G , H , I , J } = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } \{A,B,C,D,E,F,G,H,I,J\} = \{0,1,2,3,4,5,6,7,8,9\}

6 of these don't count, because they yield leading zeroes in the addends. This yields the remaining 8 solutions:

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

Of these, the unique, minimal value of A + B + C + D + E A + B + C + D + E is 21 21 :

3 + 8 + 1 + 7 + 2 = 21 3 + 8 + 1 + 7 + 2 = 21

This yields the formula:

38172
+8172
+ 172
+  72
+   2
-----
46590

And the solution is thus 3817246590 3817246590 .

Here's some naive python code. It takes about a minute to run through 10 ! 10! permutations on my machine - faster runtimes can be achieved by observing that:

  • J { 0 , 5 } J \in \{0, 5\}
  • F = A + 1 F = A + 1
  • B 5 B \geq 5

Probably more as well.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
    from itertools import permutations

    def num(a):
      ret = 0
      for x in a:
        ret += x
        ret *= 10
      return ret / 10

    \# Get all solutions
    q = [x for x in permutations(range(0,10)) if sum([num(x[i:5]) for i in range(0,5)]) == num(x[5:])]

    \# Strip out invalid ones
    q = [x for x in q if 0 not in x[:6]]

    \# Find the minimum of A + B + C + D + E
    s = min([sum(x[:5]) for x in q])

    \# [(3, 8, 1, 7, 2, 4, 6, 5, 9, 0)]
    print [x for x in q if sum(x[:5]) == s] 

How did you find the solutions? It seems to be somewhat tedious listing / case checking.

Calvin Lin Staff - 6 years, 10 months ago

Log in to reply

Loops.

Bah, you're right, this was a poor problem to post. I was optimistic that there might have been a cleverer way to discover these answers, but there doesn't seem to be in retrospect. I'll delete the problem in a bit, come up with something better.

Daniel Ploch - 6 years, 10 months ago

Log in to reply

This is a valid question. and there is no reason to delete it. I was asking because it might be better placed in Computer Science.

I get that J = 0 or 5, but after that it wasn't clear how to proceed.

Calvin Lin Staff - 6 years, 10 months ago

Log in to reply

@Calvin Lin Is it possible to re-categorize it without deleting and reposting it? I've yet to discover such an option in the UI

Daniel Ploch - 6 years, 10 months ago

Log in to reply

@Daniel Ploch I have (just) taken care of it. Thanks!

Calvin Lin Staff - 6 years, 10 months ago

Log in to reply

@Calvin Lin Alright, thanks! Sorry for the trouble.

Daniel Ploch - 6 years, 10 months ago

I do not think you can assume B >= 5 based just on observation. Note 4 + 4 + 2 (carried) = 10 which will carry 1 to A.

So if C = 9, 9 + 9 + 9 = 27, so H = 7, B = 4, G = 0

B = 4, G = 0, C = 7, H = 1 also works.

Flewk Isdead - 6 years, 9 months ago
Bill Bell
Jul 25, 2015

Quite repulsive in comparison to others.

Swapnil Bhargava
Sep 29, 2014

Here's my C++ code

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
using namespace std;
int main()
{
    bool flag;
    int a,b,c,d,e,f,g,h,i,j,min,vsum=45,mina,minb,minc,mind,mine,minf,ming,minh,mini,minj,arr[10],sum,p,cvsum;
    for(a=1;a<=9;a++)
    {
        for(b=1;b<=9;b++)
        {
            if(b==a)
                continue;
            else
            {
                for(c=1;c<=9;c++)
                {
                    if(c==a || c==b)
                        continue;
                    else
                    {
                        for(d=1;d<=9;d++)
                        {
                            if(d==a || d==b || d==c)
                                continue;
                            else
                            {
                                for(e=1;e<=9;e++)
                                {
                                    if(e==a || e==b || e==c || e==d)
                                        continue;
                                    else
                                    {
                                        sum=(5*e)+(4*10*d)+(3*100*c)+(2*1000*b)+(10000*a);
                                        j=sum%10;
                                        sum/=10;
                                        i=sum%10;
                                        sum/=10;
                                        h=sum%10;
                                        sum/=10;
                                        g=sum%10;
                                        sum/=10;
                                        f=sum%10;
                                        sum/=10;
                                        if(sum==0 && f!=0)
                                        {
                                            flag=true;
                                            for(p=0;p<10;p++)
                                                arr[p]=0;
                                            arr[a]++;
                                            arr[b]++;
                                            arr[c]++;
                                            arr[d]++;
                                            arr[e]++;
                                            arr[f]++;
                                            arr[g]++;
                                            arr[h]++;
                                            arr[i]++;
                                            arr[j]++;
                                            for(p=0;p<10;p++)
                                            {
                                                if(arr[p]>=2)
                                                    flag=false;
                                            }
                                            if(flag)
                                            {
                                                cvsum=a+b+c+d+e;
                                                if(cvsum<vsum)
                                                {
                                                    mina=a;
                                                    minb=b;
                                                    minc=c;
                                                    mind=d;
                                                    mine=e;
                                                    minf=f;
                                                    ming=g;
                                                    minh=h;
                                                    mini=i;
                                                    minj=j;
                                                    vsum=cvsum;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<mina<<minb<<minc<<mind<<mine<<minf<<ming<<minh<<mini<<minj;
    return 0;
} 

Kenny Lau
Sep 7, 2014

java code:

 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
32
33
34
35
36
37
38
39
40
41
42
43
    import java.util.Arrays;
    public class brilliant201409071714{
        public static void main(String args[]){
            long[] sum = new long[256];
            long[] list = new long[256];
            int count = 0;
            for(long a=1;a<9;a++){ //a cannot be 9 lest f be 10
                for(long b=4;b<=9;b++){ //b greater than 3 lest f=a
                    if(b==a) continue;
                    for(long c=1;c<=9;c++){
                        if(c==b||c==a) continue;
                        for(long d=1;d<=9;d++){
                            if(d==c||d==b||d==a) continue;
                            for(long e=1;e<=9;e++){
                                if(e==d||e==c||e==b||e==a) continue;
                                long j = e*5;
                                long i = d*4 + j/10;
                                long h = c*3 + i/10;
                                long g = b*2 + h/10;
                                long f = a + g/10;
                                if(f>9) continue;
                                j %= 10;
                                i %= 10;
                                h %= 10;
                                g %= 10;
                                if(f==e||f==d||f==c||f==b||f==a) continue;
                                if(g==f||g==e||g==d||g==c||g==b||g==a) continue;
                                if(h==g||h==f||h==e||h==d||h==c||h==b||h==a) continue;
                                if(i==h||i==g||i==f||i==e||i==d||i==c||i==b||i==a) continue;
                                if(j==i||j==h||j==g||j==f||j==e||j==d||j==c||j==b||j==a) continue;
                                sum[count] = a+b+c+d+e;
                                list[count] = ((((((((a*10L+b)*10+c)*10+d)*10+e)*10+f)*10+g)*10+h)*10+i)*10+j;
                                count++;
                            }
                        }
                    }
                }
            }
            System.out.println(Arrays.toString(Arrays.copyOf(sum,count)));
            System.out.println(Arrays.toString(Arrays.copyOf(list,count)));
            System.out.println(count);
        }
    }

output:

[27, 23, 24, 21, 23, 27, 28, 27]
[1476920385, 1487320695, 2489130765, 3817246590, 6493170825, 6539471280, 8675294310, 8742695310]
8
Press any key to continue . . .
Steven Zheng
Aug 22, 2014

I solved this by trial and error (old-fashioned way). It took me 5 tries to get

38172+8172+172+72+2 = 46590

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...