DEV Community

Discussion on: AoC Day 2: Inventory Management System

Collapse
 
rpalo profile image
Ryan Palo

Nice! Don’t forget about collections.Counter for part 1! I didn’t know about difflib though. Cool!

Collapse
 
lschultebraucks profile image
Lasse Schultebraucks

Thanks for the hint! Will do that later!

Thread Thread
 
lschultebraucks profile image
Lasse Schultebraucks
def part_one():
    word_twice_count = 0
    word_three_times_count = 0

    with open('input.txt', 'r') as input_file:
        for line in input_file:
            line_counter = Counter(line)
            if 2 in line_counter.values():
                word_twice_count += 1
            if 3 in line_counter.values():
                word_three_times_count += 1

    checksum = word_twice_count * word_three_times_count

    print 'checksum is ' + str(checksum)

My edited solution for part one with collections Counter