-
Notifications
You must be signed in to change notification settings - Fork 0
/
day04.py
executable file
·37 lines (30 loc) · 1.16 KB
/
day04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from src.common.utils import SolverFunctions
title = 'Day 4: Camp Cleanup'
parser_method = 'str_strip'
handle_data = 'lines'
# find_range = lambda first, second: range(first, second + 1) # PEP8: E731
class SolveTheDay(SolverFunctions):
@staticmethod
def helper(first, second):
return range(first, second + 1)
@classmethod
def level_1(cls, data):
counter = 0
for each_pair in data:
first, second = each_pair.strip().split(',')
first = set(cls.helper(*map(int, first.split('-'))))
second = set(cls.helper(*map(int, second.split('-'))))
# if len(first - second) == 0 or len(second - first) == 0:
if first.issubset(second) or second.issubset(first):
counter += 1
return counter
@classmethod
def level_2(cls, data):
counter = 0
for each_pair in data:
first, second = each_pair.strip().split(',')
first = set(cls.helper(*map(int, first.split('-'))))
second = set(cls.helper(*map(int, second.split('-'))))
if len(first & second) > 0:
counter += 1
return counter