RosettaCodeData/Task/Yellowstone-sequence/Agena/yellowstone-sequence.agena
2026-02-01 16:33:20 -08:00

27 lines
970 B
Text

scope # Yellowstone sequence - translation of the Pluto sample
local proc yellowstone( n :: number ) :: table
local a, m := [ 1, 2, 3 ], [ true, true, true ];
for x from 4 to n do
a[ x ], m[ x ] := 0, false
od;
local minV := 4;
for c from 4 to n do
local more := true
for i from minV while more do
if not m[ i ] and numtheory.gcd( a[ c - 1 ], i ) = 1 and numtheory.gcd( a[ c - 2 ], i ) > 1
then
a[ c ], m[ i ] := i, true;
if i = minV then minV +:= 1 fi;
more := false
fi
od
od;
return a
end;
local constant ySize, constant perLine := 30, 10;
local y := yellowstone( ySize );
printf( "The first %d Yellowstone numbers are:\n", ySize );
for yPos to ySize do printf( " %2d", y[ yPos ] ); if yPos mod perLine = 0 then print() fi od
end