Skip to content

Commit b36ab95

Browse files
nstoikdhruvmanila
authored andcommitted
Coding style change for project_euler problem 36 and 35 (TheAlgorithms#3062)
* add problem url. Add typehint, default value and doctest * run black * add project url. add solution function for problem 35 * add space between imports on problem 35 * Update sol1.py * Update sol1.py Co-authored-by: Dhruv <[email protected]>
1 parent bb8a5cc commit b36ab95

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

Diff for: project_euler/problem_35/sol1.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
"""
2+
Project Euler Problem 35
3+
https://projecteuler.net/problem=35
4+
5+
Problem Statement:
6+
27
The number 197 is called a circular prime because all rotations of the digits:
38
197, 971, and 719, are themselves prime.
49
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73,
@@ -65,5 +70,13 @@ def find_circular_primes(limit: int = 1000000) -> list[int]:
6570
return result
6671

6772

73+
def solution() -> int:
74+
"""
75+
>>> solution()
76+
55
77+
"""
78+
return len(find_circular_primes())
79+
80+
6881
if __name__ == "__main__":
6982
print(f"{len(find_circular_primes()) = }")

Diff for: project_euler/problem_36/sol1.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
"""
2+
Project Euler Problem 36
3+
https://projecteuler.net/problem=36
4+
5+
Problem Statement:
6+
27
Double-base palindromes
38
Problem 36
49
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
@@ -10,17 +15,28 @@
1015
leading zeros.)
1116
"""
1217

18+
from typing import Union
1319

14-
def is_palindrome(n):
15-
n = str(n)
1620

17-
if n == n[::-1]:
18-
return True
19-
else:
20-
return False
21+
def is_palindrome(n: Union[int, str]) -> bool:
22+
"""
23+
Return true if the input n is a palindrome.
24+
Otherwise return false. n can be an integer or a string.
25+
26+
>>> is_palindrome(909)
27+
True
28+
>>> is_palindrome(908)
29+
False
30+
>>> is_palindrome('10101')
31+
True
32+
>>> is_palindrome('10111')
33+
False
34+
"""
35+
n = str(n)
36+
return True if n == n[::-1] else False
2137

2238

23-
def solution(n):
39+
def solution(n: int = 1000000):
2440
"""Return the sum of all numbers, less than n , which are palindromic in
2541
base 10 and base 2.
2642

0 commit comments

Comments
 (0)