Adopted new convention from template

This commit is contained in:
David Doblas Jiménez 2022-10-02 18:38:34 +02:00
parent 4fbb158c70
commit 8e85140d06

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
""" """
Created on 18 Sep 2021 Created on 18 Sep 2021
@ -9,7 +9,7 @@ Solution for problem 50 of Project Euler
https://projecteuler.net/problem=50 https://projecteuler.net/problem=50
""" """
from utils import timeit, list_primes, is_prime from utils import is_prime, list_primes, timeit
@timeit("Problem 50") @timeit("Problem 50")
@ -19,12 +19,14 @@ def compute():
41 = 2 + 3 + 5 + 7 + 11 + 13 41 = 2 + 3 + 5 + 7 + 11 + 13
This is the longest sum of consecutive primes that adds to a prime below one-hundred. This is the longest sum of consecutive primes that adds to a prime below
one-hundred.
The longest sum of consecutive primes below one-thousand that adds to a prime, The longest sum of consecutive primes below one-thousand that adds to a
contains 21 terms, and is equal to 953. prime, contains 21 terms, and is equal to 953.
Which prime, below one-million, can be written as the sum of the most consecutive primes? Which prime, below one-million, can be written as the sum of the most
consecutive primes?
""" """
ans = 0 ans = 0
@ -40,12 +42,11 @@ def compute():
if is_prime(sum) and count > result: if is_prime(sum) and count > result:
result = count result = count
ans = sum ans = sum
# print(sum, result)
if sum > 1_000_000: if sum > 1_000_000:
break break
return ans return ans
if __name__ == "__main__": if __name__ == "__main__":
print(f"Result for Problem 50 is {compute()}")
print(f"Result for Problem 50: {compute()}")