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

@ -16,20 +16,12 @@ that all starting numbers finish at 1.
Which starting number, under one million, produces the longest chain?
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the number under n that generates the longest sequence using the
formula:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
# The code below has been commented due to slow execution affecting Travis.
# >>> solution(1000000)
# {'counter': 525, 'largest_number': 837799}
@ -62,7 +54,7 @@ def solution(n):
if __name__ == "__main__":
result = solution(int(raw_input().strip()))
result = solution(int(input().strip()))
print(
(
"Largest Number:",

View File

@ -24,14 +24,6 @@ that all starting numbers finish at 1.
Which starting number, under one million, produces the longest chain?
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def collatz_sequence(n):
"""Returns the Collatz sequence for n."""
sequence = [n]
@ -63,7 +55,7 @@ def solution(n):
if __name__ == "__main__":
result = solution(int(raw_input().strip()))
result = solution(int(input().strip()))
print(
"Longest Collatz sequence under one million is %d with length %d"
% (result["largest_number"], result["counter"])