Adopted new convention from template

This commit is contained in:
David Doblas Jiménez 2022-10-02 18:37:34 +02:00
parent 037fb1de95
commit 60d89e8681

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python
"""
Created on 12 Sep 2021
@ -9,32 +9,36 @@ Solution for problem 46 of Project Euler
https://projecteuler.net/problem=46
"""
from utils import timeit, is_prime
from utils import is_prime, timeit
def is_goldbach(number):
for i in range(number - 1, 1, -1):
if is_prime(i) and ((number - i) / 2) ** 0.5 % 1 == 0:
return True
return False
@timeit("Problem 46")
def compute():
"""
It was proposed by Christian Goldbach that every odd composite number
can be written as the sum of a prime and twice a square.
9 = 7 + 2×1^2
15 = 7 + 2×2^2
21 = 3 + 2×3^2
25 = 7 + 2×3^2
27 = 19 + 2×2^2
33 = 31 + 2×1^2
9 = 7 + 2x1^2
15 = 7 + 2x2^2
21 = 3 + 2x3^2
25 = 7 + 2x3^2
27 = 19 + 2x2^2
33 = 31 + 2x1^2
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum
of a prime and twice a square?
"""
ans = 9
while True:
ans += 2
@ -42,7 +46,5 @@ def compute():
return ans
if __name__ == "__main__":
print(f"Result for Problem 46: {compute()}")
print(f"Result for Problem 46 is {compute()}")