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 9 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/le...
New
Ok, that was a rough one today.
I haven’t found a way to improve the algorithm further. Part 1 runs in .5 seconds, Part 2 in ~ 5 minutes...
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 18 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/l...
New
I have 2 arrays: a1 can be any combination of value or nil like that
a1 = [1,nil,3]
and array 2 the same
a2 = [4,2, nil]
How do I com...
New
Note: This topic is to talk about Day 4 of the Advent of Code 2019.
There is a private leaderboard for elixirforum members. You can join...
New
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
Anyone have a solution to Part 2 today? Part 1 was straight forward, but I can’t figure out a programatic way to do part 2. I understand ...
New
Note: This topic is to talk about Day 2 of the Advent of Code 2019 .
There is a private leaderboard for elixirforum members. You can joi...
New
Thought I’d kick today’s thread off!
Parsing
Enum rocks, so most of my code was actually in parsing input.
▶ Preprocessing input
Part 1...
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 wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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









