Apparently I only attempt do Advent of Code every other year. I had this vague thought about doing this thing in JavaScript this year, but considering I am way better at Python than JS, and I have yet to actually complete one of these 100%, i should stick with what am good-ish at.
The early day are always stupid easy. It’s usually around halfway they have some super goofy and hard problem that I get stuck on. The main change this year is doing it through the Bash terminal. Though I think I did it this way in 2020. I may swap later, who knows. The only real annoyance is opening and closing files to test run.
I also have not done a lot of coding in a while, so I had to search up on how to do a few things. It was a good starter scenario though, it used a lot of things I have forgotten.
I don’t do anything super fancy with my code on these, I have seen some annoyingly unreadable one liners a few times. I always prefer clean code. The thing runs in essentially zero time anyway, I don’t need to be “milliseconds more efficient”.
Anyway, here is my solution for part 1 and 2 of Day 1.
with open("Day01Input.txt") as file:
data = file.read()
sets = [each.split(" ") for each in data.split("\n")]
sets.pop()
list1 = []
list2 = []
for each in sets:
list1.append(int(each[0]))
list2.append(int(each[1]))
list1.sort()
list2.sort()
total = 0
total2 = 0
for i in range(len(list1)):
total += abs(list1[i]-list2[i])
total2 += list1[i]*list2.count(list1[i])
print(total)
print(total2)
Josh Miller aka “Ramen Junkie”. I write about my various hobbies here. Mostly coding, photography, and music. Sometimes I just write about life in general. I also post sometimes about toy collecting and video games at Lameazoid.com.
Comments are closed.
Mentions