|
-
October 15th, 2001, 03:24 PM
#1
Logic Problem
A friend of mine's son had a home work problem as follows:
Each letter of the alphabet is assigned a value based on it's position in the alphabet, such that A=1, B=2, C=3, D=4, etc.
The assignment was to find as many words as he could given certian criteria based on the number of letters in the word and the sum of it's letters. For example, how many 4 letter words would add up to a "score" of 20. (for example, "able" = 1+2+12+5 = 20)
I though, hum... why sit around and "guess" all night... I could just write a program that takes the length of the word and the score value as parameters and spits out all letter combinations that satisfy the criteria, then it'd just be a matter of picking out real words out of the result.
What I came up with worked, but was a real mess. It consisted of a 26 case Select Case statement and 26 nested For... Next loops.
Just for fun, can anyone come up with anything cleaner? Probably have to use recurssion...?
I'd be interested to see what you come up with!
-
October 15th, 2001, 10:55 PM
#2
Re: Logic Problem
get all words ( say from a database);
Filter all 4 letter words, convert to upper case & fill an array (say about 10000 elements)
- the above could be done by Len function for Strings
Get the Ascii value of each letter and deduct 64 (or the number which makes the value 1 for A, 2 For B and so on) and add the 4 Ascii values in a loop and check whether the value = 20
If so put that to another array
Srinika
If u don't know how to Rate an answer, then Rate my answer to learn, If u know, then practice it 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|