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:

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()
    .map(|i| processed[i..i+window_size])

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:


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:


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