Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Yellowstone-sequence/Nim/yellowstone-sequence-1.nim
Normal file
18
Task/Yellowstone-sequence/Nim/yellowstone-sequence-1.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import math
|
||||
|
||||
proc yellowstone(n: int): seq[int] =
|
||||
assert n >= 3
|
||||
result = @[1, 2, 3]
|
||||
var present = {1, 2, 3}
|
||||
var start = 4
|
||||
while result.len < n:
|
||||
var candidate = start
|
||||
while true:
|
||||
if candidate notin present and gcd(candidate, result[^1]) == 1 and gcd(candidate, result[^2]) != 1:
|
||||
result.add candidate
|
||||
present.incl candidate
|
||||
while start in present: inc start
|
||||
break
|
||||
inc candidate
|
||||
|
||||
echo yellowstone(30)
|
||||
24
Task/Yellowstone-sequence/Nim/yellowstone-sequence-2.nim
Normal file
24
Task/Yellowstone-sequence/Nim/yellowstone-sequence-2.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import math, sets
|
||||
|
||||
iterator yellowstone(n: int): int =
|
||||
assert n >= 3
|
||||
for i in 1..3: yield i
|
||||
var present = [1, 2, 3].toHashSet
|
||||
var prevLast = 2
|
||||
var last = 3
|
||||
var start = 4
|
||||
for _ in 4..n:
|
||||
var candidate = start
|
||||
while true:
|
||||
if candidate notin present and gcd(candidate, last) == 1 and gcd(candidate, prevLast) != 1:
|
||||
yield candidate
|
||||
present.incl candidate
|
||||
prevLast = last
|
||||
last = candidate
|
||||
while start in present: inc start
|
||||
break
|
||||
inc candidate
|
||||
|
||||
for n in yellowstone(30):
|
||||
stdout.write " ", n
|
||||
echo()
|
||||
Loading…
Add table
Add a link
Reference in a new issue