Advent of Code 2021

Didn’t find a thread for Advent of Code 2021. This year I thought I’d use it to kickstart learning Julia. I plan to solve the exercises in Elixir and Julia. Last year I didn’t make it through to the end, hopefully this year goes better.

Here’s my Julia solution for Day 1:
https://github.com/stevensonmt/advent_of_code/blob/ad011c614a2d35d54d41a8bdc3f1ee63b346a097/2021/day1/julia/day1.jl

I would appreciate any tips on improving my code both programatically and idiomatically for Julia. Also, if anyone can explain the use of @view to generate the sliding window function I’d appreciate it. My intuitive understanding is that it could be written in Rust as something like

1..(length(processed) - window_size + step).iter()
    .step_by(step)
    .map(|i| processed[i..i+window_size])
    .collect()

A view gives a subarray backed by the original array without a copy. It’s like a slice in Go or Python. The Python syntax for slicing makes a copy in Julia.

1 Like

There is a pretty active AoC stream on julia zulip:
https://julialang.zulipchat.com/#narrow/stream/307139-advent-of-code-.282021.29

3 Likes

my “rule” is don’t define function if it’s as long as the original thing, also you don’t need Base here

Here’s my take on Day1:
https://github.com/Moelf/AoC2021/blob/main/day1.jl

2 Likes

I was just reading your post on the zulip channel. :slight_smile: Your solution is very clever. Thanks for sharing and for the style tip.

1 Like