Ludic numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: concat . map -> concatMap, (and dropped a couple of redundant $))
m (→‎{{header|REXX}}: changed output format, optimized the function to be about twice as fast.)
Line 2,889: Line 2,889:
say 'The first ' N " ludic numbers: " ludic(n) /*display title for what's coming next.*/
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 "The " bot '───►' top ' (inclusive) ludic numbers are: ' subword(ludic(top),bot)
$=ludic(triples); #=0; @=
say
say "The " bot ' to ' top " ludic numbers are: " ludic(bot,top)
$=ludic(-triples) 0 0; #=0; @=
say
say
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 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; @=@ '◄'_ _+2 _+6"► " /*bump the triple counter, and ··· */
end /*j*/ /* [↑] append the found triple ──► @ */
end /*j*/ /* [↑] append the found triple ──► @ */


Line 2,903: Line 2,902:
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,h; am=abs(m); if h\=='' then am=h; $=1 2; yes=m>0 | h\==''
ludic: procedure; parse arg m,,@; $=1 2 /*$≡ludic numbers superset; @≡sequence*/
@= /*$≡ludic numbers superset; @≡sequence*/
do j=3 by 2 to m*15 /*construct an initial list of numbers.*/
do j=3 by 2 to am*max(1, 15*yes) /*construct an initial list of numbers.*/
@=@ j /*append an odd number to the sequence.*/
@=@ j /* [↓] construct a ludic sequence. */
end /*j*/
end /*j*/ /* [↑] high limit: approx or exact. */
@=@' '; n=words(@) /*append a blank to the number sequence*/
@=@' ' /*append a blank to the number sequence*/
do while n\==0; f=word(@,1); $=$ f /*examine the first word in @; add to $*/
do while words(@)\==0; f=word(@,1) /* [↓] examine the first word. */
do d=1 by f while d<=n; n=n-1 /*use 1st number, elide all occurrances*/
$=$ f /*append this first word to the list. */
@=changestr(' 'word(@, d)" ", @, ' . ') /*crossout a number in @ */
do d=1 by f while d<=words(@) /*use 1st number, elide all occurrences*/
end /*d*/ /* [↑] done eliding the "1st" number. */
y=word(@,d) /*obtain the Yth word of @ string.*/
@=translate(@, , .) /*change dots to blanks; count numbers.*/
@=changestr(' 'y" ", @, ' . ') /*delete the number in the sequence. */
end /*d*/ /* [↑] done eliding the "1st" number. */
@=translate(@, , .) /*translate periods (dots) to blanks. */
end /*while*/ /* [↑] done eliding ludic numbers. */
end /*while*/ /* [↑] done eliding ludic numbers. */


if h=='' then return subword($, 1, am) /*return a range of ludic numbers. */
return subword($, 1, m) /*return a range of ludic numbers. */</lang>
return subword($, am, h-m+1) /*return a section of a range. */</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]].
<br><br>
<br><br>
Line 2,926: Line 2,921:
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


The 2000 ───► 2005 (inclusive) ludic numbers are: 21475 21481 21487 21493 21503 21511
There are 142 ludic numbers from 1───►1000 (inclusive).

The 2000 to 2005 ludic numbers are: 21475 21481 21487 21493 21503 21511


From 1──►249, 8 triples found: ◄1 3 7► ◄5 7 11► ◄11 13 17► ◄23 25 29► ◄41 43 47► ◄173 175 179► ◄221 223 227► ◄233 235 239►
From 1──►249, 8 triples found: ◄1 3 7► ◄5 7 11► ◄11 13 17► ◄23 25 29► ◄41 43 47► ◄173 175 179► ◄221 223 227► ◄233 235 239►