Skip to content

Add lucky numbers #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add lucky numbers
Fixes #40
  • Loading branch information
Zxey authored and richardhozak committed Oct 5, 2018
commit a0c9b1d317ff957b7460b44773ec7a9de8ac3ccd
22 changes: 22 additions & 0 deletions math/lucky_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def lucky_numbers(n):
survivor = 1
delete_every = 2
index = None
sieve = list(range(1, n + 1))

while len(sieve) >= delete_every:
index = delete_every - 1
while index < len(sieve):
del sieve[index]
index += (delete_every - 1)

survivor_index = sieve.index(survivor) + 1
survivor = sieve[survivor_index]
delete_every = survivor

return sieve

if __name__ == "__main__":
number = input("Enter number: ")
number = int(number)
print("Lucky numbers:", *lucky_numbers(number))
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy