Changeable words: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: elided a duplicate filter for the words, changed whitespace, moved an assignment statement.)
m (→‎{{header|REXX}}: moved the reading and filtering the dictionary to a subroutine.)
Line 863: Line 863:
if minL=='' | minL=="," then minL= 12 /*Not specified? Then use the default.*/
if minL=='' | minL=="," then minL= 12 /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
@.= /*default value of any dictionary word.*/
call readDict /*read & process/filter the dictionary.*/
wc= 0 /*WC: the word count of usable words.*/
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. */
if length(x)<minL then iterate /*Is the word too short? Then skip it.*/
if \datatype(x, 'M') then iterate /* " " " not alphabetic? Skip it.*/
wc= wc+1; $.wc= x; upper x; @.x= $.wc /*bump word counter; save original case*/
end /*#*/ /* [↑] semaphore name is uppercased. */

say copies('─', 30) # "words ("wc 'usable words) in the dictionary file: ' iFID
abc= 'abcdefghijklmnopqrstuvwxyz'; upper abc /*alphabet ordered by frequency of use.*/
abc= 'abcdefghijklmnopqrstuvwxyz'; upper abc /*alphabet ordered by frequency of use.*/
Labc= length(abc) /*the length of the alphabet to be used*/
Labc= length(abc) /*the length of the alphabet to be used*/
finds= 0 /*count of the changeable words found.*/
finds= 0 /*count of the changeable words found.*/
do j=1 for wc; L= length($.j) /*process all the words that were found*/
do j=1 for n; L= length($.j) /*process all the words that were found*/
x= $.j; upper x /*get an uppercased version of the word*/
x= $.j; upper x /*get an uppercased version of the word*/

pad= left('', 9) /*PAD: used for indenting the output.*/
do k=1 for L; y= substr(x, k, 1) /*Y: the current letter being changed.*/
do k=1 for L; y= substr(x, k, 1) /*Y: the current letter being changed.*/
do c=1 for Labc /* [↓] change the Y letter to another.*/
do c=1 for Labc /* [↓] change the Y letter to another.*/
?= substr(abc, c, 1) /*get a new char to replace one in word*/
?= substr(abc, c, 1) /*get a new char to replace one in word*/
if ?==y then iterate /*Is this the same char? Then use next*/
if ?==y then iterate /*Is this the same char? Then use next*/
new= overlay(?, x, k); upper new /*create a spanking new (changed) word.*/
new= overlay(?, x, k); upper new /*create a spanking new (changed) word.*/
if @.new=='' then iterate /*if the new word isn't a word, skip it*/
if @.new=='' then iterate /*New word not in dictionary? Skip it.*/
finds= finds + 1 /*bump count of changeable words found.*/
finds= finds + 1 /*bump count of changeable words found.*/
say pad left($.j, 30) @.new /*indent original word for readability.*/
say right(left($.j, 30), 40) @.new /*indent original word for readability.*/
end /*c*/
end /*c*/
end /*k*/
end /*k*/
end /*j*/
end /*j*/
say copies('─', 30) finds ' changeable words found with a minimum length of ' minL</lang>
say copies('─', 30) finds ' changeable words found with a minimum length of ' minL
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
readDict: n=0; @.= /*N: the word count of usable words. */
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. */
if length(x)<minL then iterate /*Is the word too short? Then skip it.*/
if \datatype(x, 'M') then iterate /* " " " not alphabetic? Skip it.*/
n= n + 1; $.n= x; /*bump the word counter; assign to $. */
upper x; @.x= $.n /*assign uppercased word ───► array. */
end /*#*/ /* [↑] semaphore name is uppercased. */
say copies('─', 30) # "words ("n 'usable words) in the dictionary file: ' iFID
return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>