# Advent of Code 2021

**URL:** <https://discourse.julialang.org/t/advent-of-code-2021/72415>\
**Category:** General Usage\
**Created:** [December 1, 2021, 10:51pm UTC](https://discourse.julialang.org/t/advent-of-code-2021/72415 "2021-12-01T22:51:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevensonmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensonmt/32/31298_2.png) [@stevensonmt](https://discourse.julialang.org/u/stevensonmt)\
**Post date:** [December 1, 2021, 10:51pm UTC](https://discourse.julialang.org/t/advent-of-code-2021/72415/1 "2021-12-01T22:51:20Z")

</div>

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](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

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

```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [December 1, 2021, 11:26pm UTC](https://discourse.julialang.org/t/advent-of-code-2021/72415/2 "2021-12-01T23:26:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sashmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sashmit/32/18791_2.png) [@sashmit](https://discourse.julialang.org/u/sashmit)\
**Post date:** [December 2, 2021, 12:45am UTC](https://discourse.julialang.org/t/advent-of-code-2021/72415/3 "2021-12-02T00:45:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 2, 2021, 1:19am UTC](https://discourse.julialang.org/t/advent-of-code-2021/72415/4 "2021-12-02T01:19:21Z")

</div>

> [@stevensonmt](#):
>
> ```julia
> function get_input(path)
> Base.readlines(path)
> end
> 
> ```

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](https://github.com/Moelf/AoC2021/blob/main/day1.jl)

---

<div class="post-metadata">

**Author:** ![stevensonmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensonmt/32/31298_2.png) [@stevensonmt](https://discourse.julialang.org/u/stevensonmt)\
**Post date:** [December 2, 2021, 2:11am UTC](https://discourse.julialang.org/t/advent-of-code-2021/72415/5 "2021-12-02T02:11:46Z")

</div>

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