We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ca3e11d commit 12fe606Copy full SHA for 12fe606
day4/day4.py
@@ -0,0 +1,26 @@
1
+# read input
2
+input = open('input.txt', 'r')
3
+lines = input.readlines()
4
+sectionOverlapIds = 0
5
+someOverlapIds = 0
6
+
7
+def firstToLast(str):
8
+ list = str.split('-')
9
+ return [x for x in range(int(list[0]), int(list[1]) + 1)]
10
11
+for line in lines:
12
+ line = line.split('\n')[0]
13
+ line = line.split(',')
14
+ firstStr = line[0]
15
+ secondStr = line[1]
16
+ firstList = firstToLast(firstStr)
17
+ secondList = firstToLast(secondStr)
18
+ if (all(item in firstList for item in secondList) or all(item in secondList for item in firstList)):
19
+ sectionOverlapIds = sectionOverlapIds + 1
20
+ if (any(item in firstList for item in secondList) or any(item in secondList for item in firstList)):
21
+ someOverlapIds = someOverlapIds + 1
22
23
+# part one
24
+print('Total overlapping section IDs: ', sectionOverlapIds)
25
+# part two
26
+print('Some overlapping section IDs: ', someOverlapIds)
day4/dummy.txt
@@ -0,0 +1,6 @@
+2-4,6-8
+2-3,4-5
+5-7,7-9
+2-8,3-7
+6-6,4-6
+2-6,4-8
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments