bjorng

bjorng

Erlang Core Team

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

First Post! Switch mode

bjorng

bjorng

Erlang Core Team

Here is my solution in Elixir:

https://github.com/bjorng/advent-of-code-2021/blob/2e585397128f38c3f249623b6392a73fd46e1b87/day01/lib/day01.ex

And over at the Erlang Forums is my solution in Erlang:

Most Liked

code-shoily

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_by and chunk_while-s document. Everytime something needs chunking, I reach out for chunk_by and end up using chunk or chunk_every
  • I had forgotten to use chunk_every’s :discard
  • Livebook + Advent of Code = Elixir is the best way to solve AoC.
Aetherus

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

josevalim

Creator of Elixir

My solutions for day 1 can be found here: https://github.com/josevalim/aoc/blob/main/2021/day-01.livemd

I used Livebook and I solved using different styles: enum, nx, and recursion. You can find the streaming here: Twitch

Last Post!

Where Next?

Trending in Challenges Top

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement