Fix project, now use python 3.

This commit is contained in:
Bert Peters
2015-12-14 00:29:02 +01:00
parent cf7d12fbf0
commit 0b94c1e7dc
14 changed files with 35 additions and 34 deletions

View File

@@ -12,6 +12,6 @@ for line in fileinput.input():
if not seenBasement and floor == -1: if not seenBasement and floor == -1:
seenBasement = True seenBasement = True
print "Basement reached at", idx + 1 print("Basement reached at", idx + 1)
print "Finally arrived at", floor print("Finally arrived at", floor)

View File

@@ -1,5 +1,6 @@
import fileinput import fileinput
from operator import mul from operator import mul
from functools import reduce
totalArea = 0 totalArea = 0
totalRibbon = 0 totalRibbon = 0
@@ -14,6 +15,6 @@ for line in fileinput.input():
totalRibbon += 2 * (parts[0] + parts[1]) totalRibbon += 2 * (parts[0] + parts[1])
totalRibbon += reduce(mul, parts, 1) totalRibbon += reduce(mul, parts, 1)
print totalArea, "paper" print(totalArea, "paper")
print totalRibbon, "ribbon" print(totalRibbon, "ribbon")

View File

@@ -25,4 +25,4 @@ for line in fileinput.input():
pos2 = move(pos2, c) pos2 = move(pos2, c)
places.add(pos2) places.add(pos2)
print "Houses:", len(places) print("Houses:", len(places))

View File

@@ -1,5 +1,5 @@
import sys import sys
import md5 from hashlib import md5
import fileinput import fileinput
def ok(digest, zeroes): def ok(digest, zeroes):
@@ -13,11 +13,11 @@ def solve(word, zeroes):
number = 0 number = 0
while True: while True:
digester = md5.new(word) digester = md5(word.encode("utf-8"))
digester.update(str(number)) digester.update(str(number).encode("utf-8"))
if ok(digester.hexdigest(), zeroes): if ok(digester.hexdigest(), zeroes):
print word, number print(word, number)
break break
number = number + 1 number = number + 1

View File

@@ -18,5 +18,5 @@ for line in fileinput.input():
if inbetween.search(line) and twodouble.search(line): if inbetween.search(line) and twodouble.search(line):
nice2 += 1 nice2 += 1
print nice1, "nice1 strings." print(nice1, "nice1 strings.")
print nice2, "nice2 strings." print(nice2, "nice2 strings.")

View File

@@ -14,7 +14,7 @@ for line in fileinput.input():
match = commandExpr.search(line) match = commandExpr.search(line)
if not match: if not match:
print "Invalid string" print("Invalid string")
sys.exit(1) sys.exit(1)
xStart = int(match.group(3)) xStart = int(match.group(3))
@@ -38,4 +38,4 @@ total = 0
for row in lights: for row in lights:
total += sum([int(i) for i in row]) total += sum([int(i) for i in row])
print total print(total)

View File

@@ -14,7 +14,7 @@ for line in fileinput.input():
match = commandExpr.search(line) match = commandExpr.search(line)
if not match: if not match:
print "Invalid string" print("Invalid string")
sys.exit(1) sys.exit(1)
xStart = int(match.group(3)) xStart = int(match.group(3))
@@ -38,4 +38,4 @@ total = 0
for row in lights: for row in lights:
total += sum(row) total += sum(row)
print total print(total)

View File

@@ -59,7 +59,7 @@ for line in fileinput.input():
a = findValue("a") a = findValue("a")
print "Initial a is ", a print("Initial a is ", a)
values = {} values = {}
values["b"] = a values["b"] = a
print "Secondary a is", findValue("a") print("Secondary a is", findValue("a"))

View File

@@ -26,5 +26,5 @@ for line in fileinput.input():
totalLess += diff totalLess += diff
totalMore += plus totalMore += plus
print totalLess, "less" print(totalLess, "less")
print totalMore, "more" print(totalMore, "more")

View File

@@ -59,5 +59,5 @@ for i in dist:
possible.append(shortest) possible.append(shortest)
possible.append(longest) possible.append(longest)
print "Shortest path is", min(possible) print("Shortest path is", min(possible))
print "Longest path is", max(possible) print("Longest path is", max(possible))

View File

@@ -8,9 +8,9 @@ line = "1321131112"
for x in range(40): for x in range(40):
line = lookandsay(line) line = lookandsay(line)
print "40:", len(line) print("40:", len(line))
for x in range(10): for x in range(10):
line = lookandsay(line) line = lookandsay(line)
print "50:", len(line) print("50:", len(line))

View File

@@ -1,6 +1,6 @@
import string import string
letters = [c for c in string.lowercase] letters = [c for c in string.ascii_lowercase]
password = "hxbxwxba" password = "hxbxwxba"
@@ -59,4 +59,4 @@ for x in range(2):
while not isOk(passwordCode): while not isOk(passwordCode):
increment(passwordCode) increment(passwordCode)
print "Next password is", ''.join([letters[c] for c in passwordCode]) print("Next password is", ''.join([letters[c] for c in passwordCode]))

View File

@@ -7,10 +7,10 @@ def totals(obj):
return obj return obj
if isinstance(obj, list): if isinstance(obj, list):
return sum(totals(i) for i in obj) return sum(totals(i) for i in obj)
if not isinstance(obj, dict) or "red" in obj.values(): if not isinstance(obj, dict) or "red" in list(obj.values()):
return 0 return 0
return sum(totals(i) for i in obj.values()) return sum(totals(i) for i in list(obj.values()))
fileData = ''.join(line for line in fileinput.input()) fileData = ''.join(line for line in fileinput.input())
@@ -20,4 +20,4 @@ total = sum(int(match) for match in pattern.findall(fileData))
data = json.loads(fileData) data = json.loads(fileData)
print total, totals(data) print(total, totals(data))

View File

@@ -25,7 +25,7 @@ maxHappiness = 0
maxWithMe = 0 maxWithMe = 0
# Compute happiness with everyone present # Compute happiness with everyone present
for permutation in permutations(ratings.keys()): for permutation in permutations(list(ratings.keys())):
happiness = 0 happiness = 0
withMe = 0 withMe = 0
@@ -46,5 +46,5 @@ for permutation in permutations(ratings.keys()):
maxWithMe = max(maxWithMe, withMe) maxWithMe = max(maxWithMe, withMe)
print maxHappiness, maxWithMe print(maxHappiness, maxWithMe)