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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
145 changed files with 367 additions and 976 deletions

View File

@ -84,7 +84,7 @@ We want your work to be readable by others; therefore, we encourage you to note
```python
input('Enter your input:')
# Or even worse...
input = eval(raw_input("Enter your input: "))
input = eval(input("Enter your input: "))
```
However, if your code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ to the end as in:
@ -99,11 +99,11 @@ We want your work to be readable by others; therefore, we encourage you to note
def sumab(a, b):
return a + b
# Write tests this way:
print(sumab(1,2)) # 1+2 = 3
print(sumab(6,4)) # 6+4 = 10
print(sumab(1, 2)) # 1+2 = 3
print(sumab(6, 4)) # 6+4 = 10
# Or this way:
print("1 + 2 = ", sumab(1,2)) # 1+2 = 3
print("6 + 4 = ", sumab(6,4)) # 6+4 = 10
print("1 + 2 = ", sumab(1, 2)) # 1+2 = 3
print("6 + 4 = ", sumab(6, 4)) # 6+4 = 10
```
Better yet, if you know how to write [__doctests__](https://docs.python.org/3/library/doctest.html), please consider adding them.

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import sys, random, cryptomath_module as cryptoMath
SYMBOLS = r""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""

View File

@ -1,23 +1,15 @@
try: # Python 2
raw_input
unichr
except NameError: # Python 3
raw_input = input
unichr = chr
def Atbash():
def atbash():
output=""
for i in raw_input("Enter the sentence to be encrypted ").strip():
for i in input("Enter the sentence to be encrypted ").strip():
extract = ord(i)
if 65 <= extract <= 90:
output += unichr(155-extract)
output += chr(155-extract)
elif 97 <= extract <= 122:
output += unichr(219-extract)
output += chr(219-extract)
else:
output+=i
output += i
print(output)
if __name__ == '__main__':
Atbash()
atbash()

View File

@ -1,4 +1,3 @@
from __future__ import print_function
def decrypt(message):
"""
>>> decrypt('TMDETUX PMDVU')

View File

@ -1,5 +1,3 @@
from __future__ import print_function
import random

View File

@ -1,4 +1,3 @@
from __future__ import print_function
# Primality Testing with the Rabin-Miller Algorithm
import random

View File

@ -1,4 +1,3 @@
from __future__ import print_function
def dencrypt(s, n):
out = ''
for c in s:

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import sys, rsa_key_generator as rkg, os
DEFAULT_BLOCK_SIZE = 128

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import random, sys, os
import rabin_miller as rabinMiller, cryptomath_module as cryptoMath

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import sys, random
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import math
def main():

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import time, os, sys
import transposition_cipher as transCipher

View File

@ -1,4 +1,3 @@
from __future__ import print_function
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def main():

View File

@ -1,7 +1,6 @@
'''
A binary search Tree
'''
from __future__ import print_function
class Node:
def __init__(self, label, parent):

View File

@ -1,4 +1,3 @@
from __future__ import print_function
class FenwickTree:
def __init__(self, SIZE): # create fenwick tree with size SIZE

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import math
class SegmentTree:

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import math
class SegmentTree:

View File

@ -1,15 +1,8 @@
#!/usr/bin/python
from __future__ import print_function, division
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
#This heap class start from here.
# This heap class start from here.
class Heap:
def __init__(self): #Default constructor of heap class.
def __init__(self): # Default constructor of heap class.
self.h = []
self.currsize = 0
@ -79,7 +72,7 @@ class Heap:
print(self.h)
def main():
l = list(map(int, raw_input().split()))
l = list(map(int, input().split()))
h = Heap()
h.buildHeap(l)
h.heapSort()

View File

@ -4,7 +4,6 @@
- Each link references the next link and the previous one.
- A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list.
- Advantages over SLL - IT can be traversed in both forward and backward direction.,Delete operation is more efficent'''
from __future__ import print_function
class LinkedList: #making main class named linked list

View File

@ -1,6 +1,3 @@
from __future__ import print_function
class Node: # create a Node
def __init__(self, data):
self.data = data # given data

View File

@ -1,4 +1,3 @@
from __future__ import print_function
# Python code to demonstrate working of
# extend(), extendleft(), rotate(), reverse()

View File

@ -1,6 +1,3 @@
from __future__ import print_function
from __future__ import absolute_import
from .stack import Stack
__author__ = 'Omkar Pathak'

View File

@ -1,5 +1,3 @@
from __future__ import print_function
from __future__ import absolute_import
import string
from .stack import Stack

View File

@ -1,4 +1,3 @@
from __future__ import print_function
# Function to print element and NGE pair for all elements of list
def printNGE(arr):

View File

@ -1,4 +1,3 @@
from __future__ import print_function
__author__ = 'Omkar Pathak'

View File

@ -6,7 +6,6 @@ The span Si of the stock's price on a given day i is defined as the maximum
number of consecutive days just before the given day, for which the price of the stock
on the current day is less than or equal to its price on the given day.
'''
from __future__ import print_function
def calculateSpan(price, S):
n = len(price)

View File

@ -1,5 +1,3 @@
from __future__ import print_function, absolute_import, division
from numbers import Number
"""
The convex hull problem is problem of finding all the vertices of convex polygon, P of

View File

@ -1,5 +1,3 @@
from __future__ import print_function, absolute_import, division
"""
Given an array-like data structure A[1..n], how many pairs
(i, j) for all 1 <= i < j <= n such that A[i] > A[j]? These pairs are

View File

@ -9,7 +9,6 @@ Find the total no of ways in which the tasks can be distributed.
"""
from __future__ import print_function
from collections import defaultdict

View File

@ -5,9 +5,6 @@ Can you determine number of ways of making change for n units using
the given types of coins?
https://www.hackerrank.com/challenges/coin-change/problem
"""
from __future__ import print_function
def dp_count(S, m, n):
# table[i] represents the number of ways to get to amount i

View File

@ -7,7 +7,6 @@ This is a pure Python implementation of Dynamic Programming solution to the edit
The problem is :
Given two strings A and B. Find the minimum number of operations to string B such that A = B. The permitted operations are removal, insertion, and substitution.
"""
from __future__ import print_function
class EditDistance:
@ -82,21 +81,13 @@ def min_distance_bottom_up(word1: str, word2: str) -> int:
return dp[m][n]
if __name__ == '__main__':
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
solver = EditDistance()
print("****************** Testing Edit Distance DP Algorithm ******************")
print()
print("Enter the first string: ", end="")
S1 = raw_input().strip()
print("Enter the second string: ", end="")
S2 = raw_input().strip()
S1 = input("Enter the first string: ").strip()
S2 = input("Enter the second string: ").strip()
print()
print("The minimum Edit Distance is: %d" % (solver.solve(S1, S2)))

View File

@ -5,7 +5,6 @@
This program calculates the nth Fibonacci number in O(log(n)).
It's possible to calculate F(1000000) in less than a second.
"""
from __future__ import print_function
import sys

View File

@ -1,7 +1,6 @@
"""
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
"""
from __future__ import print_function
class Fibonacci:
@ -29,21 +28,16 @@ class Fibonacci:
if __name__ == '__main__':
print("\n********* Fibonacci Series Using Dynamic Programming ************\n")
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
print("\n Enter the upper limit for the fibonacci sequence: ", end="")
try:
N = eval(raw_input().strip())
N = int(input().strip())
fib = Fibonacci(N)
print(
"\n********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n")
"\n********* Enter different values to get the corresponding fibonacci "
"sequence, enter any negative number to exit. ************\n")
while True:
print("Enter value: ", end=" ")
try:
i = eval(raw_input().strip())
i = int(input("Enter value: ").strip())
if i < 0:
print("\n********* Good Bye!! ************\n")
break

View File

@ -1,27 +1,15 @@
from __future__ import print_function
try:
xrange #Python 2
except NameError:
xrange = range #Python 3
try:
raw_input #Python 2
except NameError:
raw_input = input #Python 3
'''
The number of partitions of a number n into at least k parts equals the number of partitions into exactly k parts
plus the number of partitions into at least k-1 parts. Subtracting 1 from each part of a partition of n into k parts
gives a partition of n-k into k parts. These two facts together are used for this algorithm.
'''
def partition(m):
memo = [[0 for _ in xrange(m)] for _ in xrange(m+1)]
for i in xrange(m+1):
memo = [[0 for _ in range(m)] for _ in range(m+1)]
for i in range(m+1):
memo[i][0] = 1
for n in xrange(m+1):
for k in xrange(1, m):
for n in range(m+1):
for k in range(1, m):
memo[n][k] += memo[n][k-1]
if n-k > 0:
memo[n][k] += memo[n-k-1][k]
@ -33,7 +21,7 @@ if __name__ == '__main__':
if len(sys.argv) == 1:
try:
n = int(raw_input('Enter a number: '))
n = int(input('Enter a number: ').strip())
print(partition(n))
except ValueError:
print('Please enter a number.')

View File

@ -3,7 +3,6 @@ LCS Problem Statement: Given two sequences, find the length of longest subsequen
A subsequence is a sequence that appears in the same relative order, but not necessarily continuous.
Example:"abc", "abg" are subsequences of "abcdefgh".
"""
from __future__ import print_function
def longest_common_subsequence(x: str, y: str):
@ -80,4 +79,3 @@ if __name__ == '__main__':
assert expected_ln == ln
assert expected_subseq == subseq
print("len =", ln, ", sub-sequence =", subseq)

View File

@ -7,8 +7,6 @@ The problem is :
Given an ARRAY, to find the longest and increasing sub ARRAY in that given ARRAY and return it.
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return [10, 22, 33, 41, 60, 80] as output
'''
from __future__ import print_function
def longestSub(ARRAY): #This function is recursive
ARRAY_LENGTH = len(ARRAY)

View File

@ -1,4 +1,3 @@
from __future__ import print_function
#############################
# Author: Aravind Kashyap
# File: lis.py

View File

@ -6,7 +6,6 @@ This is a pure Python implementation of Dynamic Programming solution to the long
The problem is :
Given an array, to find the longest and continuous sub array and get the max sum of the sub array in the given array.
'''
from __future__ import print_function
class SubArray:

View File

@ -1,5 +1,3 @@
from __future__ import print_function
import sys
'''
Dynamic Programming

View File

@ -1,7 +1,6 @@
"""
author : Mayank Kumar Jha (mk9440)
"""
from __future__ import print_function
from typing import List
import time
import matplotlib.pyplot as plt

View File

@ -1,5 +1,3 @@
from __future__ import print_function
grid = [[0, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],#0 are free path whereas 1's are obstacles
[0, 1, 0, 0, 0, 0],

View File

@ -1,23 +1,10 @@
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
if __name__ == "__main__":
# Accept No. of Nodes and edges
n, m = map(int, raw_input().split(" "))
n, m = map(int, input().split(" "))
# Initialising Dictionary of edges
g = {}
for i in xrange(n):
for i in range(n):
g[i + 1] = []
"""
@ -25,8 +12,8 @@ if __name__ == "__main__":
Accepting edges of Unweighted Directed Graphs
----------------------------------------------------------------------------
"""
for _ in xrange(m):
x, y = map(int, raw_input().strip().split(" "))
for _ in range(m):
x, y = map(int, input().strip().split(" "))
g[x].append(y)
"""
@ -34,8 +21,8 @@ if __name__ == "__main__":
Accepting edges of Unweighted Undirected Graphs
----------------------------------------------------------------------------
"""
for _ in xrange(m):
x, y = map(int, raw_input().strip().split(" "))
for _ in range(m):
x, y = map(int, input().strip().split(" "))
g[x].append(y)
g[y].append(x)
@ -44,8 +31,8 @@ if __name__ == "__main__":
Accepting edges of Weighted Undirected Graphs
----------------------------------------------------------------------------
"""
for _ in xrange(m):
x, y, r = map(int, raw_input().strip().split(" "))
for _ in range(m):
x, y, r = map(int, input().strip().split(" "))
g[x].append([y, r])
g[y].append([x, r])
@ -170,10 +157,10 @@ def topo(G, ind=None, Q=[1]):
def adjm():
n = raw_input().strip()
n = input().strip()
a = []
for i in xrange(n):
a.append(map(int, raw_input().strip().split()))
for i in range(n):
a.append(map(int, input().strip().split()))
return a, n
@ -193,10 +180,10 @@ def adjm():
def floy(A_and_n):
(A, n) = A_and_n
dist = list(A)
path = [[0] * n for i in xrange(n)]
for k in xrange(n):
for i in xrange(n):
for j in xrange(n):
path = [[0] * n for i in range(n)]
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
path[i][k] = k
@ -245,10 +232,10 @@ def prim(G, s):
def edglist():
n, m = map(int, raw_input().split(" "))
n, m = map(int, input().split(" "))
l = []
for i in xrange(m):
l.append(map(int, raw_input().split(' ')))
for i in range(m):
l.append(map(int, input().split(' ')))
return l, n
@ -272,10 +259,10 @@ def krusk(E_and_n):
break
print(s)
x = E.pop()
for i in xrange(len(s)):
for i in range(len(s)):
if x[0] in s[i]:
break
for j in xrange(len(s)):
for j in range(len(s)):
if x[1] in s[j]:
if i == j:
break

View File

@ -1,5 +1,3 @@
from __future__ import print_function
def printDist(dist, V):
print("\nVertex Distance")
for i in range(V):

View File

@ -3,8 +3,6 @@
""" Author: OMKAR PATHAK """
from __future__ import print_function
class Graph():
def __init__(self):

View File

@ -2,7 +2,6 @@
# encoding=utf8
""" Author: OMKAR PATHAK """
from __future__ import print_function
class Graph():

View File

@ -1,5 +1,3 @@
from __future__ import print_function
def printDist(dist, V):
print("\nVertex Distance")
for i in range(V):

View File

@ -2,7 +2,6 @@
# Author: Shubham Malik
# References: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
from __future__ import print_function
import math
import sys
# For storing the vertex set to retreive node with the lowest distance

View File

@ -12,7 +12,6 @@ Constraints
Note: The tree input will be such that it can always be decomposed into
components containing an even number of nodes.
"""
from __future__ import print_function
# pylint: disable=invalid-name
from collections import defaultdict

View File

@ -1,7 +1,6 @@
#!/usr/bin/python
# encoding=utf8
from __future__ import print_function
# Author: OMKAR PATHAK
# We can use Python's dictionary for constructing the graph.

View File

@ -1,6 +1,3 @@
from __future__ import print_function
class Graph:
def __init__(self, vertex):

View File

@ -4,8 +4,6 @@
have negative edge weights.
"""
from __future__ import print_function
def _print_dist(dist, v):
print("\nThe shortest path matrix using Floyd Warshall algorithm\n")

View File

@ -1,5 +1,3 @@
from __future__ import print_function
if __name__ == "__main__":
num_nodes, num_edges = list(map(int, input().strip().split()))

View File

@ -1,12 +1,6 @@
from __future__ import print_function
import heapq
import numpy as np
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
class PriorityQueue:
def __init__(self):
@ -96,7 +90,7 @@ def do_something(back_pointer, goal, start):
grid[(n-1)][0] = "-"
for i in xrange(n):
for i in range(n):
for j in range(n):
if (i, j) == (0, n-1):
print(grid[i][j], end=' ')

View File

@ -1,6 +1,3 @@
from __future__ import print_function
def dfs(u):
global g, r, scc, component, visit, stack
if visit[u]: return

View File

@ -1,10 +1,4 @@
"""example of simple chaos machine"""
from __future__ import print_function
try:
input = raw_input # Python 2
except NameError:
pass # Python 3
# Chaos Machine (K, t, m)
K = [0.33, 0.44, 0.55, 0.44, 0.33]; t = 3; m = 5

View File

@ -1,5 +1,3 @@
from __future__ import print_function
alphabets = [chr(i) for i in range(32, 126)]
gear_one = [i for i in range(len(alphabets))]
gear_two = [i for i in range(len(alphabets))]

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import math

View File

@ -3,8 +3,6 @@ Implementation of a basic regression decision tree.
Input data set: The input data set must be 1-dimensional with continuous labels.
Output: The decision tree maps a real number input to a real number output.
"""
from __future__ import print_function
import numpy as np
class Decision_Tree:

View File

@ -1,7 +1,6 @@
"""
Implementation of gradient descent algorithm for minimizing cost of a linear hypothesis function.
"""
from __future__ import print_function, division
import numpy
# List of input, output pairs

View File

@ -46,7 +46,6 @@ Usage:
5. Have fun..
'''
from __future__ import print_function
from sklearn.metrics import pairwise_distances
import numpy as np

View File

@ -7,8 +7,6 @@ We try to set these Feature weights, over many iterations, so that they best
fits our dataset. In this particular code, i had used a CSGO dataset (ADR vs
Rating). We try to best fit a line through dataset and estimate the parameters.
"""
from __future__ import print_function
import requests
import numpy as np

View File

@ -8,9 +8,6 @@ method 2:
"Simpson Rule"
"""
from __future__ import print_function
def method_2(boundary, steps):
# "Simpson Rule"
# int(f) = delta_x/2 * (b-a)/3*(f1 + 4f2 + 2f_3 + ... + fn)

View File

@ -7,8 +7,6 @@ method 1:
"extended trapezoidal rule"
"""
from __future__ import print_function
def method_1(boundary, steps):
# "extended trapezoidal rule"
# int(f) = dx/2 * (f1 + 2f2 + ... + fn)

View File

@ -1,4 +1,3 @@
from __future__ import annotations
import datetime
import argparse

View File

@ -13,9 +13,6 @@ Converting to matrix,
So we just need the n times multiplication of the matrix [1,1],[1,0]].
We can decrease the n times multiplication by following the divide and conquer approach.
"""
from __future__ import print_function
def multiply(matrix_a, matrix_b):
matrix_c = []
n = len(matrix_a)

View File

@ -15,8 +15,6 @@
Date: 2017.9.20
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
'''
from __future__ import print_function
import pickle
import numpy as np
import matplotlib.pyplot as plt

View File

@ -9,8 +9,6 @@
p2 = 1
'''
from __future__ import print_function
import random

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import collections, pprint, time, os
start_time = time.time()

View File

@ -1,4 +1,3 @@
from __future__ import print_function
# https://en.wikipedia.org/wiki/Euclidean_algorithm
def euclidean_gcd(a, b):

View File

@ -1,4 +1,3 @@
from __future__ import print_function
__author__ = "Tobias Carryer"
from time import time

View File

@ -13,9 +13,6 @@ The function called is_balanced takes as input a string S which is a sequence of
returns true if S is nested and false otherwise.
'''
from __future__ import print_function
def is_balanced(S):
stack = []

View File

@ -1,5 +1,4 @@
"""Password generator allows you to generate a random password of length N."""
from __future__ import print_function
from random import choice
from string import ascii_letters, digits, punctuation

View File

@ -1,4 +1,3 @@
from __future__ import print_function
def moveTower(height, fromPole, toPole, withPole):
'''
>>> moveTower(3, 'A', 'B', 'C')

View File

@ -9,8 +9,6 @@ Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
"""
from __future__ import print_function
def twoSum(nums, target):
"""
:type nums: List[int]

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import pprint, time
def getWordPattern(word):

View File

@ -4,14 +4,6 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3,5,6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all the multiples of 3 or 5 below n.
@ -31,4 +23,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -4,12 +4,6 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3,5,6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
@ -36,4 +30,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -4,14 +4,6 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3,5,6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""
This solution is based on the pattern that the successive numbers in the
@ -63,4 +55,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -4,14 +4,6 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3,5,6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all the multiples of 3 or 5 below n.
@ -50,4 +42,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -4,12 +4,6 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3,5,6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
"""A straightforward pythonic solution using list comprehension"""
@ -31,4 +25,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -4,14 +4,6 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3,5,6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all the multiples of 3 or 5 below n.
@ -37,4 +29,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -9,14 +9,6 @@ By considering the terms in the Fibonacci sequence whose values do not exceed
n, find the sum of the even-valued terms. e.g. for n=10, we have {2,8}, sum is
10.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all fibonacci sequence even elements that are lower
or equals to n.
@ -44,4 +36,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -9,14 +9,6 @@ By considering the terms in the Fibonacci sequence whose values do not exceed
n, find the sum of the even-valued terms. e.g. for n=10, we have {2,8}, sum is
10.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all fibonacci sequence even elements that are lower
or equals to n.
@ -42,4 +34,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -9,14 +9,6 @@ By considering the terms in the Fibonacci sequence whose values do not exceed
n, find the sum of the even-valued terms. e.g. for n=10, we have {2,8}, sum is
10.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all fibonacci sequence even elements that are lower
or equals to n.
@ -44,4 +36,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -9,15 +9,9 @@ By considering the terms in the Fibonacci sequence whose values do not exceed
n, find the sum of the even-valued terms. e.g. for n=10, we have {2,8}, sum is
10.
"""
from __future__ import print_function
import math
from decimal import Decimal, getcontext
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the sum of all fibonacci sequence even elements that are lower
@ -68,4 +62,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -5,14 +5,8 @@ of a given number N?
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
"""
from __future__ import print_function, division
import math
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def isprime(no):
if no == 2:
@ -81,4 +75,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -5,12 +5,6 @@ of a given number N?
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
"""
from __future__ import print_function, division
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
@ -60,4 +54,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,14 +6,6 @@ the product of two 2-digit numbers is 9009 = 91 x 99.
Find the largest palindrome made from the product of two 3-digit numbers which
is less than N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the largest palindrome made from the product of two 3-digit
numbers which is less than n.
@ -47,4 +39,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,14 +6,6 @@ the product of two 2-digit numbers is 9009 = 91 x 99.
Find the largest palindrome made from the product of two 3-digit numbers which
is less than N.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the largest palindrome made from the product of two 3-digit
numbers which is less than n.
@ -35,4 +27,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,14 +6,6 @@ to 10 without any remainder.
What is the smallest positive number that is evenly divisible(divisible with no
remainder) by all of the numbers from 1 to N?
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the smallest positive number that is evenly divisible(divisible
with no remainder) by all of the numbers from 1 to n.
@ -66,4 +58,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,13 +6,6 @@ to 10 without any remainder.
What is the smallest positive number that is evenly divisible(divisible with no
remainder) by all of the numbers from 1 to N?
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
""" Euclidean GCD Algorithm """
@ -47,4 +40,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -14,14 +14,6 @@ numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first N natural
numbers and the square of the sum.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the difference between the sum of the squares of the first n
natural numbers and the square of the sum.
@ -45,4 +37,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -14,14 +14,6 @@ numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first N natural
numbers and the square of the sum.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the difference between the sum of the squares of the first n
natural numbers and the square of the sum.
@ -42,4 +34,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -14,14 +14,8 @@ numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first N natural
numbers and the square of the sum.
"""
from __future__ import print_function
import math
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""Returns the difference between the sum of the squares of the first n
@ -42,4 +36,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,14 +6,8 @@ By listing the first six prime numbers:
We can see that the 6th prime is 13. What is the Nth prime number?
"""
from __future__ import print_function
from math import sqrt
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def isprime(n):
if n == 2:
@ -58,4 +52,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,14 +6,6 @@ By listing the first six prime numbers:
We can see that the 6th prime is 13. What is the Nth prime number?
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def isprime(number):
for i in range(2, int(number ** 0.5) + 1):
if number % i == 0:
@ -73,4 +65,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -6,15 +6,9 @@ By listing the first six prime numbers:
We can see that the 6th prime is 13. What is the Nth prime number?
"""
from __future__ import print_function
import math
import itertools
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def primeCheck(number):
if number % 2 == 0 and number > 2:
@ -50,4 +44,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -7,7 +7,6 @@ For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
from __future__ import print_function
def solution():

View File

@ -7,14 +7,6 @@ For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
from __future__ import print_function
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(n):
"""
Return the product of a,b,c which are Pythagorean Triplet that satisfies
@ -41,4 +33,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -10,9 +10,6 @@ For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
from __future__ import print_function
def solution():
"""
Returns the product of a,b,c which are Pythagorean Triplet that satisfies

Some files were not shown because too many files have changed in this diff Show More