Adopted new convention from template

This commit is contained in:
2022-09-22 09:05:55 +02:00
parent 6941a8cf45
commit 682ee755d2

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
""" """
Created on 01 Jan 2018 Created on 01 Jan 2018
@@ -9,9 +9,10 @@ Solution for problem 12 of Project Euler
https://projecteuler.net/problem=12 https://projecteuler.net/problem=12
""" """
import itertools from itertools import count
from math import floor, sqrt
from utils import timeit from utils import timeit
from math import sqrt, floor
# Returns the number of integers in the range [1, n] that divide n. # Returns the number of integers in the range [1, n] that divide n.
@@ -23,8 +24,7 @@ def num_divisors(n):
divs.append(i) divs.append(i)
if end**2 == n: if end**2 == n:
divs.pop() divs.pop()
return 2*len(divs) return 2 * len(divs)
@timeit("Problem 12") @timeit("Problem 12")
@@ -54,7 +54,7 @@ def compute():
""" """
triangle = 0 triangle = 0
for i in itertools.count(1): for i in count(1):
# This is the ith triangle number, i.e. num = 1 + 2 + ... + i = # This is the ith triangle number, i.e. num = 1 + 2 + ... + i =
# = i*(i+1)/2 # = i*(i+1)/2
triangle += i triangle += i
@@ -63,5 +63,4 @@ def compute():
if __name__ == "__main__": if __name__ == "__main__":
print(f"Result for Problem 12 is {compute()}")
print(f"Result for Problem 12: {compute()}")