08-31-2010, 01:25 PM
how this puzzle works is that you're given an equation of letters, the goal is to identify the value of each letter. For example : SEND + MORE = MONEY ( given before and solved) and each letter can only be given a value from 0 to 9 and two letters cant have the same value.
OK now i have to solve a similar example and its :
So my question is about the algorithm of the problem. I'm not entirely sure how to do it but i think you use nested loops in order to make it do that, right?
by the way i've posted this on hack forums and i've been told to use backtracking but im not entirely sure how to use the algorithm for that. does anyone here know how to do this with a easier algorithm ?
Code:
S E N D
9 5 6 7 <-- value found for "send"
+ M O R E
1 0 8 5 <-- value found for "more"
__________
M O N E Y
1 0 6 5 2 <-- value for "money"
so the solution for this is ( S = 9, E = 5, N = 6, etc..)
Code:
T O O
T O O
+T O O
T O O
_______
G O O D
so what I've did was manually test every number to check if it'll work with the result and I've got ( O = 9, D = 6, T = 4, G = 1)
at least i think its right :confused:
Code:
#include <iostream>
using namespace std;
int question1();
int main()
{
return 0;
}
int question1();
{
int t, o = 0;
int g, d;
d = 4 * o;
for(int i = 0; i <= 9; i++)
{
for(int j = 0; j<= 9; j++)
{
// something something
}
// something something
}
return 0;
}
yea i know its still doesn't have anything but I'm not sure how to exactly set it up