22
3
Story:
Lucy asked George what his Lucky Number was. After some contemplation, George replied that he had several Lucky Numbers. After some brief confusion, Lucy asked George what his first n
Lucky Numbers are. George then asked you, his buddy, to write him a program to do the work for him.
The Challenge:
You will write a program/function that will receive from standard input/function argument a string or integer n
. The program/function will then return/output the first n
Lucky Numbers. Lucky numbers are defined via a sieve as follows.
Start with the positive integers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ...
Now remove every second number:
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ...
The second remaining number is 3, so remove every third number:
1, 3, 7, 9, 13, 15, 19, 21, 25, ...
Now the next remaining number is 7, so remove every seventh number:
1, 3, 7, 9, 13, 15, 21, 25, ...
Next, remove every ninth number and so on. The resulting sequence are the lucky numbers.
Winning:
As usual for codegolf, fewest bytes wins.
As usual, submissions using standard loopholes are disqualified.
8I'd suggest including the definition in the post as well as the first ten or so numbers. – xnor – 2015-02-17T04:14:13.013
A cool extension would be that for each item examined (3, 7, etc.) will do that operation that number of times. For example for 3, remove the third element in the list 3 times, the 7th element 7 times, etc. (note this is not the sequence but the idea is the same) – Ryan – 2015-02-17T15:51:05.357
@Ryan I think that sequence would be remarkably similar to the natural numbers :) – TheNumberOne – 2015-02-18T02:40:30.227
@TheBestOne You think so? I posted earlier to math.stackexchange: https://math.stackexchange.com/questions/1153889/characterization-of-extended-lucky-numbers
– Ryan – 2015-02-18T02:41:41.967@Ryan Actually, I misinterpreted your suggestion. As you stated it in your question on math.se, I think that would be interesting. – TheNumberOne – 2015-02-18T02:47:46.697