Skip to content

Commit a50cf03

Browse files
committed
Add lucky numbers
1 parent f7f877b commit a50cf03

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

math/lucky_numbers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def is_lucky(number):
2+
counter = 2
3+
4+
def is_lucky_inner(number):
5+
nonlocal counter
6+
7+
next_position = number
8+
9+
if counter > number: return True
10+
if number % counter == 0: return False
11+
12+
next_position -= next_position // counter
13+
counter += 1
14+
15+
return is_lucky_inner(next_position)
16+
17+
return is_lucky_inner(number)
18+
19+
for i in range(1, 11):
20+
print("number {} {}".format(i, "is lucky" if is_lucky(i) else "is not lucky"))

0 commit comments

Comments
 (0)
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