-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ardy
committed
Dec 7, 2022
1 parent
4b1972c
commit 0579a55
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,4 +127,4 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
**/problem.txt | ||
problem.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from helper import * | ||
|
||
# readString or readNumbers | ||
data_example = readStrings("./days/day_4/example.txt") | ||
data = readStrings("./days/day_4/problem.txt") | ||
|
||
def part1(data): | ||
sum = 0 | ||
for i, item in enumerate(data): | ||
item = item.split(",") | ||
l1 = int(item[0].split("-")[0]) | ||
l2 = int(item[0].split("-")[1]) | ||
r1 = int(item[1].split("-")[0]) | ||
r2 = int(item[1].split("-")[1]) | ||
|
||
if l1 <= r1 and l2 >= r2: | ||
sum += 1 | ||
elif r1 <= l1 and r2 >= l2: | ||
sum += 1 | ||
return sum | ||
|
||
|
||
def part2(data): | ||
sum = 0 | ||
for i, item in enumerate(data): | ||
item = item.split(",") | ||
l1 = int(item[0].split("-")[0]) | ||
l2 = int(item[0].split("-")[1]) | ||
r1 = int(item[1].split("-")[0]) | ||
r2 = int(item[1].split("-")[1]) | ||
|
||
if l1 <= r1 and l2 >= r2: | ||
sum += 1 | ||
elif r1 <= l1 and r2 >= l2: | ||
sum += 1 | ||
elif l1 <= r1 and l2 >= r1: | ||
sum += 1 | ||
elif l1 <= r2 and l1 >= r1: | ||
sum += 1 | ||
elif r1 <= l1 and r2 >= l1: | ||
sum += 1 | ||
elif r1 <= l2 and r1 >= l1: | ||
sum += 1 | ||
return sum | ||
|
||
print(part1(data_example), part2(data_example)) | ||
print(part1(data), part2(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |