Преглед изворни кода

Use 2to3 for initial conversion to Python 3

Adel Qalieh пре 12 година
родитељ
комит
a38b1292a0
50 измењених фајлова са 88 додато и 87 уклоњено
  1. 1 1
      1.py
  2. 1 1
      10.py
  3. 18 18
      11.py
  4. 1 1
      12.py
  5. 1 1
      13.py
  6. 1 1
      14.py
  7. 1 1
      15.py
  8. 1 1
      16.py
  9. 2 2
      18.py
  10. 1 1
      2.py
  11. 1 1
      20.py
  12. 1 1
      21.py
  13. 4 3
      211.py
  14. 2 2
      22.py
  15. 1 1
      24.py
  16. 1 1
      25.py
  17. 1 1
      28.py
  18. 1 1
      29.py
  19. 1 1
      3.py
  20. 1 1
      30.py
  21. 1 1
      31.py
  22. 3 3
      32.py
  23. 1 1
      33.py
  24. 1 1
      34.py
  25. 2 2
      35.py
  26. 1 1
      36.py
  27. 1 1
      37.py
  28. 1 1
      38.py
  29. 1 1
      39.py
  30. 1 1
      4.py
  31. 1 1
      40.py
  32. 1 1
      41.py
  33. 2 2
      42.py
  34. 3 3
      43.py
  35. 1 1
      45.py
  36. 1 1
      48.py
  37. 1 1
      49.py
  38. 1 1
      5.py
  39. 1 1
      55.py
  40. 2 2
      58.py
  41. 8 8
      59.py
  42. 1 1
      6.py
  43. 2 2
      63.py
  44. 2 2
      67.py
  45. 1 1
      7.py
  46. 1 1
      74.py
  47. 1 1
      8.py
  48. 1 1
      9.py
  49. 1 1
      92.py
  50. 1 1
      97.py

+ 1 - 1
1.py

@@ -2,4 +2,4 @@ summation = 0
 for i in range(1000):
 	if (i % 3 == 0) or (i % 5 == 0):
 		summation += i
-print summation
+print(summation)

+ 1 - 1
10.py

@@ -15,4 +15,4 @@ while primes[-1] < 2000000:
 		primes.append(i)
 
 primes.pop()
-print sum(primes)
+print(sum(primes))

+ 18 - 18
11.py

@@ -1,23 +1,23 @@
-grid = [[8, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 8],
-[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00],
-[81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65],
-[52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91],
+grid = [[8, 0o2, 22, 97, 38, 15, 00, 40, 00, 75, 0o4, 0o5, 0o7, 78, 52, 12, 50, 77, 91, 8],
+[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 0o4, 56, 62, 00],
+[81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 0o3, 49, 13, 36, 65],
+[52, 70, 95, 23, 0o4, 60, 11, 42, 69, 24, 68, 56, 0o1, 32, 56, 71, 37, 0o2, 36, 91],
 [22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80],
-[24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50],
+[24, 47, 32, 60, 99, 0o3, 45, 0o2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50],
 [32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70],
-[67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21],
-[24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72],
+[67, 26, 20, 68, 0o2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21],
+[24, 55, 58, 0o5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72],
 [21, 36, 23, 9, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95],
-[78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 9, 53, 56, 92],
-[16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57],
-[86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58],
-[19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40],
-[04, 52, 8, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66],
-[88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69],
-[04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36],
-[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16],
-[20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54],
-[01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48]]
+[78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 0o3, 80, 0o4, 62, 16, 14, 9, 53, 56, 92],
+[16, 39, 0o5, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57],
+[86, 56, 00, 48, 35, 71, 89, 0o7, 0o5, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58],
+[19, 80, 81, 68, 0o5, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 0o4, 89, 55, 40],
+[0o4, 52, 8, 83, 97, 35, 99, 16, 0o7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66],
+[88, 36, 68, 87, 57, 62, 20, 72, 0o3, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69],
+[0o4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36],
+[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 0o4, 36, 16],
+[20, 73, 35, 29, 78, 31, 90, 0o1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 0o5, 54],
+[0o1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 0o1, 89, 19, 67, 48]]
 
 def listproduct(quadlist):
 	product = 1
@@ -61,4 +61,4 @@ def diagleft(grid):
 				maxproduct = currentproduct
 	return maxproduct
 
-print max(vertproduct(grid), horizproduct(grid), diagright(grid), diagleft(grid))
+print(max(vertproduct(grid), horizproduct(grid), diagright(grid), diagleft(grid)))

+ 1 - 1
12.py

@@ -14,7 +14,7 @@ numgen = 1
 while True:
 	trianglenumber = numgen*(numgen+1)/2
 	if FindAllDivisors(trianglenumber) > 500:
-		print trianglenumber
+		print(trianglenumber)
 		break
 	else:
 		numgen += 1

+ 1 - 1
13.py

@@ -100,4 +100,4 @@ numlist = [
 20849603980134001723930671666823555245252804609722,
 53503534226472524250874054075591789781264330331690]
 
-print str(sum(numlist))[0:10]
+print(str(sum(numlist))[0:10])

+ 1 - 1
14.py

@@ -20,4 +20,4 @@ def main():
 			max = seq(i)
 	return maxnum
 
-print main()
+print(main())

+ 1 - 1
15.py

@@ -5,4 +5,4 @@ def combin(n, r):
 	return factorial(n) / (factorial(r) * factorial(n-r))
 
 # Number of paths in a m x n lattice given by combin(m+n, m)
-print combin(20 + 20, 20)
+print(combin(20 + 20, 20))

+ 1 - 1
16.py

@@ -2,4 +2,4 @@ num = str(2**1000)
 sum = 0
 for i in num:
 	sum += int(i)
-print sum
+print(sum)

+ 2 - 2
18.py

@@ -5,7 +5,7 @@ def loadTriangle():
 	f = open("18_triangle.txt", 'r')
 	triangle = f.read().split("\n")
 	for row in range(len(triangle)):
-		triangle[row] = map(int, triangle[row].split())
+		triangle[row] = list(map(int, triangle[row].split()))
 	return triangle
 
 def addBottom(triangle):
@@ -35,4 +35,4 @@ def main():
 		triangle = addBottom(triangle)
 	return triangle[0][0]
 
-print main()
+print(main())

+ 1 - 1
2.py

@@ -15,4 +15,4 @@ for i in range(33):
 	if fiblist[i] % 2 == 0:
 		summation += fiblist[i]
 
-print summation
+print(summation)

+ 1 - 1
20.py

@@ -6,4 +6,4 @@ sum = 0
 for i in num:
 	sum += int(i)
 
-print sum
+print(sum)

+ 1 - 1
21.py

@@ -18,4 +18,4 @@ for a in range(1,10000):
 	if d(a) == b and d(b) == a and b != 1 and a != b:
 		amicablesum += a
 
-print amicablesum
+print(amicablesum)

+ 4 - 3
211.py

@@ -1,4 +1,5 @@
 from math import sqrt
+from functools import reduce
 
 def appendEs2Sequences(sequences,es):
 	result=[]
@@ -37,7 +38,7 @@ def factorGenerator(n):
 def divisors(n):
 	factors = factorGenerator(n)
 	divisors=[]
-	listexponents=[map(lambda x:k**x,range(0,factors[k]+1)) for k in factors.keys()]
+	listexponents=[[k**x for x in range(0,factors[k]+1)] for k in list(factors.keys())]
 	listfactors=cartesianproduct(listexponents)
 	for f in listfactors:
 		divisors.append(reduce(lambda x, y: x*y, f, 1))
@@ -64,7 +65,7 @@ def main():
 	for i in range(1,64000000):
 		if is_square(o2(i)):
 			divsqsum += o2(i)
-			print o2(i)
-	print divsqsum
+			print(o2(i))
+	print(divsqsum)
 
 main()

+ 2 - 2
22.py

@@ -1,5 +1,5 @@
 import string
-letterscore = dict(zip(string.ascii_lowercase, range(1, 27)))
+letterscore = dict(list(zip(string.ascii_lowercase, list(range(1, 27)))))
 
 f = open("names.txt", "r")
 f = f.read()
@@ -18,4 +18,4 @@ for i in range(len(namelist)):
 		wordscore += letterscore[char]
 	namescoresum += (i + 1) * wordscore
 
-print namescoresum
+print(namescoresum)

