WRONG + WRONG = RIGHT

They say that 2 wrongs do not make a right. But sometimes, they can.

In this alphameric puzzle, we could replace each of the letters with a unique digit, such that the addition works. For example, we have

12734 + 12734 25468 \begin{aligned} & 12734 \\ + & 12734 \\ \hline & 25468 \\ \end{aligned}

What is the total number of such solutions?


The answer is 21.

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

Lu Chee Ket
Dec 17, 2015

WRONG and RIGHT:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
12734   25468
12867   25734
12938   25876
24153   48306
24765   49530
25173   50346
25193   50386
25418   50836
25438   50876
25469   50938
25734   51468
25867   51734
25938   51876
37081   74162
37091   74182
37806   75612
37846   75692
37908   75816
49153   98306
49265   98530
49306   98612
WRONG   RIGHT

Answer: 21 \boxed{21}

 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
#include <iostream>
#include <cmath>
using namespace std;

bool Distinct (int tab[],int tab2[]){

    int tab3[8] = {tab[0], tab[1], tab[2], tab[3], tab[4], tab2[1], tab2[3], tab2[4]};
    bool distinct = true;
    for (int i = 0; i < 8; i++)
    {
        for (int k = i + 1; k < 8; k++)
        {
            if (tab3[i] == tab3[k]) return !distinct; 
        }
    }
    return distinct;
}
int main ()
{
    int Wrong[5] = {0,0,0,0,0};
    int Right[5];
    int i = 0;
    int cpt = 0;
    while (i < 50000)
    {
        for (int k = 0;k < 5;k++)
        {
            Wrong[k] = floor((i % (int)(pow(10,5-k))) / pow(10,5-(k+1)));
        }
        for (int k = 0;k < 5;k++)
        {
            Right[k] = floor(((i * 2) % (int)(pow(10,5-k))) / pow(10,5-(k+1)));
        }
        if (Wrong[4] == Right[2] && Wrong[1] == Right[0] && Distinct(Wrong,Right)) 
        {   
            cpt++;
        }
        i++;
    }
    cout << cpt << endl;
    return 0;
}

My mighty Mathematica code! It runs fast!

1
2
3
4
5
6
7
8
9
Select[Permutations[Range[0, 9], {8}], Block[{w = #[[1]],
    r = #[[2]],
    o = #[[3]],
    n = #[[4]],
    g = #[[5]],
    i = #[[6]],
    h = #[[7]],
    t = #[[8]]}, 
   2 FromDigits[{w, r, o, n, g}] == FromDigits[{r, i, g, h, t}]] &]

( W R O N G I H T 1 2 7 3 4 5 6 8 1 2 8 6 7 5 3 4 1 2 9 3 8 5 7 6 2 4 1 5 3 8 0 6 2 4 7 6 5 9 3 0 2 5 1 7 3 0 4 6 2 5 1 9 3 0 8 6 2 5 4 1 8 0 3 6 2 5 4 3 8 0 7 6 2 5 4 6 9 0 3 8 2 5 7 3 4 1 6 8 2 5 8 6 7 1 3 4 2 5 9 3 8 1 7 6 3 7 0 8 1 4 6 2 3 7 0 9 1 4 8 2 3 7 8 0 6 5 1 2 3 7 8 4 6 5 9 2 3 7 9 0 8 5 1 6 4 9 1 5 3 8 0 6 4 9 2 6 5 8 3 0 4 9 3 0 6 8 1 2 ) \left( \begin{array}{cccccccc} W&R&O&N&G&I&H&T\\ 1 & 2 & 7 & 3 & 4 & 5 & 6 & 8 \\ 1 & 2 & 8 & 6 & 7 & 5 & 3 & 4 \\ 1 & 2 & 9 & 3 & 8 & 5 & 7 & 6 \\ 2 & 4 & 1 & 5 & 3 & 8 & 0 & 6 \\ 2 & 4 & 7 & 6 & 5 & 9 & 3 & 0 \\ 2 & 5 & 1 & 7 & 3 & 0 & 4 & 6 \\ 2 & 5 & 1 & 9 & 3 & 0 & 8 & 6 \\ 2 & 5 & 4 & 1 & 8 & 0 & 3 & 6 \\ 2 & 5 & 4 & 3 & 8 & 0 & 7 & 6 \\ 2 & 5 & 4 & 6 & 9 & 0 & 3 & 8 \\ 2 & 5 & 7 & 3 & 4 & 1 & 6 & 8 \\ 2 & 5 & 8 & 6 & 7 & 1 & 3 & 4 \\ 2 & 5 & 9 & 3 & 8 & 1 & 7 & 6 \\ 3 & 7 & 0 & 8 & 1 & 4 & 6 & 2 \\ 3 & 7 & 0 & 9 & 1 & 4 & 8 & 2 \\ 3 & 7 & 8 & 0 & 6 & 5 & 1 & 2 \\ 3 & 7 & 8 & 4 & 6 & 5 & 9 & 2 \\ 3 & 7 & 9 & 0 & 8 & 5 & 1 & 6 \\ 4 & 9 & 1 & 5 & 3 & 8 & 0 & 6 \\ 4 & 9 & 2 & 6 & 5 & 8 & 3 & 0 \\ 4 & 9 & 3 & 0 & 6 & 8 & 1 & 2 \\ \end{array} \right)

Well done Agnishom!

Daniele Giuffrida - 6 years, 3 months ago

Wow i am speechless, what is the language used by the way ?

Elmokhtar Mohamed Moussa - 6 years, 3 months ago
Brian Riccardi
Sep 30, 2014

And this is my C++ code :P I think it is one of my ugliest codes :D

 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int control( int w, int r )
{
        int W, R, O, N, G, R1, I, G1, H, T;

        G=w%10; w/=10;
        N=w%10; w/=10;
        O=w%10; w/=10;
        R=w%10; w/=10;
        W=w%10; w/=10;

        T=r%10; r/=10;
        H=r%10; r/=10;
        G1=r%10; r/=10;
        I=r%10; r/=10;
        R1=r%10; r/=10;

        if( R==R1 && G==G1 && W!=R && W!=O &&
             W!=N && W!=G && W!=I && W!=H &&
             W!=T && R!=O && R!=N && R!=G &&
             R!=I && R!=H && R!=T && O!=N &&
             O!=G && O!=I && O!=H && O!=T &&
             N!=G && N!=I && N!=H && N!=T &&
             G!=I && G!=H && G!=T &&
             I!=H && I!=T && H!=T) return 1;

        return 0;

}

int main()
{
        int WRONG, RIGHT, ans=0;;

        for(WRONG=10000; WRONG<100000; WRONG++){
                RIGHT=2*WRONG;
                if( RIGHT>=100000 ){
                        cout << ans << endl;
                        return 0;
                }
                ans+=control( WRONG,RIGHT );
        }
}

Swapnil Bhargava
Sep 28, 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
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int flag;
    long long int a,b,count=0;
    int w,r,o,n,g,arr[10],R,I,G,H,T,i;
    for(w=0;w<=9;w++)
    {
        for(r=0;r<=9;r++)
        {
            if(w==r)
                continue;
            else
            {
                for(o=0;o<=9;o++)
                {
                    if(o==w || o==r)
                        continue;
                    else
                    {
                        for(n=0;n<=9;n++)
                        {
                            if(n==w || n==r || n==o)
                                continue;
                            else
                            {
                                for(g=0;g<=9;g++)
                                {
                                    if(g==w || g==r || g==o || g==n)
                                        continue;
                                    else
                                    {
                                        a=w*10000+r*1000+o*100+n*10+g;
                                        a=2*a;
                                        T=a%10;
                                        a/=10;
                                        H=a%10;
                                        a/=10;
                                        G=a%10;
                                        a/=10;
                                        I=a%10;
                                        a/=10;
                                        R=a%10;
                                        a/=10;
                                        if(a==0 && r==R && g==G)
                                        {
                                            flag=1;
                                            for(i=0;i<10;i++)
                                                arr[i]=0;
                                            arr[w]++;
                                            arr[r]++;
                                            arr[o]++;
                                            arr[n]++;
                                            arr[g]++;
                                            arr[I]++;
                                            arr[H]++;
                                            arr[T]++;
                                            for(i=0;i<10;i++)
                                            {
                                                if(arr[i]>=2)
                                                {
                                                    flag=0;
                                                    break;
                                                }
                                            }
                                            if(flag)
                                                count++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

        }
    }
    cout<<count;
    return 0;
}

Bill Bell
Jul 25, 2015

Abdelhamid Saadi
Jul 15, 2015

Solution in python 3.4

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def wrongright():
    tot = 0
    for i in range(10000, 50000):
        stri = str(i)
        str2i = str(2*i)
        if stri[1] == str2i[0] and stri[4] == str2i[2] and len(set(stri + str2i)) == 8:
            tot += 1
    return tot

print(wrongright())

Gaurav Rao
Jun 22, 2015

Java Solution!

 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
 public class Wrongs {
    public static void main(String[] args) {
        int ctr = 0;
        for (int w = 1; w <= 9; w++)
            for (int r = 1; r <= 9; r++)
                for (int o = 0; o <= 9; o++)
                    for (int n = 0; n <= 9; n++)
                        for (int g = 0; g <= 9; g++)
                            for (int i = 0; i <= 9; i++)
                                for (int h = 0; h <= 9; h++)
                                    for (int t = 0; t <= 9; t++)
                                        if (2 * makeInt(w, r, o, n, g) == makeInt(
                                                r, i, g, h, t)
                                                && checkDiverse(w, r, o, n, g, i,
                                                        h, t)) {
                                            ctr++;

                                        }
        System.out.println(ctr);

    }
    public static int makeInt(int d1, int d2, int d3, int d4, int d5) {
        return 10000 * d1 + 1000 * d2 + 100 * d3 + 10 * d4 + d5;
    }
    public static boolean checkDiverse(int... asdf) {
        for (int i = 0; i < asdf.length; i++) {
            for (int j = i + 1; j < asdf.length; j++) {
                if (asdf[i] == asdf[j])
                    return false;
            }
        }
        return true;
    }

}

Nam Diện Lĩnh
Jun 19, 2015
 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
var c=0;
function digits(n)
{
    var result=[];
    do
    {
        result.unshift(n%10);
        n=parseInt(n/10);
    }
    while(n);

    return result;
}

function unique(digits)
{
    var set=[];
    for(var i=0;i<digits.length;i++)
        if(set.indexOf(digits[i])==-1)
        {
            set.push(digits[i]);
        }
        else
            return false;

    return true;
}

function check(w, r)
{
    var wrong=digits(w);
    var right=digits(r);

    if(!unique(wrong))
        return false;
    if(!unique(right))
        return false;

    var others=[];

    others.push(wrong[0]);
    others.push(wrong[2]);
    others.push(wrong[3]);

    others.push(right[1]);
    others.push(right[3]);
    others.push(right[4]);

    if(wrong[1]==right[0]&&wrong[4]==right[2]&&unique(others))
        return true;

    return false;
}

for(var i=10000;i<50000;i++)
{

    if(check(i, i*2))
        c++;
}
console.log(c);

I am in year 6 and my teacher gave me this question, these comments are so helpful.

TGF The Green Fire - 2 years, 3 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...