-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4.py
53 lines (43 loc) · 1.24 KB
/
day4.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# opening the file in read mode
my_file = open("data.txt", "r")
# reading the file
data = my_file.read()
# replacing end splitting the text
# when newline ('\n') is seen.
data = data.split("\n")
my_file.close()
def star_1():
count = 0
for line in data:
pairs = line.split(",")
sections = []
for elf in pairs:
limits = elf.split("-")
indv = []
for i in range(int(limits[0]), int(limits[1]) + 1):
indv.append(i)
sections.append(indv)
#print(sections)
same = list(set(sections[0]).intersection(sections[1]))
if len(same) == len(sections[0]) or len(same) == len(sections[1]):
count += 1
sections = []
print(count)
def star_2():
count = 0
for line in data:
pairs = line.split(",")
sections = []
for elf in pairs:
limits = elf.split("-")
indv = []
for i in range(int(limits[0]), int(limits[1]) + 1):
indv.append(i)
sections.append(indv)
# print(sections)
same = list(set(sections[0]).intersection(sections[1]))
if len(same) > 0:
count += 1
sections = []
print(count)
star_2()