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' /* " " " " " " */ |
||
call readDict /*read & process/filter the dictionary.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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 |
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*/ |
||
⚫ | |||
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 |
new= overlay(?, x, k); upper new /*create a spanking new (changed) word.*/ |
||
if @.new=='' then iterate /* |
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 |
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 |
say copies('─', 30) finds ' changeable words found with a minimum length of ' minL |
||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
upper x; @.x= $.n /*assign uppercased word ───► array. */ |
|||
⚫ | |||
⚫ | |||
return</lang> |
|||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |