Changeable words: Difference between revisions
(add freebasic) |
|||
Line 236:
wordList = str2list(cStr)
num = 0
ln = len(wordList)
Line 259 ⟶ 258:
ind = find(wordList,tempWord)
bool = (ind > 0) and (wordList[n][m] != abc)
if bool = 1
num = num + 1
see "" + num + ". " + wordList[n] + " >> " + tempWord + nl
ok
Line 275 ⟶ 273:
Changable words are:
1. aristotelean >> aristotelian
2. aristotelian >> aristotelean
4. claustrophobic >> claustrophobia
4. committeewoman >> committeewomen▼
5.
6.
8. committeewomen >> committeewoman
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27. installation >> instillation
28. instillation >> installation
29. kaleidescope >> kaleidoscope
30. kaleidoscope >> kaleidescope
31. neuroanatomy >> neuroanotomy
32. neuroanotomy >> neuroanatomy
33. newspaperman >> newspapermen
34. newspapermen >> newspaperman
35. nonagenarian >> nonogenarian
36. nonogenarian >> nonagenarian
37. onomatopoeia >> onomatopoeic
38. onomatopoeic >> onomatopoeia
39. philanthrope >> philanthropy
40. philanthropy >> philanthrope
41. prescription >> proscription
42. proscription >> prescription
43. schizophrenia >> schizophrenic
44. schizophrenic >> schizophrenia
45. shakespearean >> shakespearian
46. shakespearian >> shakespearean
47. spectroscope >> spectroscopy
48. spectroscopy >> spectroscope
49. underclassman >> underclassmen
50. underclassmen >> underclassman
51. upperclassman >> upperclassmen
52. upperclassmen >> upperclassman
done...
</pre>
|
Revision as of 06:44, 6 December 2020
- Task
Using the dictionary unixdict.txt, change one letter in a word, and if the changed word occurs in the dictionary,
then display the original word and the changed word here (on this page).
The length of any word shown should have a length > 11 .
Note: changable can also be spelled changeable.
- Metrics
- Counting
- Word frequency
- Letter frequency
- Jewels and stones
- I before E except after C
- Bioinformatics/base count
- Count occurrences of a substring
- Count how many vowels and consonants occur in a string
- Remove/replace
- XXXX redacted
- Conjugate a Latin verb
- Remove vowels from a string
- String interpolation (included)
- Strip block comments
- Strip comments from a string
- Strip a set of characters from a string
- Strip whitespace from a string -- top and tail
- Strip control codes and extended characters from a string
- Anagrams/Derangements/shuffling
- Word wheel
- ABC problem
- Sattolo cycle
- Knuth shuffle
- Ordered words
- Superpermutation minimisation
- Textonyms (using a phone text pad)
- Anagrams
- Anagrams/Deranged anagrams
- Permutations/Derangements
- Find/Search/Determine
- ABC words
- Odd words
- Word ladder
- Semordnilap
- Word search
- Wordiff (game)
- String matching
- Tea cup rim text
- Alternade words
- Changeable words
- State name puzzle
- String comparison
- Unique characters
- Unique characters in each string
- Extract file extension
- Levenshtein distance
- Palindrome detection
- Common list elements
- Longest common suffix
- Longest common prefix
- Compare a list of strings
- Longest common substring
- Find common directory path
- Words from neighbour ones
- Change e letters to i in words
- Non-continuous subsequences
- Longest common subsequence
- Longest palindromic substrings
- Longest increasing subsequence
- Words containing "the" substring
- Sum of the digits of n is substring of n
- Determine if a string is numeric
- Determine if a string is collapsible
- Determine if a string is squeezable
- Determine if a string has all unique characters
- Determine if a string has all the same characters
- Longest substrings without repeating characters
- Find words which contains all the vowels
- Find words which contains most consonants
- Find words which contains more than 3 vowels
- Find words which first and last three letters are equals
- Find words which odd letters are consonants and even letters are vowels or vice_versa
- Formatting
- Substring
- Rep-string
- Word wrap
- String case
- Align columns
- Literals/String
- Repeat a string
- Brace expansion
- Brace expansion using ranges
- Reverse a string
- Phrase reversals
- Comma quibbling
- Special characters
- String concatenation
- Substring/Top and tail
- Commatizing numbers
- Reverse words in a string
- Suffixation of decimal numbers
- Long literals, with continuations
- Numerical and alphabetical suffixes
- Abbreviations, easy
- Abbreviations, simple
- Abbreviations, automatic
- Song lyrics/poems/Mad Libs/phrases
- Mad Libs
- Magic 8-ball
- 99 Bottles of Beer
- The Name Game (a song)
- The Old lady swallowed a fly
- The Twelve Days of Christmas
- Tokenize
- Text between
- Tokenize a string
- Word break problem
- Tokenize a string with escaping
- Split a character string based on change of character
- Sequences
FreeBASIC
Brute force method, reuses some code from Odd_words#FreeBASIC. <lang freebasic>
- define NULL 0
type node
word as string*32 'enough space to store any word in the dictionary nxt as node ptr
end type
function addword( tail as node ptr, word as string ) as node ptr
'allocates memory for a new node, links the previous tail to it, 'and returns the address of the new node dim as node ptr newnode = allocate(sizeof(node)) tail->nxt = newnode newnode->nxt = NULL newnode->word = word return newnode
end function
function length( word as string ) as uinteger
'necessary replacement for the built-in len function, which in this 'case would always return 32 for i as uinteger = 1 to 32 if asc(mid(word,i,1)) = 0 then return i-1 next i return 999
end function
dim as string word dim as node ptr tail = allocate( sizeof(node) ) dim as node ptr head = tail, curr = head, currj tail->nxt = NULL tail->word = "XXXXHEADER"
open "unixdict.txt" for input as #1 while true
line input #1, word if word = "" then exit while if length(word)>11 then tail = addword( tail, word )
wend close #1
dim as string tempword
while curr->nxt <> NULL
for i as uinteger = 1 to length(curr->word) for j as uinteger = 97 to 122 if j = asc(mid(curr->word,i,1)) then continue for tempword = left(curr->word,i-1)+ chr(j) + mid(curr->word, i+1, length(curr->word)-i) currj = head while currj->nxt <> NULL if tempword = currj->word then print left(curr->word,length(curr->word));" ---> ";tempword currj = currj->nxt wend next j next i curr = curr->nxt
wend</lang>
- Output:
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
REXX
This REXX version doesn't care what order the words in the dictionary are in, nor does it care what
case (lower/upper/mixed) the words are in, the search for alternades is caseless.
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
Programming note: the alphabet (used to changed any letter) is ordered by the highest frequency of use.
<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
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 num = num + 1 see "" + num + ". " + wordList[n] + " >> " + tempWord + nl ok next next
next
see "done..." + nl </lang> Output:
working... Changable words are: 1. aristotelean >> aristotelian 2. aristotelian >> aristotelean 3. claustrophobia >> claustrophobic 4. claustrophobic >> claustrophobia 5. committeeman >> committeemen 6. committeemen >> committeeman 7. committeewoman >> committeewomen 8. committeewomen >> committeewoman 9. complementary >> complimentary 10. complimentary >> complementary 11. confirmation >> conformation 12. conformation >> confirmation 13. congresswoman >> congresswomen 14. congresswomen >> congresswoman 15. councilwoman >> councilwomen 16. councilwomen >> councilwoman 17. craftsperson >> draftsperson 18. draftsperson >> craftsperson 19. eavesdropped >> eavesdropper 20. eavesdropper >> eavesdropped 21. frontiersman >> frontiersmen 22. frontiersmen >> frontiersman 23. handicraftsman >> handicraftsmen 24. handicraftsmen >> handicraftsman 25. incommutable >> incomputable 26. incomputable >> incommutable 27. installation >> instillation 28. instillation >> installation 29. kaleidescope >> kaleidoscope 30. kaleidoscope >> kaleidescope 31. neuroanatomy >> neuroanotomy 32. neuroanotomy >> neuroanatomy 33. newspaperman >> newspapermen 34. newspapermen >> newspaperman 35. nonagenarian >> nonogenarian 36. nonogenarian >> nonagenarian 37. onomatopoeia >> onomatopoeic 38. onomatopoeic >> onomatopoeia 39. philanthrope >> philanthropy 40. philanthropy >> philanthrope 41. prescription >> proscription 42. proscription >> prescription 43. schizophrenia >> schizophrenic 44. schizophrenic >> schizophrenia 45. shakespearean >> shakespearian 46. shakespearian >> shakespearean 47. spectroscope >> spectroscopy 48. spectroscopy >> spectroscope 49. underclassman >> underclassmen 50. underclassmen >> underclassman 51. upperclassman >> upperclassmen 52. upperclassmen >> upperclassman done...