mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Fix project, now use python 3.
This commit is contained in:
@@ -12,6 +12,6 @@ for line in fileinput.input():
|
||||
|
||||
if not seenBasement and floor == -1:
|
||||
seenBasement = True
|
||||
print "Basement reached at", idx + 1
|
||||
print("Basement reached at", idx + 1)
|
||||
|
||||
print "Finally arrived at", floor
|
||||
print("Finally arrived at", floor)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fileinput
|
||||
from operator import mul
|
||||
from functools import reduce
|
||||
|
||||
totalArea = 0
|
||||
totalRibbon = 0
|
||||
@@ -14,6 +15,6 @@ for line in fileinput.input():
|
||||
totalRibbon += 2 * (parts[0] + parts[1])
|
||||
totalRibbon += reduce(mul, parts, 1)
|
||||
|
||||
print totalArea, "paper"
|
||||
print totalRibbon, "ribbon"
|
||||
print(totalArea, "paper")
|
||||
print(totalRibbon, "ribbon")
|
||||
|
||||
|
||||
@@ -25,4 +25,4 @@ for line in fileinput.input():
|
||||
pos2 = move(pos2, c)
|
||||
places.add(pos2)
|
||||
|
||||
print "Houses:", len(places)
|
||||
print("Houses:", len(places))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
import md5
|
||||
from hashlib import md5
|
||||
import fileinput
|
||||
|
||||
def ok(digest, zeroes):
|
||||
@@ -11,15 +11,15 @@ def ok(digest, zeroes):
|
||||
|
||||
def solve(word, zeroes):
|
||||
number = 0
|
||||
|
||||
|
||||
while True:
|
||||
digester = md5.new(word)
|
||||
digester.update(str(number))
|
||||
|
||||
digester = md5(word.encode("utf-8"))
|
||||
digester.update(str(number).encode("utf-8"))
|
||||
|
||||
if ok(digester.hexdigest(), zeroes):
|
||||
print word, number
|
||||
print(word, number)
|
||||
break
|
||||
|
||||
|
||||
number = number + 1
|
||||
|
||||
for line in fileinput.input():
|
||||
|
||||
@@ -18,5 +18,5 @@ for line in fileinput.input():
|
||||
if inbetween.search(line) and twodouble.search(line):
|
||||
nice2 += 1
|
||||
|
||||
print nice1, "nice1 strings."
|
||||
print nice2, "nice2 strings."
|
||||
print(nice1, "nice1 strings.")
|
||||
print(nice2, "nice2 strings.")
|
||||
|
||||
@@ -14,7 +14,7 @@ for line in fileinput.input():
|
||||
match = commandExpr.search(line)
|
||||
|
||||
if not match:
|
||||
print "Invalid string"
|
||||
print("Invalid string")
|
||||
sys.exit(1)
|
||||
|
||||
xStart = int(match.group(3))
|
||||
@@ -38,4 +38,4 @@ total = 0
|
||||
for row in lights:
|
||||
total += sum([int(i) for i in row])
|
||||
|
||||
print total
|
||||
print(total)
|
||||
|
||||
@@ -14,7 +14,7 @@ for line in fileinput.input():
|
||||
match = commandExpr.search(line)
|
||||
|
||||
if not match:
|
||||
print "Invalid string"
|
||||
print("Invalid string")
|
||||
sys.exit(1)
|
||||
|
||||
xStart = int(match.group(3))
|
||||
@@ -38,4 +38,4 @@ total = 0
|
||||
for row in lights:
|
||||
total += sum(row)
|
||||
|
||||
print total
|
||||
print(total)
|
||||
|
||||
@@ -59,7 +59,7 @@ for line in fileinput.input():
|
||||
|
||||
a = findValue("a")
|
||||
|
||||
print "Initial a is ", a
|
||||
print("Initial a is ", a)
|
||||
values = {}
|
||||
values["b"] = a
|
||||
print "Secondary a is", findValue("a")
|
||||
print("Secondary a is", findValue("a"))
|
||||
|
||||
@@ -26,5 +26,5 @@ for line in fileinput.input():
|
||||
totalLess += diff
|
||||
totalMore += plus
|
||||
|
||||
print totalLess, "less"
|
||||
print totalMore, "more"
|
||||
print(totalLess, "less")
|
||||
print(totalMore, "more")
|
||||
|
||||
@@ -59,5 +59,5 @@ for i in dist:
|
||||
possible.append(shortest)
|
||||
possible.append(longest)
|
||||
|
||||
print "Shortest path is", min(possible)
|
||||
print "Longest path is", max(possible)
|
||||
print("Shortest path is", min(possible))
|
||||
print("Longest path is", max(possible))
|
||||
|
||||
@@ -8,9 +8,9 @@ line = "1321131112"
|
||||
for x in range(40):
|
||||
line = lookandsay(line)
|
||||
|
||||
print "40:", len(line)
|
||||
print("40:", len(line))
|
||||
|
||||
for x in range(10):
|
||||
line = lookandsay(line)
|
||||
|
||||
print "50:", len(line)
|
||||
print("50:", len(line))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import string
|
||||
|
||||
letters = [c for c in string.lowercase]
|
||||
letters = [c for c in string.ascii_lowercase]
|
||||
|
||||
password = "hxbxwxba"
|
||||
|
||||
@@ -58,5 +58,5 @@ for x in range(2):
|
||||
increment(passwordCode)
|
||||
while not isOk(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]))
|
||||
|
||||
@@ -7,10 +7,10 @@ def totals(obj):
|
||||
return obj
|
||||
if isinstance(obj, list):
|
||||
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 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())
|
||||
|
||||
@@ -20,4 +20,4 @@ total = sum(int(match) for match in pattern.findall(fileData))
|
||||
|
||||
data = json.loads(fileData)
|
||||
|
||||
print total, totals(data)
|
||||
print(total, totals(data))
|
||||
|
||||
@@ -25,7 +25,7 @@ maxHappiness = 0
|
||||
maxWithMe = 0
|
||||
|
||||
# Compute happiness with everyone present
|
||||
for permutation in permutations(ratings.keys()):
|
||||
for permutation in permutations(list(ratings.keys())):
|
||||
happiness = 0
|
||||
withMe = 0
|
||||
|
||||
@@ -46,5 +46,5 @@ for permutation in permutations(ratings.keys()):
|
||||
maxWithMe = max(maxWithMe, withMe)
|
||||
|
||||
|
||||
print maxHappiness, maxWithMe
|
||||
print(maxHappiness, maxWithMe)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user