Unable to load image

Advent of code day 4 :marseysad:

This is the advent of code day 4 thread for bragging about your solution and bullying people who haven't gotten it yet :marseyill:

35
Jump in the discussion.

No email address required.

with range and set its easy. Don't care about performance

with open('input04.txt') as file:
    lines = [line.split(',') for line in file]

# a and b
count_a = 0
count_b = 0
for pair in lines:
    lower,upper = pair[0].split('-')
    id_set_1 = set(range(int(lower),int(upper)+1))
    lower,upper = pair[1].split('-')
    id_set_2 = set(range(int(lower),int(upper)+1))
    if id_set_1.issubset(id_set_2) or id_set_1.issuperset(id_set_2): # a
        count_a += 1
    if len(id_set_1.intersection(id_set_2)) > 0: # b
        count_b += 1
print("Part a:", count_a)
print("Part b:", count_b)
Jump in the discussion.

No email address required.

sets in python are so unoptimized it's hilarious how slow they are in basically anything

Jump in the discussion.

No email address required.



Now playing: Welcome to Crocodile Isle (DKC2).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.