EKG sequence convergence: Difference between revisions
Content added Content deleted
(Ada version) |
(Added XPL0 example.) |
||
Line 1,478: | Line 1,478: | ||
EKG(5) and EKG(7) converge at term 21. |
EKG(5) and EKG(7) converge at term 21. |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
As can be seen, EKG(5) and EKG(7) converge at N = 21. |
|||
<lang XPL0>int N, A(1+30); |
|||
func Used; int M; \Return 'true' if M is in array A |
|||
int I; |
|||
[for I:= 1 to N-1 do |
|||
if M = A(I) then return true; |
|||
return false; |
|||
]; |
|||
func MinFactor; int Num; \Return minimum unused factor |
|||
int Fac, Val, Min; |
|||
[Fac:= 2; |
|||
Min:= -1>>1; |
|||
repeat if rem(Num/Fac) = 0 then \found a factor |
|||
[Val:= Fac; |
|||
loop [if Used(Val) then Val:= Val+Fac |
|||
else [if Val<Min then Min:= Val; |
|||
quit; |
|||
]; |
|||
]; |
|||
Num:= Num/Fac; |
|||
] |
|||
else Fac:= Fac+1; |
|||
until Fac > Num; |
|||
return Min; |
|||
]; |
|||
proc EKG; int M; \Calculate and show EKG sequence |
|||
[A(1):= 1; A(2):= M; |
|||
for N:= 3 to 30 do |
|||
A(N):= MinFactor(A(N-1)); |
|||
Format(2, 0); |
|||
Text(0, "EKG("); RlOut(0, float(M)); Text(0, "):"); |
|||
Format(3, 0); |
|||
for N:= 1 to 30 do |
|||
RlOut(0, float(A(N))); |
|||
CrLf(0); |
|||
]; |
|||
int Tbl, I; |
|||
[Tbl:= [2, 5, 7, 9, 10]; |
|||
for I:= 0 to 4 do EKG(Tbl(I)); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
EKG( 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 |
|||
EKG( 5): 1 5 10 2 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 |
|||
EKG( 7): 1 7 14 2 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 |
|||
EKG( 9): 1 9 3 6 2 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 |
|||
EKG(10): 1 10 2 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 |
|||
</pre> |
</pre> |
||