June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,30 +1,30 @@
|
|||
/*REXX program finds words with the largest set of anagrams (of the same size). */
|
||||
iFID= 'unixdict.txt' /*the dictionary input File IDentifier.*/
|
||||
$=; !.=; #.=0; w=0; uw=0; most=0 /*initialize a bunch of REXX variables.*/
|
||||
$=; !.=; ww=0; uw=0; most=0 /*initialize a bunch of REXX variables.*/
|
||||
/* [↓] read the entire file (by lines)*/
|
||||
do while lines(iFID)\==0 /*Got any data? Then read a record. */
|
||||
@=space( linein(iFID), 0) /*pick off a word from the input line. */
|
||||
L=length(@); if L<3 then iterate /*onesies and twosies words can't win. */
|
||||
if \datatype(@, 'M') then iterate /*ignore any non─anagramable words. */
|
||||
uw=uw+1 /*count of the (useable) words in file.*/
|
||||
z=sortA(@) /*sort the letters in the word. */
|
||||
!.z=!.z @; #.z=#.z+1 /*append it to !.z; bump the counter. */
|
||||
if #.z>most then do; $=z; most=#.z; if L>w then w=L; iterate; end
|
||||
if #.z==most then $=$ z /*append the sorted word──► max anagram*/
|
||||
do while lines(iFID) \== 0 /*Got any data? Then read a record. */
|
||||
parse value linein(iFID) with @ . /*obtain a word from an input line. */
|
||||
len=length(@); if len<3 then iterate /*onesies and twosies words can't win. */
|
||||
if \datatype(@, 'M') then iterate /*ignore any non─anagramable words. */
|
||||
uw=uw + 1 /*count of the (useable) words in file.*/
|
||||
_=sortA(@) /*sort the letters in the word. */
|
||||
!._=!._ @; #=words(!._) /*append it to !._; bump the counter. */
|
||||
if #==most then $=$ _ /*append the sorted word──► max anagram*/
|
||||
else if #>most then do; $=_; most=#; if len>ww then ww=len; end
|
||||
end /*while*/ /*$ ◄── list of high count anagrams. */
|
||||
say '─────────────────────────' uw "useable words in the dictionary file: " iFID
|
||||
say '─────────────────────────' uw "usable words in the dictionary file: " iFID
|
||||
say
|
||||
do m=1 for words($); z=subword($, m, 1) /*the high count of the anagrams. */
|
||||
say ' ' left(subword(!.z, 1, 1), w) ' [anagrams: ' subword(!.z, 2)"]"
|
||||
say ' ' left(word(!.z, 1), ww) ' [anagrams: ' subword(!.z, 2)"]"
|
||||
end /*m*/ /*W is the maximum width of any word.*/
|
||||
say
|
||||
say '───── Found' words($) "words (each of which have" #.z-1 'anagrams).'
|
||||
say '───── Found' words($) "words (each of which have" words(!.z)-1 'anagrams).'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
sortA: procedure; arg char +1 xx,@. /*get the first letter of arg; @.=null*/
|
||||
sortA: arg char 2 xx,@. /*get the first letter of arg; @.=null*/
|
||||
@.char=char /*no need to concatenate the first char*/
|
||||
/*[↓] sort/put letters alphabetically.*/
|
||||
do length(xx); parse var xx char +1 xx; @.char=@.char || char; end
|
||||
do length(xx); parse var xx char 2 xx; @.char=@.char || char; end
|
||||
/*reassemble word with sorted letters. */
|
||||
return @.a||@.b||@.c||@.d||@.e||@.f||@.g||@.h||@.i||@.j||@.k||@.l||@.m||,
|
||||
@.n||@.o||@.p||@.q||@.r||@.s||@.t||@.u||@.v||@.w||@.x||@.y||@.z
|
||||
return @.a || @.b || @.c || @.d || @.e || @.f||@.g||@.h||@.i||@.j||@.k||@.l||@.m||,
|
||||
@.n || @.o || @.p || @.q || @.r || @.s||@.t||@.u||@.v||@.w||@.x||@.y||@.z
|
||||
|
|
|
|||
|
|
@ -1,27 +1,30 @@
|
|||
/*REXX program finds words with the largest set of anagrams (of the same size). */
|
||||
iFID= 'unixdict.txt' /*the dictionary input File IDentifier.*/
|
||||
$=; !.=; #.=0; ww=0; uw=0; most=0 /*initialize a bunch of REXX variables.*/
|
||||
$=; !.=; ww=0; uw=0; most=0 /*initialize a bunch of REXX variables.*/
|
||||
/* [↓] read the entire file (by lines)*/
|
||||
do while lines(iFID)\==0 /*Got any data? Then read a record. */
|
||||
@=space( linein(iFID), 0) /*pick off a word from the input line. */
|
||||
LL=length(@); if LL<3 then iterate /*onesies and twosies (words) can't win*/
|
||||
if \datatype(@, 'M') then iterate /*ignore any non─anagramable words. */
|
||||
uw=uw+1 /*count of the (useable) words in file.*/
|
||||
parse upper var @ _ +1 xx @. /*get uppercase @ and nullify @. */
|
||||
@._=_ /*get the first letter (special case). */
|
||||
/*[↓] sort/put letters alphabetically.*/
|
||||
do LL-1; parse var xx _ +1 xx; @._=@._||_; end /*get the rest of the word.*/
|
||||
/*reassemble word with sorted letters. */
|
||||
zz=@.a||@.b||@.c||@.d||@.e||@.f||@.g||@.h||@.i||@.j||@.k||@.l||@.m||,
|
||||
@.n||@.o||@.p||@.q||@.r||@.s||@.t||@.u||@.v||@.w||@.x||@.y||@.z
|
||||
!.zz=!.zz @; #.zz=#.zz+1 /*append it to !.zz; bump the counter.*/
|
||||
if #.zz>most then do; $=zz; most=#.zz; if LL>ww then ww=LL; iterate; end
|
||||
if #.zz==most then $=$ zz /*append the sorted word──► $ anagrams.*/
|
||||
end /*while*/
|
||||
say '─────────────────────────' uw "useable words in the dictionary file: " iFID
|
||||
do while lines(iFID) \== 0 /*Got any data? Then read a record. */
|
||||
parse value linein(iFID) with @ . /*obtain a word from an input line. */
|
||||
len=length(@); if len<3 then iterate /*onesies and twosies words can't win. */
|
||||
if \datatype(@, 'M') then iterate /*ignore any non─anagramable words. */
|
||||
uw=uw + 1 /*count of the (useable) words in file.*/
|
||||
_=sortA(@) /*sort the letters in the word. */
|
||||
!._=!._ @; #=words(!._) /*append it to !._; bump the counter. */
|
||||
if #==most then $=$ _ /*append the sorted word──► max anagram*/
|
||||
else if #>most then do; $=_; most=#; if len>ww then ww=len; end
|
||||
end /*while*/ /*$ ◄── list of high count anagrams. */
|
||||
say '─────────────────────────' uw "usable words in the dictionary file: " iFID
|
||||
say
|
||||
do m=1 for words($); z=subword($,m,1) /*the high count of the anagrams. */
|
||||
say ' ' left(subword(!.z, 1, 1), ww) " [anagrams: " subword(!.z,2)"]"
|
||||
end /*m*/ /*WW is the maximum width of any word.*/
|
||||
say /*stick a fork in it, we're all done. */
|
||||
say '───── Found' words($) "words (each of which have" #.z-1 'anagrams).'
|
||||
do m=1 for words($); z=subword($, m, 1) /*the high count of the anagrams. */
|
||||
say ' ' left(word(!.z, 1), ww) ' [anagrams: ' subword(!.z, 2)"]"
|
||||
end /*m*/ /*W is the maximum width of any word.*/
|
||||
say
|
||||
say '───── Found' words($) "words (each of which have" words(!.z)-1 'anagrams).'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
sortA: arg char 2 xx,@. /*get the first letter of arg; @.=null*/
|
||||
@.char=char /*no need to concatenate the first char*/
|
||||
/*[↓] sort/put letters alphabetically.*/
|
||||
do length(xx); parse var xx char 2 xx; @.char=@.char || char; end
|
||||
/*reassemble word with sorted letters. */
|
||||
return @.a || @.b || @.c || @.d || @.e || @.f||@.g||@.h||@.i||@.j||@.k||@.l||@.m||,
|
||||
@.n || @.o || @.p || @.q || @.r || @.s||@.t||@.u||@.v||@.w||@.x||@.y||@.z
|
||||
|
|
|
|||
|
|
@ -1,27 +1,23 @@
|
|||
/*REXX program finds words with the largest set of anagrams (of the same size). */
|
||||
iFID= 'unixdict.txt' /*the dictionary input File IDentifier.*/
|
||||
$=; !.=; #.=0; ww=0; uw=0; most=0 /*initialize a bunch of REXX variables.*/
|
||||
/* [↓] read the entire file (by lines)*/
|
||||
do while lines(iFID)\==0 /*Got any data? Then read a record. */
|
||||
@=space( linein(iFID), 0) /*pick off a word from the input line. */
|
||||
LL=length(@); if LL<3 then iterate /*onesies and twosies (words) can't win*/
|
||||
if \datatype(@, 'M') then iterate /*ignore any non─anagramable words. */
|
||||
uw=uw+1 /*count of the (useable) words in file.*/
|
||||
parse upper var @ _ +1 xx . @. /*get uppercase @ and nullify @. */
|
||||
@._=_ /*get the first letter (special case). */
|
||||
/*[↓] sort/put letters alphabetically.*/
|
||||
do LL-1; parse var xx _ +1 xx; @._=@._ || _; end /*get rest of the word*/
|
||||
/*reassemble word with sorted letters. */
|
||||
zz=@.a|| @.b|| @.c|| @.d|| @.e|| @.f|| @.g|| @.h|| @.i|| @.j|| @.k|| @.l|| @.m ||,
|
||||
@.n|| @.o|| @.p|| @.q|| @.r|| @.s|| @.t|| @.u|| @.v|| @.w|| @.x|| @.y|| @.z
|
||||
!.zz=!.zz @; #.zz=#.zz+1 /*append it to !.zz; bump the counter.*/
|
||||
if #.zz>most then do; $=zz; most=#.zz; if LL>ww then ww=LL; iterate; end
|
||||
if #.zz==most then $=$ zz /*append the sorted word──► $ anagrams.*/
|
||||
end /*while*/
|
||||
say '─────────────────────────' uw 'useable words in the dictionary file: ' iFID
|
||||
say
|
||||
do m=1 for words($); z=subword($, m, 1) /*the high count of the anagrams. */
|
||||
say ' ' left(subword(!.z, 1, 1), ww) " [anagrams: " subword(!.z, 2)']'
|
||||
end /*m*/ /*WW is the maximum width of any word.*/
|
||||
say /*stick a fork in it, we're all done. */
|
||||
say '───── Found' words($) "words (each of which have" #.z-1 'anagrams).'
|
||||
u= 'Halloween' /*word to be sorted by (Latin) letter.*/
|
||||
upper u /*fast method to uppercase a variable. */
|
||||
/*another: u = translate(u) */
|
||||
/*another: parse upper var u u */
|
||||
/*another: u = upper(u) */
|
||||
/*not always available [↑] */
|
||||
say 'u=' u
|
||||
_.=
|
||||
do until u=='' /*keep truckin' until U is null. */
|
||||
parse var u y +1 u /*get the next (first) character in U.*/
|
||||
xx='?'y /*assign a prefixed character to XX. */
|
||||
_.xx=_.xx || y /*append it to all the Y characters. */
|
||||
end /*until*/ /*U now has the first character elided.*/
|
||||
/*Note: the variable U is destroyed.*/
|
||||
|
||||
/* [↓] constructs a sorted letter word*/
|
||||
|
||||
z=_.?a||_.?b||_.?c||_.?d||_.?e||_.?f||_.?g||_.?h||_.?i||_.?j||_.?k||_.?l||_.?m||,
|
||||
_.?n||_.?o||_.?p||_.?q||_.?r||_.?s||_.?t||_.?u||_.?v||_.?w||_.?x||_.?y||_.?z
|
||||
|
||||
/*Note: the ? is prefixed to the letter to avoid */
|
||||
/*collisions with other REXX one-character variables.*/
|
||||
say 'z=' z
|
||||
|
|
|
|||
|
|
@ -1,23 +1,18 @@
|
|||
u= 'Halloween' /*word to be sorted by (Latin) letter.*/
|
||||
upper u /*fast method to uppercase a variable. */
|
||||
/*another: u = translate(u) */
|
||||
/*another: parse upper var u u */
|
||||
/*another: u = upper(u) */
|
||||
/*not always available [↑] */
|
||||
L=length(u) /*get the length of the word (in bytes)*/
|
||||
say 'u=' u
|
||||
say 'L=' L
|
||||
_.=
|
||||
do until u=='' /*keep truckin' until U is null. */
|
||||
parse var u y +1 u /*get the next (first) character in U.*/
|
||||
do k=1 for L /*keep truckin' for L characters. */
|
||||
parse var u =(k) y +1 /*get the Kth character in U string.*/
|
||||
xx='?'y /*assign a prefixed character to XX. */
|
||||
_.xx=_.xx || y /*append it to all the Y characters. */
|
||||
end /*until*/ /*U now has the first character elided.*/
|
||||
/*Note: the variable U is destroyed.*/
|
||||
end /*do k*/ /*U now has the first character elided.*/
|
||||
|
||||
/* [↓] constructs a sorted letter word*/
|
||||
/* [↓] construct a sorted letter word.*/
|
||||
|
||||
z=_.?a||_.?b||_.?c||_.?d||_.?e||_.?f||_.?g||_.?h||_.?i||_.?j||_.?k||_.?l||_.?m||,
|
||||
_.?n||_.?o||_.?p||_.?q||_.?r||_.?s||_.?t||_.?u||_.?v||_.?w||_.?x||_.?y||_.?z
|
||||
|
||||
/*Note: the ? is prefixed to the letter to avoid */
|
||||
/*collisions with other REXX one-character variables.*/
|
||||
say 'z=' z
|
||||
|
|
|
|||
|
|
@ -1,18 +1,61 @@
|
|||
u= 'Halloween' /*word to be sorted by (Latin) letter.*/
|
||||
upper u /*fast method to uppercase a variable. */
|
||||
L=length(u) /*get the length of the word (in bytes)*/
|
||||
say 'u=' u
|
||||
say 'L=' L
|
||||
_.=
|
||||
do k=1 for L /*keep truckin' for L characters. */
|
||||
parse var u =(k) y +1 /*get the Kth character in U string.*/
|
||||
xx='?'y /*assign a prefixed character to XX. */
|
||||
_.xx=_.xx || y /*append it to all the Y characters. */
|
||||
end /*do k*/ /*U now has the first character elided.*/
|
||||
|
||||
/* [↓] construct a sorted letter word.*/
|
||||
|
||||
z=_.?a||_.?b||_.?c||_.?d||_.?e||_.?f||_.?g||_.?h||_.?i||_.?j||_.?k||_.?l||_.?m||,
|
||||
_.?n||_.?o||_.?p||_.?q||_.?r||_.?s||_.?t||_.?u||_.?v||_.?w||_.?x||_.?y||_.?z
|
||||
|
||||
say 'z=' z
|
||||
/*REXX program finds words with the largest set of anagrams (same size)
|
||||
* 07.08.2013 Walter Pachl
|
||||
* sorta for word compression courtesy Gerard Schildberger,
|
||||
* modified, however, to obey lowercase
|
||||
* 10.08.2013 Walter Pachl take care of mixed case dictionary
|
||||
* following Version 1's method
|
||||
**********************************************************************/
|
||||
Parse Value 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z',
|
||||
With a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
Call time 'R'
|
||||
ifid='unixdict.txt' /* input file identifier */
|
||||
words=0 /* number of usable words */
|
||||
maxl=0 /* maximum number of anagrams */
|
||||
wl.='' /* wl.ws words that have ws */
|
||||
Do ri=1 By 1 While lines(ifid)\==0 /* read each word in file */
|
||||
word=space(linein(ifid),0) /* pick off a word from the input.*/
|
||||
If length(word)<3 Then /* onesies and twosies can't win. */
|
||||
Iterate
|
||||
If\datatype(word,'M') Then /* not an anagramable word */
|
||||
Iterate
|
||||
words=words+1 /* count of (useable) words. */
|
||||
ws=sorta(word) /* sort the letters in the word. */
|
||||
wl.ws=wl.ws word /* add word to list of ws */
|
||||
wln=words(wl.ws) /* number of anagrams with ws */
|
||||
Select
|
||||
When wln>maxl Then Do /* a new maximum */
|
||||
maxl=wln /* use this */
|
||||
wsl=ws /* list of resulting ws values */
|
||||
End
|
||||
When wln=maxl Then /* same as the one found */
|
||||
wsl=wsl ws /* add ws to the list */
|
||||
Otherwise /* shorter */
|
||||
Nop /* not yet of interest */
|
||||
End
|
||||
End
|
||||
Say ' '
|
||||
Say copies('-',10) ri-1 'words in the dictionary file: ' ifid
|
||||
Say copies(' ',10) words 'thereof are anagram candidates'
|
||||
Say ' '
|
||||
Say 'There are' words(wsl) 'set(s) of anagrams with' maxl,
|
||||
'elements each:'
|
||||
Say ' '
|
||||
Do while wsl<>''
|
||||
Parse Var wsl ws wsl
|
||||
Say ' 'wl.ws
|
||||
End
|
||||
Say time('E')
|
||||
Exit
|
||||
sorta:
|
||||
/**********************************************************************
|
||||
* sort the characters in word_p (lowercase translated to uppercase)
|
||||
* 'chARa' -> 'AACHR'
|
||||
**********************************************************************/
|
||||
Parse Upper Arg word_p
|
||||
c.=''
|
||||
Do While word_p>''
|
||||
Parse Var word_p cc +1 word_p
|
||||
c.cc=c.cc||cc
|
||||
End
|
||||
Return c.a||c.b||c.c||c.d||c.e||c.f||c.g||c.h||c.i||c.j||c.k||c.l||,
|
||||
c.m||c.n||c.o||c.p||c.q||c.r||c.s||c.t||c.u||c.v||c.w||c.x||c.y||c.z
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue