Changeable words
In the list change one letter in word and if new word occur in list then display on this page.
Length of word > 11
REXX
<lang rexx>/*REXX program finds changable words (within an identified dict.), changing any letter.*/ parse arg minL iFID . /*obtain optional arguments from the CL*/ if minL== | minL=="," then minL= 12 /*Not specified? Then use the default.*/ if iFID== | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ @.= /*default value of any dictionary word.*/
do #=1 while lines(iFID)\==0 /*read each word in the file (word=X).*/ x= strip( linein( iFID) ) /*pick off a word from the input line. */ $.#= x; upper x; @.x= $.# /*save: original case. */ end /*#*/ /* [↑] semaphore name is uppercased. */
say copies('─', 30) # "words in the dictionary file: " iFID found= 0 /*count of the changable words found.*/ abc= 'etaoinshrdlcumwfgypbvkjxqz'; upper abc /*alphabet ordered by frequency of use.*/ Labc= length(abc) /*the length of the alphabet to be used*/
do j=1 for #-1; L= length($.j) /*process all the words that were found*/ if L<minL then iterate /*Is the word long enough? No, skip it*/ if \datatype($.j, 'M') then iterate /*verify that the word is all letters. */ x= $.j; upper x /*get an uppercased version of the word*/
do k=1 for L; _= substr(x, k, 1) /*y: the current letter being changed.*/ do c=1 for Labc /* [↓] change the _ letter to another.*/ ?= substr(abc, c, 1) /*get a new char to replace one in word*/ if ?==_ then iterate /*Is this the same char? Then use next*/ new= overlay(?, x, k) /*create a spanking new (changed) word.*/ newU= new; upper newU /*get an uppercase version of new word.*/ if @.newU== then iterate /*if the new word isn't a word, skip it*/ leave k /*we found a new word, stop searching.*/ end /*c*/ if k==L then iterate j /*No new word found? Then try another.*/ end /*k*/
found= found + 1 /*bump count of changable words found. */ say right(left($.j, 30), 40) @.newU /*indent original word for readability.*/ end /*j*/
say copies('─', 30) found ' changable words found with a minimum length of ' minL</lang>
- output when using the default inputs:
────────────────────────────── 25105 words in the dictionary file: unixdict.txt aristotelean aristotelian aristotelian aristotelean claustrophobia claustrophobic claustrophobic claustrophobia committeeman committeemen committeemen committeeman committeewoman committeewomen committeewomen committeewoman complementary complimentary complimentary complementary confirmation conformation conformation confirmation congresswoman congresswomen congresswomen congresswoman councilwoman councilwomen councilwomen councilwoman craftsperson draftsperson draftsperson craftsperson eavesdropped eavesdropper eavesdropper eavesdropped frontiersman frontiersmen frontiersmen frontiersman handicraftsman handicraftsmen handicraftsmen handicraftsman incommutable incomputable incomputable incommutable installation instillation instillation installation kaleidescope kaleidoscope kaleidoscope kaleidescope neuroanatomy neuroanotomy neuroanotomy neuroanatomy newspaperman newspapermen newspapermen newspaperman nonagenarian nonogenarian nonogenarian nonagenarian onomatopoeia onomatopoeic onomatopoeic onomatopoeia philanthrope philanthropy philanthropy philanthrope prescription proscription proscription prescription schizophrenia schizophrenic schizophrenic schizophrenia shakespearean shakespearian shakespearian shakespearean spectroscope spectroscopy spectroscopy spectroscope underclassman underclassmen underclassmen underclassman upperclassman upperclassmen upperclassmen upperclassman ────────────────────────────── 52 changable words found with a minimum length of 12
Ring
<lang ring> cStr = read("unixdict.txt") wordList = str2list(cStr) num = 0 oldWord = "abc"
ln = len(wordList) for n = ln to 1 step -1
if len(wordList[n]) < 12 del(wordList,n) ok
next
see "working..." + nl see "Changable words are:" + nl
for n = 1 to len(wordList)
len = len(wordList[n]) for m = 1 to len abcList = "abcdefghijklmnopqrstuvwxyz" for abc in abcList str1 = left(wordList[n],m-1) str2 = abc str3 = right(wordList[n],len-m) tempWord = str1 + str2 + str3 ind = find(wordList,tempWord) bool = (ind > 0) and (wordList[n][m] != abc) if bool = 1 and wordList[n] != oldWord num = num + 1 oldWord = tempWord see "" + num + ". " + wordList[n] + " >> " + tempWord + nl ok next next
next
see "done..." + nl </lang> Output:
working... Changable words are: 1. aristotelean >> aristotelian 2. claustrophobia >> claustrophobic 3. committeeman >> committeemen 4. committeewoman >> committeewomen 5. complementary >> complimentary 6. confirmation >> conformation 7. congresswoman >> congresswomen 8. councilwoman >> councilwomen 9. craftsperson >> draftsperson 10. eavesdropped >> eavesdropper 11. frontiersman >> frontiersmen 12. handicraftsman >> handicraftsmen 13. incommutable >> incomputable 14. installation >> instillation 15. kaleidescope >> kaleidoscope 16. neuroanatomy >> neuroanotomy 17. newspaperman >> newspapermen 18. nonagenarian >> nonogenarian 19. onomatopoeia >> onomatopoeic 20. philanthrope >> philanthropy 21. prescription >> proscription 22. schizophrenia >> schizophrenic 23. shakespearean >> shakespearian 24. spectroscope >> spectroscopy 25. underclassman >> underclassmen 26. upperclassman >> upperclassmen done...