Compare commits
No commits in common. "4dcc750416e3725ef000cda835e671c17036675a" and "016a92f3cde738d96759db35befd518fe884d9ce" have entirely different histories.
4dcc750416
...
016a92f3cd
3 changed files with 20 additions and 60 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
*.in
|
||||
*.ex*
|
35
day02.py
35
day02.py
|
@ -1,35 +0,0 @@
|
|||
import fileinput
|
||||
from functools import reduce
|
||||
|
||||
def main():
|
||||
part1 = 0
|
||||
part2 = 0
|
||||
|
||||
for i, line in enumerate(fileinput.input()):
|
||||
line = line.strip()
|
||||
subsets = line.split(": ")[1].split("; ")
|
||||
|
||||
maxes = {}
|
||||
|
||||
part1_possible = True
|
||||
for subset in subsets:
|
||||
for balls in subset.split(", "):
|
||||
count, color = balls.split()
|
||||
count = int(count)
|
||||
maxes[color] = max(maxes.get(color, 0), count)
|
||||
part1_possible = (
|
||||
part1_possible
|
||||
and (color != "red" or count <= 12)
|
||||
and (color != "green" or count <= 13)
|
||||
and (color != "blue" or count <= 14)
|
||||
)
|
||||
|
||||
if part1_possible:
|
||||
part1 += i + 1
|
||||
|
||||
power = reduce(lambda x, y: x * y, maxes.values())
|
||||
part2 += power
|
||||
|
||||
print(part1, part2)
|
||||
|
||||
main()
|
43
day04.py
43
day04.py
|
@ -1,27 +1,24 @@
|
|||
import fileinput
|
||||
|
||||
def main():
|
||||
#
|
||||
# Part 1
|
||||
#
|
||||
cards = []
|
||||
part1 = 0
|
||||
for line in fileinput.input():
|
||||
card = line.split(": ", 1)[1]
|
||||
(winning, owned) = ({int(i) for i in h.split()} for h in card.split(" | ", 1))
|
||||
count = len(winning & owned)
|
||||
cards.append(count)
|
||||
part1 += 1 << count - 1 if count else 0
|
||||
#
|
||||
# Part 1
|
||||
#
|
||||
cards = []
|
||||
part1 = 0
|
||||
for i, line in enumerate(fileinput.input()):
|
||||
card = line.rstrip().split(": ")[1]
|
||||
(winning, owned) = ({int(i) for i in h.split()} for h in card.split(" | "))
|
||||
count = len(winning & owned)
|
||||
cards.append(count)
|
||||
part1 += 1 << count - 1 if count else 0
|
||||
|
||||
#
|
||||
# Part 2
|
||||
#
|
||||
dp = [0] * len(cards)
|
||||
part2 = 0
|
||||
for i in range(len(cards)):
|
||||
dp[i] = 1 + sum(dp[i - cards[-i - 1] : i])
|
||||
part2 += dp[i]
|
||||
#
|
||||
# Part 2
|
||||
#
|
||||
dp = [0] * len(cards)
|
||||
part2 = 0
|
||||
for i in range(len(cards)):
|
||||
dp[i] = 1 + sum(dp[i - cards[-i - 1] : i])
|
||||
part2 += dp[i]
|
||||
|
||||
print(part1, part2)
|
||||
|
||||
main()
|
||||
print(part1, part2)
|
||||
|
|
Loading…
Reference in a new issue