adventofcode/2023/day4/main.py
2023-12-04 15:44:00 +01:00

32 lines
737 B
Python

def part1(file: str):
with open(file) as f:
array = []
for line in f:
tmp = []
for el in [i.split(" ") for i in line.split(":")[1].split("|")]:
tmp.append([int(it) for it in el if len(it) > 0])
array.append(tmp)
total = 0
for card in array:
num_matches = len(set(card[0]) & set(card[1]))
if num_matches > 0:
total += 2 ** (num_matches - 1)
return total
def part2(file: str):
with open(file) as f:
for line in f:
pass
return 0
if __name__ == "__main__":
assert part1("example.txt") == 13
print(part1("input.txt"))
assert part2("example.txt") == 30
print(part2("input.txt"))