Ludic numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments and whitespace.)
Line 3,319: Line 3,319:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program displays (a range of) ludic numbers, or a count of when a range is used.*/
<lang rexx>/*REXX program gens/shows (a range of) ludic numbers, or a count when a range is used.*/
parse arg N count bot top triples . /*obtain optional arguments from the CL*/
parse arg N count bot top triples . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N=25 /*Not specified? Then use the default.*/
if N=='' | N=="," then N= 25 /*Not specified? Then use the default.*/
if count=='' | count=="," then count=1000 /* " " " " " " */
if count=='' | count=="," then count= 1000 /* " " " " " " */
if bot=='' | bot=="," then bot=2000 /* " " " " " " */
if bot=='' | bot=="," then bot= 2000 /* " " " " " " */
if top=='' | top=="," then top=2005 /* " " " " " " */
if top=='' | top=="," then top= 2005 /* " " " " " " */
if triples=='' | triples=="," then triples=250-1 /* " " " " " " */
if triples=='' | triples=="," then triples= 249 /* " " " " " " */
$=ludic( max(N, count, bot, top, triples) ) /*generate enough ludic nums.*/
#= 0 /*the number of ludic numbers (so far).*/
say 'The first ' N " ludic numbers: " subword($,1,25) /*display 1st N ludic nums.*/
$= ludic( max(N, count, bot, top, triples) ) /*generate enough ludic nums*/
do j=1 until word($, j) > count; end /*process up to a specific #.*/
say 'The first ' N " ludic numbers: " subword($,1,25) /*display 1st N ludic nums*/
do j=1 until word($, j) > count /*search up to a specific #.*/
end /*j*/
say
say
say "There are " j-1 ' ludic numbers that are ≤ ' count
say "There are " j - 1 ' ludic numbers that are ≤ ' count
say
say
say "The " bot '───►' top ' (inclusive) ludic numbers are: ' subword($, bot)
say "The " bot '───►' top ' (inclusive) ludic numbers are: ' subword($, bot)
@= /*list of ludic triples found (so far).*/
#=0
@=; do j=1 for words($); _=word($,j) /*it is known that ludic _ exists. */
do j=1 for words($)
_= word($, j) /*it is known that ludic _ exists. */
if _>=triples then leave /*only process up to a specific number.*/
if _>=triples then leave /*only process up to a specific number.*/
if wordpos(_+2, $)==0 | wordpos(_+6, $)==0 then iterate /*Not triple? Skip it.*/
if wordpos(_+2, $)==0 | wordpos(_+6, $)==0 then iterate /*Not triple? Skip it.*/
#=#+1; @=@ '◄'_ _+2 _+6"► " /*bump the triple counter, and ··· */
#= # + 1 /*bump the triple counter. */
end /*j*/ /* [↑] append the found triple ──► @ */
@= @ '◄'_ _+2 _+6"► " /*append the newly found triple ──► @ */
end /*j*/
say
say
if @=='' then say 'From 1──►'triples", no triples found."
if @=='' then say 'From 1──►'triples", no triples found."
Line 3,344: Line 3,348:
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ludic: procedure; parse arg m,,@; $=1 2 /*$≡ludic numbers superset; @≡sequence*/
ludic: procedure; parse arg m,,@; $= 1 2 /*$≡ludic numbers superset; @≡sequence*/
do j=3 by 2 to m*15; @=@ j; end /*construct an initial list of numbers.*/
do j=3 by 2 to m*15; @= @ j /*construct an initial list of numbers.*/
end /*j*/
@=@' '; n=words(@) /*append a blank to the number sequence*/
do while n\==0; f=word(@,1); $=$ f /*examine the first word in @; add to $*/
@= @' '; n= words(@) /*append a blank to the number sequence*/
do d=1 by f while d<=n; n=n-1 /*use 1st number, elide all occurrences*/
do while n\==0; f= word(@, 1) /*examine the first word in the @ list.*/
@=changestr(' 'word(@, d)" ", @, ' . ') /*crossout a number in @ */
$= $ f /*add the word to the $ list. */
end /*d*/ /* [↑] done eliding the "1st" number. */
do d=1 by f while d<=n; n= n-1 /*use 1st number, elide all occurrences*/
@=translate(@, , .) /*change dots to blanks; count numbers.*/
@= changestr(' 'word(@, d)" ", @, ' . ') /*cross─out a number in @ */
end /*while*/ /* [↑] done eliding ludic numbers. */
end /*d*/ /* [↑] done eliding the "1st" number. */
@= translate(@, , .) /*change dots to blanks; count numbers.*/
end /*while*/ /* [↑] done eliding ludic numbers. */
return subword($, 1, m) /*return a range of ludic numbers. */</lang>
return subword($, 1, m) /*return a range of ludic numbers. */</lang>
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, &nbsp; so one is included here &nbsp; ──► &nbsp; [[CHANGESTR.REX]].
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, &nbsp; so one is included here &nbsp; ──► &nbsp; [[CHANGESTR.REX]].