day4 part1 complete.
This commit is contained in:
1000
day4/input.txt
Normal file
1000
day4/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
15
day4/part1.py
Normal file
15
day4/part1.py
Normal file
@@ -0,0 +1,15 @@
|
||||
input = open("./input.txt", "r")
|
||||
|
||||
total = 0
|
||||
|
||||
for line in input:
|
||||
trimmedLine = line.replace("\n", "")
|
||||
elves = trimmedLine.split(",")
|
||||
elf1 = elves[0].split("-")
|
||||
elf2 = elves[1].split("-")
|
||||
if (int(elf1[0]) <= int(elf2[0]) and int(elf1[1]) >= int(elf2[1])):
|
||||
total += 1
|
||||
elif (int(elf2[0]) <= int(elf1[0]) and int(elf2[1]) >= int(elf1[1])):
|
||||
total += 1
|
||||
|
||||
print(total)
|
||||
18
day4/part2.py
Normal file
18
day4/part2.py
Normal file
@@ -0,0 +1,18 @@
|
||||
input = open("./test.txt", "r")
|
||||
|
||||
total = 0
|
||||
|
||||
for line in input:
|
||||
trimmedLine = line.replace("\n", "")
|
||||
elves = trimmedLine.split(",")
|
||||
elf1 = elves[0].split("-")
|
||||
elf1 = [int(elf1[0]), int(elf1[1])]
|
||||
elf2 = elves[1].split("-")
|
||||
elf2 = [int(elf2[0]), int(elf2[1])]
|
||||
if (elf1[0] <= elf2[0] and elf1[1] >= elf2[1]):
|
||||
total += 1
|
||||
elif (elf2[0] <= elf1[0] and elf2[1] >= elf1[1]):
|
||||
total += 1
|
||||
elif(elf1[0] >= elf2[0] or elf)
|
||||
|
||||
print(total)
|
||||
6
day4/test.txt
Normal file
6
day4/test.txt
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user