
September 10th, 2025
Day 1.0
I wanted to refresh my Julia skills, so I decided to do the Advent of Code 2024 challenge. I figured I'd start with Day 1, and see how it goes. The first part of the challenge is to find the sum of the distances between a pair of numbers. The user is provdided a text file with a pair of numbers on each line, and the task is to calculate the sum of the distances between each pair. The tricky part is that you must sort the left and right numbers so they pairs are in ascending order before calculating the distance.
My initial idea was to read the file using readlines, then split the lines into numbers in separate lists leftNums
and rightNums
. Then I sort each list, and iterate through the lists using zip, calculating the distance between each pair and summing them up. I used a function distCalc
, as I'm not the biggest fan of using global values, coming from Python. Here's my initial code:
using Pkg Pkg.activate(".") lines = readlines("./input/day1.txt") leftNums, rightNums = Vector{Int}(), Vector{Int}() for line in lines numbers = split(line) push!(leftNums, parse(Int64, numbers[1])) push!(rightNums, parse(Int64, numbers[2])) end sort!(leftNums) sort!(rightNums) function distCalc(leftNums, rightNums) dist = 0 for (leftNum, rightNum) in zip(leftNums, rightNums) dist += abs(leftNum - rightNum) end return dist end totalDist = distCalc(leftNums, rightNums) println("Day 1.0: $totalDist")
This code worked well, and I got the correct answer for Day 1.0. This opened up the second half of the problem, Day 1.5.
Day 1.5
The second half of the problem builds on the first half, but adds a bit more difficulty. This part asks the user to calculate a total similarity score by adding up each number in the left list after multiplying it by the number of times that number appears in the right list. Luckily, I could use the leftNums
and rightNums
lists, and just iterate through leftNums
, and add to total similarity score by multiplying the number by the count of that number in rightNums
. Here's my code for Day 1.5:
function countSim(leftNums, rightNums) simScore = 0 for leftNum in leftNums simScore += leftNum * count(rightNums .== leftNum) end return simScore end simScore = countSim(leftNums, rightNums) println("Day 1.5: $simScore")
Conclusions
I had fun working on this, and plan to continue working my way through AoC24; its been a while since I've done any real coding in Julia, and this is a great way to refresh my skills, so I'll prolly continue working through the problems, and posting them here, just no promises on how often. My code can be found on my GitHub in this repo.