bjorng
Advent of Code 2021 - Day 1
This topic is about Day 1 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums):
https://adventofcode.com/2021/leaderboard/private/view/370884
The entry code is:
370884-a6a71927
Most Liked
code-shoily
Here’s mine:
advent_of_code/day_01.ex at master · code-shoily/advent_of_code (github.com)
Observations:
- Though wasn’t applicable, but had a re-read of
chunk_byandchunk_while-s document. Everytime something needs chunking, I reach out forchunk_byand end up usingchunkorchunk_every - I had forgotten to use
chunk_every's:discard - Livebook + Advent of Code = Elixir is the best way to solve AoC.
Aetherus
My solution using chunk_every/4
Part 1
#!/usr/bin/env elixir
File.stream!("input.txt")
|> Stream.map(&String.trim/1)
|> Stream.map(&String.to_integer/1)
|> Stream.chunk_every(2, 1, :discard)
|> Enum.count(fn [a, b] -> a < b end)
|> IO.inspect()
Part 2
#!/usr/bin/env elixir
File.stream!("input.txt")
|> Stream.map(&String.trim/1)
|> Stream.map(&String.to_integer/1)
|> Stream.chunk_every(3, 1, :discard)
|> Stream.map(&Enum.sum/1)
|> Stream.chunk_every(2, 1, :discard)
|> Enum.count(fn [a, b] -> a < b end)
|> IO.inspect()
josevalim
My solutions for day 1 can be found here: aoc/day-01.livemd at main · josevalim/aoc · GitHub
I used Livebook and I solved using different styles: enum, nx, and recursion. You can find the streaming here: Twitch
stevensonmt
TIL Enum.zip_reduce/3
def parse(path) do
File.stream!(path)
|> Enum.map(&String.trim(&1))
|> Enum.map(&String.to_integer(&1))
end
def depth_increment_count(input, step \\ 1) do
Enum.zip_reduce([input, Enum.drop(input, step)], 0, fn [a, b], acc ->
if b > a do
acc + 1
else
acc
end
end)
end
def trios_increment(input) do
depth_increment_count(input, 3)
end
Edited for DRYing.
stevensonmt
In comparison of A1 + A2 + A3 and B1 + B2 + B3 you really only compare A1 and B3 b/c A2 == B1 and A3 == B2. I think that counts as “non brute force”.







