From 682ee755d2d9836d8a12009411ccbb24223474ad Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 22 Sep 2022 09:05:55 +0200 Subject: [PATCH] Adopted new convention from template --- src/Python/Problems001-050/Problem012.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Python/Problems001-050/Problem012.py b/src/Python/Problems001-050/Problem012.py index fd7064b..00610ed 100644 --- a/src/Python/Problems001-050/Problem012.py +++ b/src/Python/Problems001-050/Problem012.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python """ Created on 01 Jan 2018 @@ -9,9 +9,10 @@ Solution for problem 12 of Project Euler https://projecteuler.net/problem=12 """ -import itertools +from itertools import count +from math import floor, sqrt + from utils import timeit -from math import sqrt, floor # Returns the number of integers in the range [1, n] that divide n. @@ -23,8 +24,7 @@ def num_divisors(n): divs.append(i) if end**2 == n: divs.pop() - return 2*len(divs) - + return 2 * len(divs) @timeit("Problem 12") @@ -54,7 +54,7 @@ def compute(): """ 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 = # = i*(i+1)/2 triangle += i @@ -63,5 +63,4 @@ def compute(): if __name__ == "__main__": - - print(f"Result for Problem 12: {compute()}") \ No newline at end of file + print(f"Result for Problem 12 is {compute()}")