adamu
Nobody’s doing Advent of Code this year? ![]()
I might do the first week or so.
For Day 1, first I solved it using regular expressions and String.replace, which took about 10ms for each part.
Then I rewrote it using binaries and recursion, which got each part under 1ms.
def filter_digits2(<<>>), do: <<>>
def filter_digits2(<<x, rest::binary>>) when x in ?1..?9, do: <<x>> <> filter_digits2(rest)
def filter_digits2(<<"one", rest::binary>>), do: "1" <> filter_digits2("e" <> rest)
def filter_digits2(<<"two", rest::binary>>), do: "2" <> filter_digits2("o" <> rest)
def filter_digits2(<<"three", rest::binary>>), do: "3" <> filter_digits2("e" <> rest)
def filter_digits2(<<"four", rest::binary>>), do: "4" <> filter_digits2("r" <> rest)
def filter_digits2(<<"five", rest::binary>>), do: "5" <> filter_digits2("e" <> rest)
def filter_digits2(<<"six", rest::binary>>), do: "6" <> filter_digits2("x" <> rest)
def filter_digits2(<<"seven", rest::binary>>), do: "7" <> filter_digits2("n" <> rest)
def filter_digits2(<<"eight", rest::binary>>), do: "8" <> filter_digits2("t" <> rest)
def filter_digits2(<<"nine", rest::binary>>), do: "9" <> filter_digits2("e" <> rest)
def filter_digits2(<<_, rest::binary>>), do: filter_digits2(rest)
https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2023/day1.exs
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #elixirconf-us
- #ai
- #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)
mexicat
Hah, my solution was quite similar:
https://github.com/mexicat/aoc-2023/blob/main/lib/aoc/day_01.ex
stefanluptak
How did you realize that
"oneight"should be transformed to"18"?kwando
Binary pattern matching made today’s problem quite straightforward, I got lucky with my input though so the first version which didn’t account for “overlapping” numbers worked, “oneight” for instance is both “one” and “eight”.
mexicat
The naive solution didn’t work and while the text didn’t mention these cases specifically (which for day 1 is kind of unexpected…) I noticed the ambiguity in the
eightwothreeexample, so I gave it a try.stefanluptak
Exactly. Day 1 used to be just a little warmup to get our environments up and running.
I was also quite surprised by them using this kind of “catch”. Or maybe I am just being tired and not thinking clearly enough.
Anyway, thank you for the explanation.
APB9785
My first approach didn’t handle overlaps properly in part 2, so I ended up with a somewhat funky pattern match syntax:
There’s probably a cleaner way to do this, but it works!
Full solution here: https://github.com/APB9785/AoC-2023-elixir/blob/master/lib/day_01.ex
mruoss
I approached part 2 from both sides
hq1
Very clean and fast, love it
andre-dasilva
Hi everyone, i am quite new to elixir. So my code looks quite ugly:
But i gotta say there are some beautiful solutions in this thread
Askath
Took me way to long, as I misread the question. But was nice trying out elixir with a more difficult prolbem for the first time! really enjoyed it. Although my solution seems bruteforced