Computer Science Canada

Possible Words

Author:  Azzy [ Thu Dec 08, 2005 4:37 pm ]
Post subject:  Possible Words

I'm making a program to find possible words from a list letters and numbers. Basically the letters have a corrisponding number and what it does is add three numbers together and if it equals 100 then those three letters are a possible outcome for the word. This is only the first stage so their are only three letters in the word, but later there will be more if I can fix this problem

What happens is it will go through the program but when it gets to the end it says that the variables have no value. It probably has to do with the 2D array cause this is the first time I've used one in turing, but it may not be, so please help me.

code:
var sum : int
var numans : int := 1

var letters : array 1 .. 26 of string :=
    init ("P", "T", "Q", "C", "G", "E", "Y", "I", "O", "U", "S", "S", "L", "I", "N", "J", "T", "R", "Q", "M", "A", "S", "E", "D", "L", "R")
var numbers : array 1 .. 26 of int :=
    init (39, 40, 16, 17, 24, 40, 17, 17, 23, 24, 24, 24, 39, 23, 40, 24, 23, 39, 17, 23, 16, 16, 23, 24, 17, 39)
var answers : array 1 .. 24, 1 .. 3 of int

for first : 1 .. 24
    for second : 2 .. 25
        for third : 3 .. 26
            sum := numbers (first) + numbers (second) + numbers (third)

            if sum = 100 then
                answers (numans, 1) := first
                answers (numans, 2) := second
                answers (numans, 3) := third
                numans += 1
            end if

            sum := 0
        end for
    end for
end for

put "Answers:"
put ""
put ""

for : 1 .. numans
    put answers (numans, 1), ",", answers (numans, 2), ",", answers (numans, 3)
end for

Author:  Tony [ Thu Dec 08, 2005 5:41 pm ]
Post subject: 

code:

            if sum = 100 then
                answers (numans, 1) := first
                answers (numans, 2) := second
                answers (numans, 3) := third
                numans += 1
put "something found"
            end if

Try it out. The sum is never actually 100 in your case.


: