Odd words: Difference between revisions
Content added Content deleted
(Added Go) |
(→{{header|REXX}}: added a caseless version for REXX.) |
||
Line 252: | Line 252: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
=== version 1 === |
|||
<lang rwxx>/* REXX */ |
<lang rwxx>/* REXX */ |
||
fid='d:\unix.txt' |
fid='d:\unix.txt' |
||
Line 299: | Line 300: | ||
13 supervene spree |
13 supervene spree |
||
14 terminable trial</pre> |
14 terminable trial</pre> |
||
=== version 2, caseless === |
|||
This REXX version doesn't care what order the words in the dictionary are in, nor does it care what |
|||
<br>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. |
|||
<lang rexx>/*REXX program finds all the caseless "odd words" (within an identified dictionary). */ |
|||
parse arg minL iFID . /*obtain optional arguments from the CL*/ |
|||
if minL=='' | minL=="," then minL= 5 /*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 and the semaphore*/ |
|||
end /*#*/ /* [↑] semaphore name is uppercased. */ |
|||
minW= minL * 2 - 1 /*minimum width of a word to be usable.*/ |
|||
say copies('─', 30) # "words in the dictionary file: " iFID |
|||
ows= 0 /*count of the "odd words" found. */ |
|||
do j=1 for #-1; L= length($.j) /*process all the words that were found*/ |
|||
if L<minW then iterate /*Is word too short? Then ignore it. */ |
|||
ow= /*initialize the "odd word". */ |
|||
do k=1 by 2 to L /*only use odd indexed letters in word.*/ |
|||
ow= ow || substr($.j, k, 1) /*construct the "odd word". */ |
|||
end /*k*/ |
|||
owU= ow; upper owU /*uppercase the odd word to be caseless*/ |
|||
if @.owU=='' then iterate /*if not extant, then skip this word. */ |
|||
ows= ows + 1 /*bump the count of "odd words" found. */ |
|||
say right(left($.j, 20), 24) left(ow, 9) /*indent original word for readability.*/ |
|||
end /*j*/ |
|||
say copies('─', 30) ows ' "odd words" found with a minimum length of ' minL</lang> |
|||
{{out|output|text= when using the default input:}} |
|||
<pre> |
|||
────────────────────────────── 25105 words in the dictionary file: unixdict.txt |
|||
barbarian brain |
|||
childbear cider |
|||
corrigenda cried |
|||
gargantuan grata |
|||
headdress hades |
|||
palladian plain |
|||
propionate point |
|||
salvation slain |
|||
siltation slain |
|||
slingshot sight |
|||
statuette saute |
|||
supersede spree |
|||
supervene spree |
|||
terminable trial |
|||
────────────────────────────── 14 "odd words" found with a minimum length of 5 |
|||
</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |