woolfred

woolfred

Advent of Code 2022 - Day 1

It is that time of the year again: Advent of Code 2022 :christmas_tree:

Day 1

Leaderboard:

Most Liked

woolfred

woolfred

Here is my first attempt, which uses specific reduces for the task at hand: advent-of-code/elixir/lib/aoc22/day01.ex at b4357a22f3a53bb46e4a98852eef4049ab1b1ec6 · woolfred/advent-of-code · GitHub

Afterwards I refactored it a bit, which makes it less efficient for Part 1, but favours readability:
https://github.com/woolfred/advent-of-code/blob/master/elixir/lib/aoc22/day01.ex

egze

egze

There is a leaderboard from last year that we can reuse. (shared with users of Erlang Forums ) /cc @bjorng

https://adventofcode.com/2022/leaderboard/private/view/370884

The entry code is:
370884-a6a71927

pesnk

pesnk

I used a very naive approach, I believe using chunk can turn out to be a better solution

Part 1

String.split(input, "\n\n")
|> Stream.map(fn(x) ->
  String.split(x)
  |> Stream.map(&String.to_integer/1)
  |> Enum.sum()
end)
|> Enum.max()

Part 2

String.split(input, "\n\n")
|> Stream.map(fn(x) ->
  String.split(x)
  |> Stream.map(&String.to_integer/1)
  |> Enum.sum()
end)
|> Enum.sort(:desc)
|> Stream.take(3)
|> Enum.sum()

Where Next?

Popular in Challenges Top

bjorng
This topic is about Day 17 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
stevensonmt
Reasonably pleased with my solution. The bitstring packet problems are so well suited to Erlang/Elixir it’s almost not fair. defmodule D...
New
bjorng
This topic is about Day 18 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
bjorng
This topic is about Day 16 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums): https://adve...
New
sb8244
Note: This topic is to talk about Day 10 of the Advent of Code 2019 . There is a private leaderboard for elixirforum members. You can jo...
New
bjorng
Here is my solution: https://github.com/bjorng/advent-of-code-2021/blob/77bdef7a51b428b58ffb4ab76f540901e636f841/day12/lib/day12.ex
New
Aetherus
Today’s problem is really tense. I don’t think I can do it without libgraph.
New
liamcmitchell
A frustrating one for me. I spent a long time trying to understand why some combinations resulted in fewer presses and struggled to keep ...
New
New
seeplusplus
This one was much easier for me than yesterday’s. Part 1 runs in 22ms and part 2 runs in ~3s. defmodule BridgeRepair do def parse_inpu...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement