EKG sequence convergence: Difference between revisions
Content deleted Content added
m added templates and whitespace to the task preamble. |
→{{header|REXX}}: added the REXX computer programming language. |
||
Line 412: | Line 412: | ||
(21, [13, 17, 19, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]), |
(21, [13, 17, 19, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]), |
||
(24, [13, 17, 19, 23, 25, 26, 27, 28, 29, 30, 31, 32])]</pre> |
(24, [13, 17, 19, 23, 25, 26, 27, 28, 29, 30, 31, 32])]</pre> |
||
=={{header|REXX}}== |
|||
<lang rexx>/*REXX program can generate and display several EKG sequences (with various starts).*/ |
|||
parse arg nums start /*obtain optional argumenst from the CL*/ |
|||
if nums=='' | nums=="," then nums= 30 /*Not specified? Then use the default.*/ |
|||
if start= '' | start= "," then start=2 5 7 9 10 /* " " " " " " */ |
|||
do s=1 for words(start); $= /*step through the specified STARTs. */ |
|||
second= word(start, s); say /*obtain the second interger in the seq*/ |
|||
do j=1 for nums |
|||
if j<3 then do; #=1; if j==2 then #=second; end /*handle 1st & 2nd number*/ |
|||
else #= ekg(#) |
|||
$= $ # /*append the EKG integer to the $ list.*/ |
|||
end /*j*/ |
|||
say '(start' second"):" $ /*display the EKG sequence to terminal.*/ |
|||
end /*s*/ |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
add_: do while z//j == 0; z=z%j; _=_ j; w=w+1; end; return strip(_) |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
ekg: procedure expose $; parse arg x 1 z,,_ |
|||
w=0 /*W: number of factors.*/ |
|||
do k=1 to 11 by 2; j=k; if j==1 then j=2 /*divide by low primes. */ |
|||
if j==9 then iterate; call add_ /*skip ÷ 9; add to list.*/ |
|||
end /*k*/ |
|||
/* [↓] skips mult. of 3*/ |
|||
do y=0 by 2; j= j + 2 + y//4 /*increment J by 2 or 4.*/ |
|||
parse var j '' -1 r; if r==5 then iterate /*divisible by five ? */ |
|||
if j*j>x | j>z then leave /*passed the sqrt(x) ? */ |
|||
_= add_() /*add a factor to list. */ |
|||
end /*y*/ |
|||
j=z; if z\==1 then _= add_() /*Z¬=1? Then add──►list.*/ |
|||
if _='' then _=x /*Null? Then use prime. */ |
|||
do j=3; done=1 |
|||
do k=1 for w |
|||
if j // word(_, k)==0 then do; done=0; leave; end |
|||
end /*k*/ |
|||
if done then iterate |
|||
if wordpos(j, $)==0 then return j /*return an EKG integer.*/ |
|||
end /*j*/</lang> |
|||
{{out|output|text= when using the default inputs:}} |
|||
<pre> |
|||
(start 2): 1 2 4 6 3 9 12 8 10 5 15 18 14 7 21 24 16 20 22 11 33 27 30 25 35 28 26 13 39 36 |
|||
(start 5): 1 5 10 4 6 3 9 12 8 14 7 21 15 18 16 20 22 11 33 24 26 13 39 27 30 25 35 28 32 34 |
|||
(start 7): 1 7 14 4 6 3 9 12 8 10 5 15 18 16 20 22 11 33 21 24 26 13 39 27 30 25 35 28 32 34 |
|||
(start 9): 1 9 3 6 4 8 10 5 15 12 14 7 21 18 16 20 22 11 33 24 26 13 39 27 30 25 35 28 32 34 |
|||
(start 10): 1 10 4 6 3 9 12 8 14 7 21 15 5 20 16 18 22 11 33 24 26 13 39 27 30 25 35 28 32 34 |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |