Water + Earth = Melon

WATER +EARTH MELON \Large{\begin{matrix} \text{WATER} \\ \underline { \text{+EARTH} } \\ \text{MELON} \end{matrix}}

If above given is a cryptogram such that each distinct letter represents distinct single digit numbers (i.e. 0,1, 2, 3, ...., 9). Find the sum of all values of MELON \text{MELON} . Note:- W , E , M 0 W,E,M \neq 0


The answer is 652560.

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

It takes a long time

 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
#include<bits/stdc++.h>
using namespace std;

int main(){
int w,a,t,e,r,m,l,o,n,h;
long long shell,elf,sale,rest;
long long bill=0;

w=1; a=0; t=0; e=1; r=0;
while(w<10)  {
    while(a<10){
        while(t<10){
            while(e<10){
                while(r<10){
                    for(m=1;m<10;m++){
                        for(l=0;l<10;l++){
                            for(o=0;o<10;o++){
                                for(n=0;n<10;n++){
                                        for(h=0;h<10;h++){
if((w!=a) && (w!=t) && (w!=e) && (w!=r) && (w!=m) && (w!=l) && (w!=o) && (w!=n) && (w!=h) &&
   (a!=t) && (a!=e) && (a!=r) && (a!=m) && (a!=l) && (a!=o) && (a!=n) && (a!=h) &&
   (t!=e) && (t!=r) && (t!=m) && (t!=l) && (t!=o) && (t!=n) && (t!=h) &&
   (e!=r) && (e!=m) && (e!=l) && (e!=o) && (e!=n) && (e!=h) &&
   (r!=m) && (r!=l) && (r!=o) && (r!=n) && (r!=h) && 
   (m!=l) && (m!=o) && (m!=n) && (m!=h) &&
   (l!=o) && (l!=n) && (l!=h) &&
   (o!=n) && (o!=h) &&
   (n!=h)){
                        shell=w*10000+a*1000+t*100+e*10+r; elf=e*10000+a*1000+r*100+t*10+h; sale=m*10000+e*1000+l*100+o*10+n;
                        if((shell+elf)==sale) bill+=sale;
                                }
                                }
                                }
                    }
                    }
                }
                r++;}
            e++;r=0;}
        t++;e=1;}
    a++;t=0;}
w++;a=0;}   

cout<<bill<<endl; //OUTPUT=652560

}

about 171 sec.

Good but not better than mine :P

Zeeshan Ali - 5 years, 3 months ago

Log in to reply

"while" faster than "for", I think :/

Resha Dwika Hefni Al-Fahsi - 5 years, 3 months ago

If you want to find all the values, you don't need to wait for that long; here's my python code:

1
2
3
4
5
for w,a,t,e,r,h,m,l,o,n in permutations('0123456789',10):
  if '0' in (w,e,m):
    continue
  if int(w+a+t+e+r)+int(e+a+r+t+h)==int(m+e+l+o+n):
    print(m+e+l+o+n)

Zeeshan Ali
Jan 16, 2016

Well... It was so boring to wait so long for the result but I did it...

 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
#include<iostream>
using namespace std;
int main(){
    long long int sum=0;
    for (int w=1; w<10; w++){
    for (int a=0; a<10; a++){
    for (int t=0; t<10; t++){
    for (int e=1; e<10; e++){
    for (int r=0; r<10; r++){
    for (int h=0; h<10; h++){
    for (int m=1; m<10; m++){
    for (int l=0; l<10; l++){
    for (int o=0; o<10; o++){
    for (int n=0; n<10; n++){
        if (!((w+e+(a+a+(t+r+(e+t+(r+h)/10)/10)/10)/10)/10)){
            if (w!=a && w!=t && w!=e && w!=r && w!=h && w!=m && w!=l && w!=o && w!=n){
                if (a!=t && a!=e && a!=r && a!=h && a!=m && a!=l && a!=o && a!=n){
                    if (t!=e && t!=r && t!=h && t!=m && t!=l && t!=o && t!=n){
                        if (e!=r && e!=h && e!=m && e!=l && e!=o && e!=n){
                            if (r!=h && r!=m && r!=l && r!=o && r!=n){
                                if (h!=m && h!=l && h!=o && h!=n){
                                    if (m!=l && m!=o && m!=n){
                                        if (l!=o && l!=n){
                                            if (o!=n){                              
                                                if (w!=a && w!=t && w!=e && w!=r && w!=h && w!=m && w!=l && w!=o && w!=n){
                                                    int A[5];
                                                    A[0]=(r+h)%10;
                                                    A[1]=(e+t+(r+h)/10)%10;
                                                    A[2]=(t+r+(e+t+(r+h)/10)/10)%10;
                                                    A[3]=(a+a+(t+r+(e+t+(r+h)/10)/10)/10)%10;
                                                    A[4]=(w+e+(a+a+(t+r+(e+t+(r+h)/10)/10)/10)/10)%10;
                                                    if (A[0]==n && A[1]==o && A[2]==l && A[3]==e && A[4]==m){
                                                        long long int term=m*10000+e*1000+l*100+o*10+n;
                                                        sum+=term;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    cout<<sum<<endl;
    return 0;
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
for c in range(1,10):
    for h in range(10):
        if h!=c:
            for a in range(10):
                if a not in [h,c]:
                    for r in range(1,10):
                        if r not in [c,h,a]:
                            for y in range(10):
                                if y not in [c,h,a,r]:  
                                    for s in range(1,10):
                                        if s not in [c,h,a,r,y]:    
                                            for e in range(10):
                                                if e not in [c,h,a,r,y,s]:
                                                    for m in range(10):
                                                        if m not in [c,h,a,r,y,s,e]:
                                                            for u in range(10):
                                                                if u not in [c,h,a,r,y,s,e,m]:
                                                                    for b in range(10):
                                                                        if b not in [c,h,a,r,y,s,e,m,u]:
                                                                            if (10000*(c+r-s)+1000*(h+h-r)+100*(a+y-e)+10*(r+a-m)+y+b-u==0):
                                                                                print s,r,e,m,u

did not take much time.

Soumava Pal - 5 years, 3 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...