"Imagine" the Taming Helmet

T A M I N G + H E L M E T 9 2 5 7 6 4 \begin{array}{ccccccc} &&T & A &M & I & N&G\\ + & &H & E& L& M & E &T \\ \hline & &9 &2 & 5 & 7 & 6 &4\\ \hline \end{array}

Above represents a cryptogram such that each letter represents a distinct single digit positive integer. Find the value of the 7-digit integer I M A G I N E \overline{IMAGINE} .


The answer is 9871924.

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.

4 solutions

Shreyash S
Sep 20, 2014

I used this Python Code

for T in xrange(1,10):
    for A in xrange(1,10):
        for M in xrange(1,10):
            for I in xrange(1,10):
                for N in xrange(1,10):
                    for G in xrange(1,10):
                        for H in xrange(1,10):
                            for E in xrange(1,10):
                                for L in xrange(1,10):
                                    if ((G+T)%10 == 4) and A not in [T] and M not in [T, A] and I not in [T, A, M] and N not in [T, A, M, I] and G not in [T, A, M, I, N] and H not in [T, A, M, I, N, G] and E not in [T, A, M, I, N, G, H] and L not in [T, A, M, I, N, G, H, E]:
                                        a=G+10*N+100*I+1000*M+10000*A+100000*T
                                        b=T+10*E+100*M+1000*L+10000*E+100000*H
                                        if (b+a == 925764):
                                            print I, M, A, G, I, N, E

Which give me output as 9 8 7 1 9 2 4

There's a far simpler and neater way to do this : simply create an array [ 1 , 2 , , 8 , 9 ] [1,2,\ldots,8,9] and mark (associate) each position of the array with a letter. Then, use a probabilistic algorithm : permute the array randomly, calculate the numbers T A M I N G \overline{TAMING} and H E L M E T \overline{HELMET} and then do the condition check (sum of them being 925764 925764 ). If the condition is true, print out the results, otherwise permute the array and repeat the same process.

Although this algorithm isn't deterministic like yours, this method has a shorter runtime. Here 's the C++ implementation of the above algorithm for this problem. Runtime varies over 0.04 to 0.3 secs in general. I used the positions 0 , 1 , 2 , , 8 0,1,2,\ldots,8 for T , H , A , E , M , L , I , N , G T,H,A,E,M,L,I,N,G respectively.

Prasun Biswas - 5 years, 7 months ago

Actually, 8973824 is also a correct solution. Assuming T = 1, A = 7, M = 9, I = 8, N = 2, G = 3, H = 7, E = 4 and L = 5, one can arrive at the correct solution by using distinct positive integers. This problem has lots of different answers

Kaleab Belete - 5 years, 5 months ago

Log in to reply

The example you mention has A=H=7 which violates the condition that all the letters represent distinct single digit positive integers.

This problem "has lots of different answers" only if you don't put the restriction that all letters represent distinct single positive integers.

With the above-mentioned restriction enforced, the solution to the problem is unique .

Prasun Biswas - 5 years, 5 months ago

Hey my code in Netbeans isn't working. Can you point out my mistake?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
int T = 0;
int T = 0;
int A = 0;
int M = 0;
int I = 0;
int N = 0;
int G = 0;
int H = 0;
int E = 0;
int L = 0;
int a1 = 0;
int b1 = 0;
a1=G+(10*N)+(100*I)+(1000*M)+(10000*A)+(100000*T);
b1=T+(10*E)+(100*M)+(1000*L)+(10000*E)+(100000*H);
if(((b1+a1)==925764) && ((G+T)%10==4) && (A!=T) &&((M!=A) && (M!=T)) && ((I!=T) &&(I!=A) &&(I!=M)) && ((N!=T) &&(N!=A) &&(N!=M) &&(N!=I))&& ((G!=T) &&(G!=A) &&(G!=M))&& ((G!=I) &&(G!=N))&& ((H!=T) &&(H!=A) &&(H!=M) &&(H!=I) &&(H!=N) &&(H!=G))&& ((E!=T) &&(E!=A) &&(E!=M) &&(E!=I) &&(E!=N) &&(E!=G) &&(E!=H)) &&((L!=T) &&(L!=A) &&(L!=M) &&(L!=I) &&(L!=N) &&(L!=G) &&(L!=H) &&(L!=E))){
   ans.setText(""+I+"+"+M+"+"+A+"+"+G+"+"+I+"+"+N+"+"+E);    
}

