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.

Not difficult yet. Misread the problem per usual and sunk 20 minutes into a problem that didnt exist though.

Part 1

subSets = 0

elfAssignments = []

with open('input', 'r') as f:

for line in f:

    cur_pair = line.split(',')

    first_assign = range(int(cur_pair[0].split('-')[0]), int(cur_pair[0].split('-')[1])+1)

    second_assign = range(int(cur_pair[1].split('-')[0]), int(cur_pair[1].split('-')[1])+1)

    l1 = set(list(first_assign))

    l2 = set(list(second_assign))

    if (l1.issubset(l2)) or l2.issubset(l1):

        subSets += 1

print(subSets)

Part 2:

overlaps = 0

elfAssignments = []

with open('input', 'r') as f:

    for line in f:

        cur_pair = line.split(',')

        first_assign = range(int(cur_pair[0].split('-')[0]), int(cur_pair[0].split('-')[1])+1)

        second_assign = range(int(cur_pair[1].split('-')[0]), int(cur_pair[1].split('-')[1])+1)

        l1 = set(list(first_assign))

        l2 = set(list(second_assign))

        if not l1.isdisjoint(l2) or not l2.isdisjoint(l1):

            overlaps += 1

print(overlaps)
Jump in the discussion.

No email address required.



Now playing: Aquatic Ambience (A Hint of Blue remix) (DKC).mp3

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