Challenges

# The Ludic Numbers

+4
−0

The Ludic Numbers are a sequence that pops up when you apply the sieve of eratosthenes to the natural numbers, completely removing the numbers every iteration.

Here is how they are generated:

l = [1]
n = [2,3,4,5,6,7,8,9,10....]


Every iteration, we take the first element x in n, add it to the list, and remove every xth number in n, including x.

l = [1,2]
n = [3,5,7,9,11,...]


By repeating this process an infinite number of times, we can get the full list of Ludic numbers.

# Challenge

For this sequence, you can

• Take an index $n$ and output the $n^{th}$ term, either 0 or 1 indexed.
• Take a positive integer $n$ and output the first $n$ terms.
• Output the whole sequence as an infinite list.

# Testcases

1		1
2		2
3		3
4		5
5		7
6		11
7		13
8		17
9		23
10		25
11		29
12		37
13		41
14		43
15		47
16		53


The first 56 values can be seen here: A003309.

Reference implementations can be found at Rosetta Code.

# Scoring

This is code-golf. Shortest answer in every language wins.

Why does this post require moderator attention?
Why should this post be closed?

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+2
−0

# Python 3, 807775 72 bytes

def f():
yield 1;l=[*range(2,236425)]
while l:yield l[0];del l[::l[0]]


Try it online!

Prints out the whole sequence. I did my best to get the biggest number that won't crash the program.

Golfed 3 bytes thanks to @Moshi's advice.

Why does this post require moderator attention?

list -> [*] (1 comment)
+3
−0

-2 bytes thanks to Wheat Wizard

1:g[2..]
g(a:b)=a:g[d|(c,d)<-zip[1..]b,cmoda>0]


Try it online!

Why does this post require moderator attention?

Suggested golf (1 comment)
+2
−0

# Sclipting, (UTF-16) 5852 bytes

가匱❸增平갠下氫終要鈮貶⓶梴감⓶上❸乘殲終終并鈮掘增


Gives the nth ludic number, 0-indexed.

가
Start list of Ludics with 0

Create a list of numbers from 2 to n+1 squared

While the list is truthy
鈮
Retrieve the Ludic number x (the first element)
貶
Decrement x
⓶梴감⓶上
For i = 1 up to the length of the list
❸乘殲
Remove the number at index x * i
終
End loop

End loop

Get the nth item from the list of Ludics and increment

Why does this post require moderator attention?