You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
863 B
Python
39 lines
863 B
Python
file = open("in.txt", "r")
|
|
|
|
lns = file.readlines()
|
|
|
|
def p1():
|
|
count = 0
|
|
for i in range(1, len(lns)):
|
|
if int(lns[i]) >= int(lns[i-1]):
|
|
count += 1
|
|
return count
|
|
|
|
def p2():
|
|
count = 0
|
|
sets = []
|
|
for i in range(len(lns)):
|
|
if i + 3 > len(lns):
|
|
continue
|
|
temp = [None] * 3
|
|
temp[0] = lns[i]
|
|
temp[1] = lns[i+1]
|
|
temp[2] = lns[i+2]
|
|
if len(sets) == 0:
|
|
index = 0
|
|
else:
|
|
index = len(sets) + 1
|
|
sets.append(temp)
|
|
|
|
for i in range(1, len(sets)):
|
|
set1 = sets[i]
|
|
set2 = sets[i-1]
|
|
sum1 = int(set1[0]) + int(set1[1]) + int(set1[2])
|
|
sum2 = int(set2[0]) + int(set2[1]) + int(set2[2])
|
|
if sum1 > sum2:
|
|
count += 1
|
|
|
|
return count
|
|
|
|
print(f"part 1: {p1()}")
|
|
print(f"part 2: {p2()}") |