mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 05:40:32 +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:
|
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)
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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.")
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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"))
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -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]))
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user