Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with a cryptarithmetic puzzle
#1
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.
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..)
OK now i have to solve a similar example and its :
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:
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?
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
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 ?
Reply
#2
Hmm.. i'll try.
Reply
#3
(08-31-2010, 02:43 PM)Renegader Wrote: Hmm.. i'll try.

thanks a lot in advance and if you have any easier way you can also share it and i'll try to help think of a algorithm for it with you
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)