+ 1 - 1
24.py

@@ -4,5 +4,5 @@ lexorder = 1
 
 for permutation in permutations("0123456789", 10):
 	if lexorder == 1000000:
-		print ''.join(permutation)
+		print(''.join(permutation))
 	lexorder += 1

+ 1 - 1
25.py

@@ -8,4 +8,4 @@ def fib(n):
 x = 0
 while len(str(fib(x))) < 1000:
 	x += 1
-print x
+print(x)

+ 1 - 1
28.py

@@ -1,6 +1,6 @@
 def main(by):
 	diagonal = (by+1)*0.5
-	print spiral(diagonal)
+	print(spiral(diagonal))
 
 def spiral(d):
 	if d == 1:

+ 1 - 1
29.py

@@ -5,4 +5,4 @@ for a in range(2,101):
 		if power not in powerlist:
 			powerlist.append(power)
 
-print len(powerlist)
+print(len(powerlist))

+ 1 - 1
3.py

@@ -13,4 +13,4 @@ def prime_factors(n):
 
 pfs = prime_factors(600851475143)
 largest_prime_factor = max(pfs)
-print largest_prime_factor
+print(largest_prime_factor)

+ 1 - 1
30.py

@@ -5,4 +5,4 @@ for number in range(1000000):
 		fifthsum += int(digit)**5
 	if fifthsum == number and number > 1 and number not in fifthlist:
 		fifthlist.append(number)
-print fifthlist
+print(fifthlist)

+ 1 - 1
31.py

@@ -24,4 +24,4 @@ for a in range(total, -1, -200):
 						for g in range(f, -1, -2):
 							ways += 1
 
-print ways
+print(ways)

+ 3 - 3
32.py

@@ -19,7 +19,7 @@ def main():
 				if isPandigital(str(i) + str(j) + str(product)):
 					if product not in productsList:
 						productsList.append(product)
-						print i,j,product
+						print(i,j,product)
 	
 	# Covers 1 digit * 4 digits
 	for i in range(2,9):
@@ -29,8 +29,8 @@ def main():
 				if isPandigital(str(i) + str(j) + str(product)):
 					if product not in productsList:
 						productsList.append(product)
-						print i,j,product
+						print(i,j,product)
 
 	return sum(productsList)
 
-print main()
+print(main())

+ 1 - 1
33.py

@@ -19,4 +19,4 @@ for num in range(10,100):
 				if Fraction(num,den) == Fraction(int(str(num)[0]) , int(str(den)[1])):
 					fractionsum *= Fraction(num,den)
 
-print fractionsum
+print(fractionsum)

+ 1 - 1
34.py

@@ -8,4 +8,4 @@ for num in range(3,100000):
 	if num == strsum:
 		factorialdigit.append(num)
 
-print sum(factorialdigit)
+print(sum(factorialdigit))

+ 2 - 2
35.py

@@ -19,7 +19,7 @@ def rotate(n):
 		rotationslist.append(rot)
 		rot = rot[-1] + rot[:-1]
 
-	return map(int,rotationslist)
+	return list(map(int,rotationslist))
 
 def isCircularPrime(n):
 	"""Returns boolean whether all rotations of digits are prime"""
@@ -41,4 +41,4 @@ def main(n):
 
 	return numberCircularPrimes
 
-print main(1000000)
+print(main(1000000))

+ 1 - 1
36.py

@@ -9,4 +9,4 @@ for i in range(1000000):
 		if palindrome(str(bin(i)[2::])):
 			doublebase.append(i)
 
-print sum(doublebase)
+print(sum(doublebase))

+ 1 - 1
37.py

@@ -37,4 +37,4 @@ while len(truncprimes) < 11:
 		truncprimes.append(numgen)
 	numgen += 1
 
-print sum(truncprimes)
+print(sum(truncprimes))

+ 1 - 1
38.py

@@ -33,4 +33,4 @@ for fixed in range(9000,10000):
 		if concatenatedProduct > maxProduct:
 			maxProduct = concatenatedProduct
 
-print maxProduct
+print(maxProduct)

+ 1 - 1
39.py

@@ -22,4 +22,4 @@ for i in range(1000):
 		bestpsolution = i
 		maxsolutions = numsolutions
 
-print bestpsolution
+print(bestpsolution)

+ 1 - 1
4.py

@@ -9,4 +9,4 @@ for i in range(1000):
 		if palindrome(product):
 			palindromelist.append(product)
 
-print max(palindromelist)
+print(max(palindromelist))

+ 1 - 1
40.py

@@ -5,4 +5,4 @@ while len(champ) < 1000010:
 	champ += str(concat)
 	concat += 1
 
-print int(champ[0]) * int(champ[9]) * int(champ[99]) * int(champ[999]) * int(champ[9999]) * int(champ[99999]) * int(champ[999999])
+print(int(champ[0]) * int(champ[9]) * int(champ[99]) * int(champ[999]) * int(champ[9999]) * int(champ[99999]) * int(champ[999999]))

+ 1 - 1
41.py

@@ -22,4 +22,4 @@ for i in permutations(digits, len(digits)):
 		if i > maxPrime:
 			maxPrime = i
 
-print maxPrime
+print(maxPrime)

+ 2 - 2
42.py

@@ -1,5 +1,5 @@
 import string
-letterscore = dict(zip(string.ascii_lowercase, range(1, 27)))
+letterscore = dict(list(zip(string.ascii_lowercase, list(range(1, 27)))))
 triangle = [x*(x+1)/2 for x in range(1000)]
 
 f = open("words.txt", "r")
@@ -20,4 +20,4 @@ for word in wordlist:
 	if wordscore in triangle:
 		trianglewords += 1
 
-print trianglewords
+print(trianglewords)

+ 3 - 3
43.py

@@ -8,11 +8,11 @@ for i in permutations(digits, 10):
 	i = ''.join(i)
 	
 	# Create list of all list triplets
-	divisibilityList = map(int, [i[1:4], i[2:5], i[3:6], i[4:7], i[5:8], i[6:9], i[7:10]])
+	divisibilityList = list(map(int, [i[1:4], i[2:5], i[3:6], i[4:7], i[5:8], i[6:9], i[7:10]]))
 
 	# Check for all divisibility rules
 	if divisibilityList[0] % 2 == 0 and divisibilityList[1] % 3 == 0 and divisibilityList[2] % 5 == 0 and divisibilityList[3] % 7 == 0 and divisibilityList[4] % 11 == 0 and divisibilityList[5] % 13 == 0 and divisibilityList[6] % 17 == 0:
 		substringDivisibility += int(i)
-		print i
+		print(i)
 
-print substringDivisibility
+print(substringDivisibility)

+ 1 - 1
45.py

@@ -9,4 +9,4 @@ def hex(n):
 pentset = set(pent(x) for x in range(50000))
 hexset = set(hex(x) for x in range(50000))
 
-print pentset & hexset
+print(pentset & hexset)

+ 1 - 1
48.py

@@ -2,4 +2,4 @@ series = 0
 for i in range(1,1000):
 	series += pow(i,i)
 
-print(str(series)[-10::])
+print((str(series)[-10::]))

+ 1 - 1
49.py

@@ -43,4 +43,4 @@ for sequence in midpointList:
 for i in permutationList:
 	for j in range(len(i)):
 		i[j] = str(i[j])
-	print "".join(i[:-1])
+	print("".join(i[:-1]))

+ 1 - 1
5.py

@@ -1 +1 @@
-print 2520 * 11 * 13 * 17 * 19 * 2
+print(2520 * 11 * 13 * 17 * 19 * 2)

+ 1 - 1
55.py

@@ -30,4 +30,4 @@ def main(limit):
 			numberLychrels += 1
 	return numberLychrels
 
-print main(10000)
+print(main(10000))

+ 2 - 2
58.py

@@ -41,5 +41,5 @@ while primeRatio > 0.10:
 	sideLen += 2
 
 # Adjust sidelength by 2
-print sideLen - 2
-print primeRatio
+print(sideLen - 2)
+print(primeRatio)

+ 8 - 8
59.py

@@ -1,4 +1,4 @@
-from itertools import product,cycle,izip
+from itertools import product,cycle
 
 def loadWords():
 	"""
@@ -7,10 +7,10 @@ def loadWords():
 	Depending on the size of the word list, this function may
 	take a while to finish.
 	"""
