Compare commits
2 Commits
e72d8fa268
...
de49850989
| Author | SHA1 | Date | |
|---|---|---|---|
| de49850989 | |||
| 4ae0d2af7b |
33
04/d.py
Normal file
33
04/d.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
|
||||
pairs = open(os.path.dirname(__file__) +
|
||||
"/input.txt", "r").read().splitlines()
|
||||
|
||||
tot1 = 0
|
||||
tot2 = 0
|
||||
|
||||
for p in pairs:
|
||||
a = p.split(",")
|
||||
|
||||
arrays = []
|
||||
|
||||
for i in range(0, len(a), 1):
|
||||
b = a[i].split("-")
|
||||
|
||||
if b[0] == b[1]:
|
||||
arrays.append([int(b[0])])
|
||||
continue
|
||||
arrays.append(range(int(b[0]), int(b[1])+1))
|
||||
|
||||
set_a = set(arrays[0])
|
||||
set_b = set(arrays[1])
|
||||
|
||||
if (set_a.issubset(set_b) or set_b.issubset(set_a)):
|
||||
tot1 += 1
|
||||
|
||||
if (set_a.intersection(set_b)):
|
||||
tot2 += 1
|
||||
|
||||
|
||||
print("First answer: " + str(tot1))
|
||||
print("Second answer: " + str(tot2))
|
||||
Reference in New Issue
Block a user