stevensonmt
Reasonably pleased with my solution. The bitstring packet problems are so well suited to Erlang/Elixir it’s almost not fair.
defmodule Day6 do
defmodule Input do
def sample_data(1), do: "mjqjpqmgbljsphdztnvjfqwrcgsmlb"
def sample_data(2), do: "bvwbjplbgvbhsrlpgdmjqwftvncz"
def sample_data(3), do: "nppdvjthqldpwncqszvftbrmjlhg"
def sample_data(4), do: "nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"
def sample_data(5), do: "zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"
def load() do
ReqAOC.fetch!({2022, 06, System.fetch_env!("AOC2022Session")})
end
end
defmodule Solve do
defp find_packet(input, n, i) do
<<pkthd, pkttl::binary-size(n - 1), rest::binary>> = input
if <<pkthd, pkttl::binary>> |> uniq_chars?() do
i
else
find_packet(<<pkttl::binary, rest::binary>>, n, i + 1)
end
end
defp uniq_chars?(<<>>), do: true
defp uniq_chars?(<<a, rest::binary>>) do
not String.contains?(rest, <<a>>) and uniq_chars?(rest)
end
def part1(input), do: find_packet(input, 4, 4)
def part2(input), do: find_packet(input, 14, 14)
end
end
Not an issue for the given data sets, but I did just realize this would crash and burn if there was no packet of unique elements of N length. I could handle it but, getting late.
Trending in Challenges
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Aetherus
Today’s quiz is easy again. In order to leverage
StreamandEnumfunctions, I just read the file into a charlist.Arzar
After the convoluted puzzle input of day 5 I guess they wanted to give us a rest. Just one line
This is standard elixir ? What are pkttl::binary, rest::binary?
stevensonmt
pkttl::binaryandrest::binaryare just variables assigned to sub-binaries via pattern matching. Theuniq_chars?is just a helper function I made for this problem. I was really just talking about the pattern matching aspect on binaries.Arzar
I see, I got confused by the bitstring/binary syntax, thanks!
code-shoily
Shortest solution I produced so far… when I solved it I did more explicit pattern matching to get the answer right, then shortened it up, first used
takeinstead of patterns, then moved to binary pattern instead of grapheme pattern… here’s the final one.hst337
First part is beautiful and perfect for binary matching
LostKobrakai
I did use
Stream.chunk_everyas well. Makes this really short and sweet.Solution
mudasobwa
A bit of metaprogramming with a help of
Formulae.Combinatorsto build a guardhst337
You know you can use
Macro.generate_unique_argumentsfor thismudasobwa
Yes, thanks, but I don’t really care about syntactic sugar which brings literally nothing to the table.