33 lines
709 B
Plaintext
33 lines
709 B
Plaintext
require "table2"
|
|
local int = require "int"
|
|
local fmt = require "fmt"
|
|
|
|
local function yellowstone(n)
|
|
local m = {}
|
|
local a = table.rep(n, 0)
|
|
for i = 1, 3 do
|
|
a[i] = i
|
|
m[i] = true
|
|
end
|
|
local min = 4
|
|
for c = 4, n do
|
|
local i = min
|
|
while true do
|
|
if !m[i] and int.gcd(a[c - 1], i) == 1 and int.gcd(a[c - 2], i) > 1 then
|
|
a[c] = i
|
|
m[i] = true
|
|
if i == min then ++min end
|
|
break
|
|
end
|
|
++i
|
|
end
|
|
end
|
|
return a
|
|
end
|
|
|
|
local x = {}
|
|
for i = 1, 30 do x[i] = i end
|
|
local y = yellowstone(30)
|
|
print("The first 30 Yellowstone numbers are:")
|
|
fmt.tprint("%2d ", y, 10)
|