adamu
Advent Of Code 2022 - Day 3
Probably not the most efficient implementation, because part 1 took >1 ms and part 2 >4ms, but the code was simple enough.
def part1(input) do
input
# ...
|> Enum.map(fn {a, b} -> hd(a -- a -- b) end)
|> Enum.map(&score/1)
|> Enum.sum()
end
defp score(<<lower::utf8>>) when lower in ?a..?z, do: lower - ?a + 1
defp score(<<upper::utf8>>) when upper in ?A..?Z, do: upper - ?A + 27
https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2022/day3.exs
Most Liked
mudasobwa
Creator of Cure
I went with charlists and MapSets.
...
|> Enum.map(&to_charlist/1)
|> Enum.map(&MapSet.new/1)
|> Enum.reduce(&MapSet.intersection/2)
...
4
mcrumm
Phoenix Core Team
I started with a MapSet but ended up with a :binary.match/2:
# split the rucksack into two equal compartments
{head, tail} = line |> String.split_at(line |> String.length() |> div(2))
head
|> String.codepoints()
|> Enum.reduce_while(:ok, fn code, _ ->
case :binary.match(tail, code) do
{_, 1} -> {:halt, code |> priority()}
:nomatch -> {:cont, :ok}
end
end)
https://github.com/mcrumm/aoc2022/blob/main/aoc2022-03.livemd
4
mcrumm
Phoenix Core Team
Thanks! I made a thing in case anyone else wants to use it:
https://github.com/mcrumm/req_aoc
Mix.install([
{:req_aoc, github: "mcrumm/req_aoc", ref: "28e3813"}
])
ReqAOC.fetch!({2022, 03, System.fetch_env!("LB_AOC_SESSION")})
# ==> "..."
4
Popular in Challenges
Hello, guys. I’m back again, but only for the weekends, maybe.
This topic is about Day 13 of the Advent of Code 2020 .
Thanks to @egze,...
New
So… that’s it? Everyone is stuck on part 2? :slight_smile: I looked at Reddit hints and thought I probably wouldn’t have come up with the...
New
Here is my solution for day 2 of Advent of Code:
https://github.com/bjorng/advent-of-code/blob/main/2024/day02/lib/day02.ex
New
This topic is about Day 9 of the Advent of Code 2021 .
We have a private leaderboard (shared with users of Erlang Forums):
https://adve...
New
This topic is about Day 8 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/le...
New
This topic is about Day 5 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/le...
New
I spent 3 hours struggling in part 2, until I noticed a very basic mistake :joy:
Here’s my code:
https://github.com/Aetherus/advent-of-...
New
Nobody’s doing Advent of Code this year? :grinning_face_with_smiling_eyes:
I might do the first week or so.
For Day 1, first I solved i...
New
Setting this down for the night, as after a quick naive solve for quick part 1 I realize that part 2 is by design computationally expensi...
New
This topic is about Day 14 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/l...
New
Other popular topics
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








