DSJ
October 15th, 2001, 03:24 PM
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!
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!