Add some clarifying comments
This commit is contained in:
parent
1f22b34ae0
commit
4396cd68fc
@ -1,21 +1,20 @@
|
|||||||
from aocd import get_data
|
from aocd import get_data
|
||||||
data = get_data(day=1, year=2024)
|
data = get_data(day=1, year=2024)
|
||||||
|
|
||||||
|
# Condition data
|
||||||
list1 = []
|
list1 = []
|
||||||
list2 = []
|
list2 = []
|
||||||
lines = data.split("\n")
|
lines = data.split("\n")
|
||||||
for line in lines:
|
for line in lines:
|
||||||
nums = line.split(" ")
|
nums = line.split(" ")
|
||||||
num1 = int(nums[0])
|
num1 = int(nums[0])
|
||||||
num2 = int(nums[1])
|
num2 = int(nums[1])
|
||||||
list1.append(num1)
|
list1.append(num1)
|
||||||
list2.append(num2)
|
list2.append(num2)
|
||||||
list1.sort()
|
list1.sort()
|
||||||
list2.sort()
|
list2.sort()
|
||||||
|
|
||||||
# for i in range(len(list1)):
|
# Part 1
|
||||||
# print(list1[i], list2[i])
|
|
||||||
|
|
||||||
total_dist = 0
|
total_dist = 0
|
||||||
for i in range(len(list1)):
|
for i in range(len(list1)):
|
||||||
dist = list2[i] - list1[i]
|
dist = list2[i] - list1[i]
|
||||||
@ -24,6 +23,7 @@ for i in range(len(list1)):
|
|||||||
|
|
||||||
print("Total distance: ", total_dist)
|
print("Total distance: ", total_dist)
|
||||||
|
|
||||||
|
# Part 2
|
||||||
total_similarity = 0
|
total_similarity = 0
|
||||||
for i in range(len(list1)):
|
for i in range(len(list1)):
|
||||||
num = list1[i]
|
num = list1[i]
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from aocd import get_data
|
from aocd import get_data
|
||||||
data = get_data(day=2, year=2024)
|
data = get_data(day=2, year=2024)
|
||||||
|
|
||||||
|
# Condition data
|
||||||
lines = data.split("\n")
|
lines = data.split("\n")
|
||||||
reports = []
|
reports = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -10,6 +12,7 @@ for line in lines:
|
|||||||
total_safe = 0
|
total_safe = 0
|
||||||
safe_nums = [1, 2, 3]
|
safe_nums = [1, 2, 3]
|
||||||
|
|
||||||
|
# Part 1
|
||||||
for report in reports:
|
for report in reports:
|
||||||
dists = [report[i+1] - report[i] for i in range(len(report)) if i != len(report) - 1]
|
dists = [report[i+1] - report[i] for i in range(len(report)) if i != len(report) - 1]
|
||||||
# dists is either all positive or all negative (checks all increasing or all decreasing)
|
# dists is either all positive or all negative (checks all increasing or all decreasing)
|
||||||
@ -20,6 +23,7 @@ for report in reports:
|
|||||||
|
|
||||||
print("Total safe reports: ", total_safe)
|
print("Total safe reports: ", total_safe)
|
||||||
|
|
||||||
|
# Part 2
|
||||||
total_safe_tolerance = 0
|
total_safe_tolerance = 0
|
||||||
for report in reports:
|
for report in reports:
|
||||||
print("Checking report: ", report)
|
print("Checking report: ", report)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user