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 " |
say "The " bot '───►' top ' (inclusive) ludic numbers are: ' subword(ludic(top),bot) |
||
⚫ | |||
say |
|||
say "The " bot ' to ' top " ludic numbers are: " ludic(bot,top) |
|||
⚫ | |||
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"► " |
#=#+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, |
ludic: procedure; parse arg m,,@; $=1 2 /*$≡ludic numbers superset; @≡sequence*/ |
||
do j=3 by 2 to m*15 /*construct an initial list of numbers.*/ |
|||
@=@ j /*append an odd number to the sequence.*/ |
|||
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 $*/ |
|||
do d=1 by f while d<=n; n=n-1 /*use 1st number, elide all occurrances*/ |
|||
@=changestr(' 'word(@, d)" ", @, ' . ') /*crossout a number in @ */ |
|||
end /*d*/ /* [↑] done eliding the "1st" number. */ |
|||
@=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. */ |
||
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 '''changestr''' BIF, so one is included here ──► [[CHANGESTR.REX]]. |
Some older REXXes don't have a '''changestr''' BIF, so one is included here ──► [[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 |
||
⚫ | |||
There are 142 ludic numbers from 1───►1000 (inclusive). |
|||
⚫ | |||
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► |