If each letter has a value (a=1, b=2, c=3 etc.) what words have a total letter value of exactly 100 when you add up all of the letters?
Are there any words that equal 100 if the letter values are swapped (z=1, y=2.....a=26)?
This program, given a word list (it's set up for bogwords.txt) finds matching words under each criterion:
OPEN "bogwords.txt" FOR INPUT AS #1
OPEN "wval100a.txt" FOR OUTPUT AS #2
OPEN "wval100b.txt" FOR OUTPUT AS #3
DO
LINE INPUT #1, w$
w$ = LCASE$(w$)
t1 = 0: t2 = 0
FOR i = 1 TO LEN(w$)
v1 = ASC(MID$(w$, i, 1)) - ASC("a") + 1
v2 = 27 - v1
t1 = t1 + v1: t2 = t2 + v2
NEXT
IF t1 = 100 AND t2 = 100 THEN PRINT w$
IF t1 = 100 THEN PRINT #2, w$
IF t2 = 100 THEN PRINT #3, w$
LOOP UNTIL EOF(1)
|
Posted by Charlie
on 2003-07-17 11:44:52 |