Yellowstone sequence: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added a REXX stub.) |
(→{{header|REXX}}: added the REXX computer programming language for this task.) |
||
Line 71: | Line 71: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program calculates and displays any number of terms in the Yellowstone sequence. */ |
|||
parse arg m . /*obtain optional argument from the CL.*/ |
|||
if m=='' | m=="," then m= 30 /*Not specified? Then use the default.*/ |
|||
!.= 0 /*initialize an array of numbers(used).*/ |
|||
# = 0 /*count of Yellowstone numbers in seq. */ |
|||
$= /*list " " " " " */ |
|||
do j=1 until #==m; prev= # - 1 |
|||
if j<5 then do; #= #+1; @.#= j; !.#= j; !.j= 1; $= strip($ j); iterate; end |
|||
do k=1; if !.k then iterate /*Already used? Then skip this number.*/ |
|||
if gcd(k, @.#)==1 & gcd(k, @.prev)>1 then nop |
|||
else iterate |
|||
#= #+1; @.#= k; !.k= 1; $= $ k /*bump ctr; assign; mark used; add list*/ |
|||
leave /*go find the next Yellowstone number. */ |
|||
end /*k*/ |
|||
end /*j*/ |
|||
say $ |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
gcd: parse arg x,y; do until y==0; parse value x//y y with y x; end; return x</lang> |
|||
{{out|output|text= when using the default input:}} |
|||
<pre> |
|||
1 2 3 4 9 8 15 14 5 6 25 12 35 16 7 10 21 20 27 22 39 11 13 33 26 45 28 51 32 17 |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |