[-] thirteen37@lemmy.world 2 points 2 weeks ago

I did wonder if that might be the case, I must have been lucky with my input.

[-] thirteen37@lemmy.world 2 points 2 weeks ago

Python

def process(input, part2=False):
    if part2:
        input = re.sub(r'don\'t\(\).+?do\(\)', '', input) # remove everything between don't() and do()
    total = [ int(i[0]) * int(i[1]) for i in re.findall(r'mul\((\d+),(\d+)\)', input) ]
    return sum(total)

Given the structure of the input file, we just have to ignore everything between don't() and do(), so remove those from the instructions before processing.

thirteen37

joined 1 year ago