Ludic numbers: Difference between revisions

m
→‎{{header|REXX}}: changed output format, optimized the function to be about twice as fast.
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:
say 'The first ' N " ludic numbers: " ludic(n) /*display title for what's coming next.*/
say
say "There areThe " words(ludic(-count))bot '───►' top ' (inclusive) ludic numbers fromare: 1───►'count " subword(inclusiveludic(top),bot)."
$=ludic(-triples); 0 0; #=0; @=
say
say "The " bot ' to ' top " ludic numbers are: " ludic(bot,top)
$=ludic(-triples) 0 0; #=0; @=
say
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.*/
#=#+1; @=@ '◄'_ _+2 _+6"► " /*bump the triple counter, and ··· */
end /*j*/ /* [↑] append the found triple ──► @ */
 
Line 2,903 ⟶ 2,902:
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 numbers superset; @≡sequence*/
@= do j=3 by 2 to m*15 /*construct an initial list /*$≡ludicof numbers superset; @≡sequence.*/
do@=@ j=3 by 2 to am*max(1, 15*yes) /*constructappend an initialodd listnumber to ofthe numberssequence.*/
@=@ j end /* [↓] construct a ludic sequence. j*/
@=@' '; end /*j*/ n=words(@) /*append [↑] high limit: a approxblank orto exact.the number sequence*/
@=@' ' do while n\==0; f=word(@,1); $=$ f /*examine the first word in @; /*append a blankadd to the number sequence$*/
do while words(@)\==0; f=word(@,1) /*do [↓]d=1 examineby thef first word.while d<=n; n=n-1 /*use 1st number, elide all occurrances*/
$=$ f @=changestr(' 'word(@, d)" ", @, ' . ') /*appendcrossout thisa firstnumber wordin to the list. @ */
do end /*d=1*/ by f while d<=words(@) /*use 1st[↑] number, elidedone alleliding the "1st" number. occurrences*/
y@=wordtranslate(@,d) , .) /*obtainchange thedots to Yth word of @blanks; count stringnumbers.*/
@=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. */
 
if h=='' then return subword($, 1, amm) /*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]].
<br><br>
Line 2,926 ⟶ 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 2000 ───► to2005 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►