Ludic numbers: Difference between revisions
Content added Content deleted
m (added whitespace before the TOC (table of contents), used a constant uncapitalized spelling of ludic.) |
m (→{{header|REXX}}: added/changed comments and whitespace, changed indentations.) |
||
Line 2,120: | Line 2,120: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program displays (a range of) ludic numbers, or a count of when a range is used.*/ |
||
parse arg N count bot top triples . /*obtain optional |
parse arg N count bot top triples . /*obtain optional arguments from the CL*/ |
||
if N=='' then N=25 /*Not specified? |
if N=='' then N=25 /*Not specified? Then use the default.*/ |
||
if count=='' then count=1000 /* " " " " " */ |
if count=='' then count=1000 /* " " " " " " */ |
||
if bot=='' then bot=2000 /* " " " " " */ |
if bot=='' then bot=2000 /* " " " " " " */ |
||
if top=='' then top=2005 /* " " " " " */ |
if top=='' then top=2005 /* " " " " " " */ |
||
if triples=='' then triples=250-1 /* " " " " " */ |
if triples=='' then triples=250-1 /* " " " " " " */ |
||
say 'The first ' |
say 'The first ' N " ludic numbers: " ludic(n) /*display title for what's coming next.*/ |
||
say |
say |
||
say "There are " words(ludic(-count)) ' ludic numbers from 1───►'count " (inclusive)." |
say "There are " words(ludic(-count)) ' ludic numbers from 1───►'count " (inclusive)." |
||
say |
say |
||
say "The " bot ' to ' top " ludic numbers are: " ludic(bot,top) |
say "The " bot ' to ' top " ludic numbers are: " ludic(bot,top) |
||
Line 2,136: | Line 2,136: | ||
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 wordpos(_+2,$)==0 | wordpos(_+6,$)==0 then iterate /*¬triple.*/ |
if wordpos(_+2,$)==0 | wordpos(_+6,$)==0 then iterate /*¬triple.*/ |
||
#=#+1; @=@ '◄'_ _+2 _+6"► " /*bump triple counter, and ··· */ |
#=#+1; @=@ '◄'_ _+2 _+6"► " /*bump triple counter, and ··· */ |
||
end /*j*/ /* [↑] append found triple ──► @*/ |
end /*j*/ /* [↑] append the found triple ──► @ */ |
||
if @=='' then say 'From 1──►'triples", no triples found." |
if @=='' then say 'From 1──►'triples", no triples found." |
||
else say 'From 1──►'triples", " # ' triples found:' @ |
else say 'From 1──►'triples", " # ' triples found:' @ |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
/*──────────────────────────────────LUDIC subroutine────────────────────*/ |
|||
ludic: procedure; parse arg m 1 mm,h; am=abs(m); if h\=='' then am=h |
ludic: procedure; parse arg m 1 mm,h; am=abs(m); if h\=='' then am=h |
||
$=1 2; @= /*$ |
$=1 2; @= /*$≡ludic numbers superset; @≡sequence*/ |
||
do j=3 by 2 to am * max(1, 15 * ((m>0) | h\=='') ) |
|||
@=@ j /* [↓] construct a ludic sequence. */ |
|||
do j=3 by 2 to am * max(1,15*((m>0)|h\=='')); @=@ j; end; @=@' ' |
|||
/* [↑] high limit: approx |
end /*j*/ /* [↑] high limit: approx or exact. */ |
||
@=@' ' /*append a blank to the number sequence*/ |
|||
do while words(@)\==0 /* [↓] examine the first word. */ |
|||
f=word(@,1); $=$ f /*append this first word to the list. */ |
|||
do d=1 by f while d<=words(@) /*use 1st number, elide all occurances */ |
|||
@=changestr(' 'word(@,d)" ",@, ' . ') /*delete the number in the sequence. */ |
|||
end /*d*/ /* [↑] done eliding "1st" number*/ |
|||
end /*d*/ /* [↑] done eliding the "1st" number. */ |
|||
@=translate(@, , .) /*translate periods (dots) to blanks. */ |
|||
end /*while*/ /* [↑] done eliding ludic numbers. */ |
|||
@=space(@) /*remove extra blanks from the list. */ |
|||
if h=='' then return subword($,1,am) /*return a range of ludic numbers*/ |
|||
if h=='' then return subword($,1,am) /*return a range of ludic numbers. */ |
|||
return subword($,m,h-m+1) /*return a section of a range. */</lang> |
|||
Some older REXXes don't have a '''changestr''' |
Some older REXXes don't have a '''changestr''' BIF, so one is included here ──► [[CHANGESTR.REX]]. |
||
<br><br> |
<br><br> |
||
'''output''' using the |
'''output''' using the default values for input: |
||
<pre> |
<pre> |
||
The first 25 ludic numbers: 1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107 |
The first 25 ludic numbers: 1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107 |