Skip to content

Commit

Permalink
franklin-update
Browse files Browse the repository at this point in the history
  • Loading branch information
rdboyes committed Dec 1, 2024
1 parent 00d90bd commit 38b957e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions posts/adventofcode2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,30 @@ Unlike last year's first week, Day 1 is nice and easy.
```julia
using TidierFiles
using TidierData
using DataFrames

df = read_csv("data/1.txt", col_names = false, delim = " ")

println("Part 1: $(sum(abs.(sort(df.Column1) .- sort(df.Column2))))")
p1 = @chain DataFrame(c1 = sort(df.Column1), c2 = sort(df.Column2)) begin
@mutate(diff = abs(c1 - c2))
@pull(diff)
sum
end

println("Part 1: $p1")

p2 = @chain df begin
@aside c1 = @count(_, Column1)
@count(Column2)
@rename(n_1 = n)
@left_join(c1, "Column2" = "Column1")
@mutate(sim_score = Column2 * n * n_1)
@summarize(sum = sum(skipmissing(sim_score)))
@filter(!ismissing(sim_score))
@pull(sim_score)
sum
end

print("Part 2: $(p2[1,1])")
print("Part 2: $p2")
```

Not much to say about Part 1. Independently sorting columns not really a useful operation on a DataFrame usually so the support for it in Tidier is non-existent as far as I can tell, and I think that's a good thing.
Expand Down

0 comments on commit 38b957e

Please sign in to comment.