AdventOfCode/2023/day4/part2.py

39 lines
735 B
Python

#!/bin/python3
import sys
from pprint import pprint
input_f = sys.argv[1]
arr = []
cards = []
result = 0
def calc_double(x):
tmp = 1
if len(x) <= 2:
return len(x)
for i in range(1,len(x)+1):
if i == 1:
tmp = 1
else:
tmp = tmp*2
return tmp
with open(input_f) as file:
for line in file:
tmp = line.replace(':','|').rstrip()
arr.append(tmp.split('|'))
for idx,i in enumerate(arr):
cards.append([])
for jdx,j in enumerate(i):
cards[idx].append(j.split())
for x in cards:
match = list(set(x[1]) & set(x[2]))
if len(match) != 0:
result = result + int(calc_double(match))
print(result)