Aditya Kumar - 5 years, 5 months ago

Log in to reply

I haven't ever used NetBeans or Java, so I might miss on syntax mistakes (if any) in your code but I can point out the logical errors in your code.

Your code never changes the values of the letters (variables) during runtime, you just assigned them all to 0 0 , computed a1 and b1 with the values, obviously the result is a1 = b1 = 0 0 since all the letters are assigned to 0 0 and then you put the if check that is obviously false since none of the conditions are met (the sum is 0, not 925764 and all the other conditions are also not met, although since you're using && , falsity of just one condition makes the whole condition false anyway). The if block isn't executed since the condition is false and the program terminates.

Basically, what your program did was check if 0 + 0 = 925764 0+0=925764 or not (also the other conditions). Since it wasn't, the program terminated without any output.

What you need here is a way to change the values of the letters after each test (the condition checking) and retest with the new values so as to check different combinations of the letter values. Are you familiar with the concept of looping?

Better yet, there are probabilistic methods to do this which I'd prefer to the deterministic method (using loops to change the values of the letters) here since the deterministic method will take much more time to output the answer. I have posted one such probabilistic method in a comment below (in C++). You can check it out if you want.

Prasun Biswas - 5 years, 5 months ago

@Prasun Biswas can u also help?

Aditya Kumar - 5 years, 5 months ago

My code is given below, it give me the result=6113651

def m():

for T in range(1,10):

    for A in range(1,10):

        for M in range(1,10):

            for I in range(1,10):

                for N in range(1,10):

                    for G in range(1,10):

                        for H in range(1,10):

                            for L in range(1,10):

                                for E in range(1,10):

                                    X=int(str(T)+str(A)+str(M)+str(I)+str(N)+str(G))

                                    Y=int(str(H)+str(E)+str(L)+str(M)+str(E)+str(T))

                                    if X+Y==925764:

                                        return I,M,A,G,I,N,E

Masbahul Islam - 5 years, 7 months ago

Log in to reply

You must make sure that all variables are distinct. Your answer has repeated values (as shown with M = A = 1 M = A = 1 ).

Ivan Koswara - 5 years, 7 months ago

I called it Super FOR also IF!!

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

int main(){
int nut,shell,elf;

for(int g=1;g<10;g++){
    for(int t=1;t<10;t++){ 
        for(int n=1;n<10;n++){
            for(int m=1;m<10;m++){
                for(int i=1;i<10;i++){
                    for(int l=1;l<10;l++){
                        for(int a=1;a<10;a++){
                            for(int h=1;h<10;h++){
                                for(int e=1;e<10;e++){
if((g!=t) && (g!=n) && (g!=m) && (g!=i) && (g!=l) && (g!=a) && (g!=h) && (g!=e) && (t!=n) && (t!=m) && (t!=i) && (t!=l) && (t!=a) && (t!=h) && (t!=e) &&
   (n!=m) && (n!=i) && (n!=l) && (n!=a) && (n!=h) && (n!=e) && (m!=i) && (m!=l) && (m!=a) && (m!=h) && (m!=e) && (i!=l) && (i!=a) && (i!=h) && (i!=e) &&
   (l!=a) && (l!=h) && (l!=e) && (a!=h) && (a!=e) && (h!=e)){
                                nut=t*100000+a*10000+m*1000+i*100+n*10+g;
                                shell=h*100000+e*10000+l*1000+m*100+e*10+t;
                                if ((nut+shell)==925764){
if((i!=m) && (i!=a) && (i!=g) && (i!=n) && (i!=e) && (a!=m) && (g!=m) && (n!=m) && (e!=m) && (g!=a) && (g!=n) && (g!=e) && (e!=a) && (e!=n) && (n!=a)){
                                    elf=i*1000000+m*100000+a*10000+g*1000+i*100+n*10+e;
                                    cout<<elf<<endl;
                                    }
                                    }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
}

Lu Chee Ket
Dec 5, 2015

You may notice that:

1
2
0   7   9   1   0   4   2
3   4   7   8   3   0   5

At least valid with another one. Answer to this question may be arrived without computing method.

Bill Bell
Jul 18, 2015

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...