Skip to content

Hacktoberfest 2020 - coding style changes for project_euler problem 36 and 35 #3062

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

Merged
merged 6 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions project_euler/problem_35/sol1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""
Project Euler Problem 35
https://projecteuler.net/problem=35

Problem Statement:

The number 197 is called a circular prime because all rotations of the digits:
197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73,
Expand Down Expand Up @@ -65,5 +70,13 @@ def find_circular_primes(limit: int = 1000000) -> list[int]:
return result


def solution() -> int:
"""
>>> solution()
55
"""
return len(find_circular_primes())


if __name__ == "__main__":
print(f"{len(find_circular_primes()) = }")
30 changes: 23 additions & 7 deletions project_euler/problem_36/sol1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""
Project Euler Problem 36
https://projecteuler.net/problem=36

Problem Statement:

Double-base palindromes
Problem 36
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Expand All @@ -10,17 +15,28 @@
leading zeros.)
"""

from typing import Union

def is_palindrome(n):
n = str(n)

if n == n[::-1]:
return True
else:
return False
def is_palindrome(n: Union[int, str]) -> bool:
"""
Return true if the input n is a palindrome.
Otherwise return false. n can be an integer or a string.

>>> is_palindrome(909)
True
>>> is_palindrome(908)
False
>>> is_palindrome('10101')
True
>>> is_palindrome('10111')
False
"""
n = str(n)
return True if n == n[::-1] else False


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

Expand Down