+ T H 9 A E 2 M L 5 I M 7 N E 6 G T 4
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 .
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.
There's a far simpler and neater way to do this : simply create an array [ 1 , 2 , … , 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 and H E L M E T and then do the condition check (sum of them being 9 2 5 7 6 4 ). 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 for T , H , A , E , M , L , I , N , G respectively.
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
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 .
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 |
|
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
, computed
a1
and
b1
with the values, obviously the result is
a1
=
b1
=
0
since all the letters are assigned to
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 = 9 2 5 7 6 4 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 can u also help?
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
Log in to reply
You must make sure that all variables are distinct. Your answer has repeated values (as shown with M = A = 1 ).
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 |
|
You may notice that:
1 2 |
|
At least valid with another one. Answer to this question may be arrived without computing method.
Problem Loading...
Note Loading...
Set Loading...
I used this Python Code
Which give me output as 9 8 7 1 9 2 4