Simplify code by dropping support for legacy Python (#1143)

* Simplify code by dropping support for legacy Python

* sort() --> sorted()
This commit is contained in:
Christian Clauss
2019-08-19 15:37:49 +02:00
committed by GitHub
parent 32aa7ff081
commit 47a9ea2b0b
145 changed files with 367 additions and 976 deletions

View File

@ -21,18 +21,12 @@ We can see that 28 is the first triangle number to have over five divisors.
What is the value of the first triangle number to have over five hundred
divisors?
"""
from __future__ import print_function
from math import sqrt
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
def count_divisors(n):
nDivisors = 0
for i in xrange(1, int(sqrt(n)) + 1):
for i in range(1, int(sqrt(n)) + 1):
if n % i == 0:
nDivisors += 2
# check if n is perfect square
@ -44,7 +38,7 @@ def count_divisors(n):
def solution():
"""Returns the value of the first triangle number to have over five hundred
divisors.
# The code below has been commented due to slow execution affecting Travis.
# >>> solution()
# 76576500

View File

@ -21,9 +21,6 @@ We can see that 28 is the first triangle number to have over five divisors.
What is the value of the first triangle number to have over five hundred
divisors?
"""
from __future__ import print_function
def triangle_number_generator():
for n in range(1, 1000000):
yield n * (n + 1) // 2
@ -38,7 +35,7 @@ def count_divisors(n):
def solution():
"""Returns the value of the first triangle number to have over five hundred
divisors.
# The code below has been commented due to slow execution affecting Travis.
# >>> solution()
# 76576500