woolfred
Advent of Code 2022 - Day 1
Most Liked
woolfred
Here is my first attempt, which uses specific reduces for the task at hand: advent-of-code/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:
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
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()
stevensonmt
I was going to suggest that but if I remember correctly it does not allow for duplicate values. Elves with equal calories were not explicitly forbidden from being in the top 3 so that could lead to a bad result. You’d have to build the queue including the index from the original input like `{calories, ndx}'. Tuples get sorted by elements in order, so the gb_set would still give you the right top N, you just have to then extract the calories from the tuples.
mudasobwa
Isn’t this code losing the latest elf?
- |> elem(1)
+ |> then(fn {c, e} -> [c | e] end)







