Mistakes give rise to problems

Logic Level 5

a b c d + b c d a 0 d c b a + c b a d 0 \large{\begin{array}{cccccc} & & & a & b & c&d\\ +& & & b & c & d & a \\ \hline && & & & & \phantom0&\\ \hline \end{array}} \qquad \qquad \large{\begin{array}{cccccc} & & & d & c & b &a \\ +& & & c& b & a & d \\ \hline && & & & \phantom0 &\\ \hline \end{array}}

If a , b , c a,b,c and d d are not necessarily distinct single-digit positive integers so that the result of both additions is the same, find the number of possible quadruples ( a , b , c , d ) (a,b,c,d) .



The answer is 489.

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.

3 solutions

Using Python 3:

ans=0
for a in range(1,10):
    for b in range(1,10):
        for c in range(1,10):
            for d in range(1,10):
                if 1000*a+100*b+10*c+d+1000*b+100*c+10*d+a==1000*d+100*c+10*b+a+1000*c+100*b+10*a+d:
                    ans+=1
                else:
                    pass
print (ans)

Then we get 489.

@Julian Poon , is this solvable without CS?

Pi Han Goh - 5 years, 4 months ago

Log in to reply

Yes. I forgot how but it involves combinatorics. I also see that the inspiration has been changed to link to the same problem, neither did I add that the problem is original, because it is not, it was inspired by nihar's problem. If I'm not wrong it can be solved by noticing that c + d = b + a c+d=b+a

Julian Poon - 5 years, 4 months ago

Log in to reply

Can you show us how it's done? I have a solution, but that involved plenty of case checking which should be avoided.

Pi Han Goh - 5 years, 4 months ago

Log in to reply

@Pi Han Goh You can see Jon's report on this problem.

Julian Poon - 5 years, 4 months ago

I solved it without programming but, unfortunately, after viewing the answer.
First of all, I noted that it is neccessary that a + b = c + d a+b=c+d .
Now, First of all, all palindromes and nos. of the form a b a b abab are solutions ,totalling to: 81+72=153.
Now, coming to the cases where a,b,c,d are distinct:
There are 34 cases with 8 arrangement each totalling to 272.
Now, there are 16 cases with a=b but not equal to c or d; with 4 arrangements each totalling to 64.
Hence, total no. Of solutions is 272+64+153 = 489 \boxed{489} .
P.S. : I just wanted to tell my way. Sorry for any disturbance caused.


Yatin Khanna - 5 years ago

Using the legendary minizinc

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
include "globals.mzn";

int: n = 9;

array[1..4] of var 0..n: A;

solve satisfy;

constraint
  1000*A[1] + 100*A[2] + 10*A[3] + A[4]
  + 1000*A[2] + 100*A[3] + 10*A[4] + A[1] =
  1000*A[4] + 100*A[3] + 10*A[2] + A[1]
  + 1000*A[3] + 100*A[2] + 10*A[1] + A[4]
;

constraint
  forall(i in 1..4)
    (A[i] != 0)
;

output [show(A)];

Zeeshan Ali
Mar 23, 2016

Let your program do it for you.. :P

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    int C=0;
    for(int a=1; a<10; a++){
        for(int b=1; b<10; b++){
            for(int c=1; c<10; c++){
                for(int d=1; d<10; d++){
                    int num1=a*1000+b*100+c*10+d,
                        num2=b*1000+c*100+d*10+a,
                        num3=d*1000+c*100+b*10+a,
                        num4=c*1000+b*100+a*10+d;
                    if(num1+num2==num3+num4){
                        cout<<"C="<<++C<<endl;
                    }
                }
            }
        }
    }
    cout<<C<<endl;

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...