+ 5

Challenge: lucky numbers

Lucky numbers are "survivors numbers" in an array once a specific pattern is recursively applied (numbers in array are removed at every recursion cycle). every recursion cycle has to remove numbers from position "p" and every position interval that is the number in starting position. note that in every cycle, p is one bigger than p in previous cycle for example, lucky numbers from 1 to 120 are (1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, 87, 93, 99, 105, 111, 115) task: write a code - in every language you prefer - that displays all lucky numbers from 1 to user input p.s.: as explaining this in a few characters is difficult, i post here wikipedia link of the full explanation with examples: https://en.wikipedia.org/wiki/Lucky_number good coding :)

26th Aug 2017, 11:18 AM
Luca
Luca - avatar
12 Answers
+ 2
@baptiste you don't have to consider number in position p in the original array, but in the newborn array after previous pass... fourth pass is not with number 5, but number in fourth position in the array resulting from third pass edit: sorry, i red your answer after i posted :D glad you got it :)
26th Aug 2017, 11:54 AM
Luca
Luca - avatar
26th Aug 2017, 12:05 PM
Calviղ
Calviղ - avatar
+ 1
Your example is not the output for 25 but the output after the 3rd pass ... But aren't there more pass ? Or should we stop to 3 ? Regardless, here is my try https://code.sololearn.com/cGE3ca1WE1GW/?ref=app
26th Aug 2017, 10:52 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
@baptiste this is because both the output of third pass and for 25, as in such short sequence only 3 passes are done. the fourth pass would be every ninth enumber starting from ninth, buth there are only 8 left numbers in array... this is my php code for lucky numbers https://code.sololearn.com/wrN1AdPdTVmf/#php limit is set to 120, and as you can see it goes over 3rd passage... my fault, i gave too fiew numbers as example, i will edit soon :)
26th Aug 2017, 11:18 AM
Luca
Luca - avatar
+ 1
@baptiste i checked your code, but i get all integers from 1 to input...
26th Aug 2017, 11:19 AM
Luca
Luca - avatar
+ 1
@Luca, I understand now ! I corrected my code accordingly (I had the increment of the nth pass wrong)
26th Aug 2017, 11:46 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
26th Aug 2017, 8:18 PM
ysraelcon
ysraelcon - avatar
0
I may have misunderstood something but p should increase each time by one, so on fourth pass, be 5, no ? And the result should be applied on the list without the unlucky members already founded no ?
26th Aug 2017, 11:23 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
Here you go. Checks for valid input. https://code.sololearn.com/cHVvQwxYDx7d/?ref=app
26th Aug 2017, 11:31 AM
Vari93
Vari93 - avatar
0
@Luca yes, I forgot the line l.pop(j) but I replaced it, sorry ^^'
26th Aug 2017, 11:36 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
28th Aug 2017, 8:29 AM
sayan chandra
sayan chandra - avatar
- 1
TRY THIS BRAND NEW CHALLENGE AND GET FRESH.. https://www.sololearn.com/discuss/666260/?ref=app
28th Aug 2017, 5:40 PM
sayan chandra
sayan chandra - avatar