• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Generate & List all Lucky numbers from 1 to n using Numpy

Resolved: Generate & List all Lucky numbers from 1 to n using Numpy

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

A lucky number is found by listing all numbers up to n. 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,27,28,29,30,31,32 And then remove every second number so we get: 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 Now the next numbers after 1 here is 3 so now remove every third number: 1,3,7,9,13,15,19,21,25,27,29 Now the next number after 3 is 7, so now remove every seventh number: 1,3,7,9,13,15,21,25,27,29 And the next number after 7 in our list is 9 so now remove every ninth number. etc
The remaining numbers are lucky numbers: 1,3,7,9,13,15,21,25,31
Hello, I am a relatively new Python programmer who is trying to figure this out. I did not even come close to solving this, and I want them up to the 100 billions so an advice of the best way to go about this is welcome. here is my best try to get this done in Numpy:
It returns only 1 so this requires more advanced programming to find the lucky numbers, I need some clever programming in order to automatically find the next skip also since I can’t input millions of skips like I have done here with the skips of 2, 3, 7 & 9.

Answer:

IIUC, one way using while loop with checker:
Output:

If you have better answer, please add a comment about this, thank you!

numpy
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.