-	print "Loading word list from file..."
+	print("Loading word list from file...")
 	inFile = open("59_words.txt", 'r')
 	wordList = inFile.read().split()
-	print "  ", len(wordList), "words loaded."
+	print("  ", len(wordList), "words loaded.")
 	return wordList
 
 wordList = loadWords()
@@ -56,17 +56,17 @@ def ascii(cipherList):
 	for char in cipherList:
 		decryptedList.append(chr(int(char)))
 	
-	return "".join(map(chr, map(int, cipherList)))
+	return "".join(map(chr, list(map(int, cipherList))))
 
 def decrypt(key):
 	""" Decrypts story using given key using an XOR cipher """
 	data = ascii(getCipherList())
-	return "".join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))
+	return "".join(chr(ord(x) ^ ord(y)) for (x,y) in zip(data, cycle(key)))
 
 def asciisum(text):
 	""" Returns the sum of ASCII codes in a given string """
 	text = list(text)
-	text = map(ord, text)
+	text = list(map(ord, text))
 	return sum(text)
 
 def main():
@@ -78,7 +78,7 @@ def main():
 	The function returns the sum of the ASCII codes of the resulting decrypted
 	text.
 	"""
-	lowercase = map(chr, range(97, 123))
+	lowercase = list(map(chr, list(range(97, 123))))
 
 	# Generate a list of possible keys
 	keylist = []
@@ -97,4 +97,4 @@ def main():
 
 	return asciisum(decrypt(bestKey))
 
-print main()
+print(main())

+ 1 - 1
6.py

@@ -11,6 +11,6 @@ def sqsum(num):
 	return s**2
 
 def main(num):
-	print sqsum(num) - sumsq(num)
+	print(sqsum(num) - sumsq(num))
 
 main(100)

+ 2 - 2
63.py

@@ -18,7 +18,7 @@ for power in range(1,100):
 		# print "Bounds are from " + str(lowerbound) + " < x < " + str(upperbound)
 		
 		if currentpower >= lowerbound and currentpower < upperbound:
-			print counter**power
+			print(counter**power)
 			powerful += 1
 		counter += 1
-print powerful	
+print(powerful)	

+ 2 - 2
67.py

@@ -7,7 +7,7 @@ def loadTriangle():
 	f = open("67_triangle.txt", 'r')
 	triangle = f.read().split("\n")
 	for row in range(len(triangle)):
-		triangle[row] = map(int, triangle[row].split())
+		triangle[row] = list(map(int, triangle[row].split()))
 	return triangle
 
 def addBottom(triangle):
@@ -37,4 +37,4 @@ def main():
 		triangle = addBottom(triangle)
 	return triangle[0][0]
 
-print main()
+print(main())

+ 1 - 1
7.py

@@ -14,4 +14,4 @@ while len(primes) < 10001:
 	if prime(i):
 		primes.append(i)
 
-print i
+print(i)

+ 1 - 1
74.py

@@ -44,4 +44,4 @@ def main(limit):
 			numberFactorialChains += 1
 	return numberFactorialChains
 
-print main(1000000)
+print(main(1000000))

+ 1 - 1
8.py

@@ -8,4 +8,4 @@ productlist = []
 for digitpair in digitlist:
 	productlist.append(int(digitpair[0])*int(digitpair[1])*int(digitpair[2])*int(digitpair[3])*int(digitpair[4]))
 
-print max(productlist)
+print(max(productlist))

+ 1 - 1
9.py

@@ -15,4 +15,4 @@ for x in range(N):
 for triplet in pythlist:
 	tripsum = triplet[0] + triplet[1] + triplet[2]
 	if tripsum == 1000:
-		print triplet[0] * triplet[1] * triplet[2]
+		print(triplet[0] * triplet[1] * triplet[2])

+ 1 - 1
92.py

@@ -18,4 +18,4 @@ for i in range(1,10000000):
 	if digchain(i) == 89:
 		num89 += 1
 
-print num89
+print(num89)

+ 1 - 1
97.py

@@ -1 +1 @@
-print str(28433*(pow(2, 7830457, 10000000000))+1)[-10::]
+print(str(28433*(pow(2, 7830457, 10000000000))+1)[-10::])