import sys
from dataclasses import dataclass, field

DEBUG = True
debug_padding = 24

def debug_print(printname, *args):
    if DEBUG:
        print(f"{'DEBUG::'+printname:<{debug_padding}}", *args)

def get_points(match_count):
    return 0 if match_count==0 else 2**(match_count-1)

@dataclass
class Card:
    card_no: int = 0
    match_count: int = 0
    #technically unneeded
    winning_numbers: set = field(default_factory=set)
    my_numbers: list = field(default_factory=list)



cards = []
total_points = 0

#print("Parsing Input:")
#print("")
#print("===================================\n");

FILENAME = "/home/icaema/Public/advent-of-code/day-04/data/p01data.txt"
f = open(FILENAME, "r")

#for line in sys.stdin:
for line in f.readlines():
    line = line[5:] #remove the "Card "
    #debug_print("input",  line)
    [card_number_side, given_number_side] = line.split(':')

    card_number = int(card_number_side)
    #debug_print("aaaa", f"cns: -{card_number}-;  gns: -{given_number_side}-")
    [winning_numbers,my_numbers] = given_number_side.split('|')

    winning_numbers = set(int(wn) for wn in winning_numbers.split())
    my_numbers = [int(mn) for mn in my_numbers.split()]
    match_count = len([x for x in my_numbers if x in winning_numbers])

    total_points += get_points(match_count)

    current_card = Card(card_number, match_count, winning_numbers, my_numbers)
    cards.append(current_card)
    #debug_print("parsed", current_card)




#print("")
#print(" Proccessing:")
#print("===================================\n");
# Insert Processing Code






#print("")
#print(" Calculate Answer:")
#print("===================================\n");






print("")
print(" Answer:")
print("===================================\n");
print(f"Answer: \n{total_points}");