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
This topic is about Day 10 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums ):
https://adv...
New
Note: This topic is to talk about Day 7 of the Advent of Code 2019 .
There is a private leaderboard for elixirforum members. You can joi...
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 is my second year doing AoC in Elixir and my first year doing it with Livebook.
When I was doing just plain Elixir I usually set up...
New
This topic is about Day 2 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums):
https://adven...
New
Note: This topic is to talk about Day 16 of the Advent of Code 2019.
There is a private leaderboard for elixirforum members. You can joi...
New
Note by the Moderators: This topic is for general discussion about the Advent of Code 2018.
To prevent people from being spoiled about s...
New
Note: This topic is to talk about Day 9 of the Advent of Code 2019.
There is a private leaderboard for elixirforum members. You can join...
New
Finished Day 1 with Elixir :tada:
Here’s my code:
#!/usr/bin/env elixir
defmodule Combination do
@doc "Yields each combination of 2...
New
Fairly straightforward Dijkstra’s algorithm
import AOC
aoc 2023, 17 do
def compute(input, candidates) do
{{max_row, max_col}, ite...
New
Other popular topics
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
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








