+ G J M H K N I L O
The above represents a cryptogram such that each letter represents a distinct single digit non-negative integer. Find the number of solutions of the above cryptogram.
Note: G and J are non-zero.
Also see Part 1
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.
Holy god, @Agnishom Chattopadhyay , how many languages do you know, mate?
Log in to reply
Haha! I have been programming for a long time, so I have come across a several languages. Now, I mainly code in C++ and python but I have tried to learn/written non-significant programs in PHP, FORTRAN, BASIC, Haskell, Perl, javascript, Mathematica, Maxima, etc too. (By the way, I am writing an wiki on lambda calculus now, which is kind of a language)
This language is MiniZinc. It lets you talk to the MiniZinc solver, which is an awesome tool for discrete optimization . I tried to learn it too, but I am not very good at this.
Log in to reply
The lambda calculus stuff is pretty interesting. I will make sure I read the wiki.
Talking to the solver.... Sounds somewhat like Prolog. :D
Log in to reply
@Soumava Pal – Yes, it let's you do that kind of stuff. Like filling a magic square or a sudoku, or linear programming, the knapsack problem, etc
Log in to reply
@Agnishom Chattopadhyay – Wow... That definitely is exciting. :D
Implementation of Cryptogram
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 |
|
Hi can you please tell me where I have gone wrong? I found all the permutations of '123456789' and then split each permutation into three equal parts. I then iterated over these checking whether the first two parts were equal to the third. I got an answer of 3 2 1 ; where have I gone wrong? Thanks :)
Log in to reply
Non-negative integers. But then again you should get 336 with positive integers, not 321, not sure why you got 321.
A traditional approach in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Note the optimization: for every A B C + D E F = G H I we have D E F + A B C = G H I , and that is necessarily a different solution. Therefore we only generate solutions with A B C < D E F and count them double.
I used python to solve this as well as permutations from itertools:
1 2 3 4 5 6 7 8 |
|
int main()
{ int a,b,c,d,e,f,g,h,k,l,m,n,x=0;
for(a=1;a<=9;a++)
{
for(b=0;b<=9;b++)
{
for(c=0;c<=9;c++)
{
if(c!=a && c!=b && b!=a)
{
d=100*a+10*b+c;
for(e=1;e<=9;e++)
{
for(f=0;f<=9;f++)
{
for(g=0;g<=9;g++)
{
if(g!=f && g!=e && f!=e && e!=a && e!=b && e!=c && f!=a && f!=b && f!=c && g!=a && g!=b && g!=c)
{
h=100*e+10*f+g;
if(h+d<1000 && h!=d)
{
k=h+d;
l=k%10;m=(k/10)%10;n=(k/100)%10;
if(l!=a && l!=b && l!=c && l!=e && l!=f && l!=g && m!=a && m!=b && m!=c && m!=e && m!=f && m!=g && n!=a && n!=b && n!=c && n!=e && n!=f && n!=g && l!=m && l!=n && m!=n)
{
x++;
printf("%d\n+\n%d\n=\n%d\n\n",h,d,h+d);
}
}
}
}
}
}
}
}
}
}
printf("Total values=%d",x);
}
I seriously don't know how to get it correctly formatted..
Problem Loading...
Note Loading...
Set Loading...
The legendary minizinc to the rescue:
Generate all solutions and count them