bismark
Took me a minute to remember my binary math
..
import Bitwise
__DIR__
|> Path.join("puzzle.txt")
|> File.stream!()
|> Stream.filter(fn line ->
line
|> String.trim()
|> String.split(",")
|> Enum.map(fn range ->
[s,e] = range |> String.split("-") |> Enum.map(& String.to_integer(&1))
Integer.pow(2, e - s + 1) - 1 <<< (s - 1)
end)
|> Enum.reduce(fn int1, int2 ->
intersection = int1 ||| int2
intersection == int1 or intersection == int2
end)
end)
|> Enum.count()
|> IO.puts()
import Bitwise
__DIR__
|> Path.join("puzzle.txt")
|> File.stream!()
|> Stream.filter(fn line ->
line
|> String.trim()
|> String.split(",")
|> Enum.map(fn range ->
[s,e] = range |> String.split("-") |> Enum.map(& String.to_integer(&1))
Integer.pow(2, e - s + 1) - 1 <<< (s - 1)
end)
|> Enum.reduce(fn int1, int2 ->
(int1 &&& int2) != 0
end)
end)
|> Enum.count()
|> IO.puts()
Edit: oops, I’m supposed to import not use Bitwise now..
Trending in Challenges
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 24 to 15- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dmarcoux
I decided to look into
Regex, which I have never used before in Elixir. Here’s what I came up with, I don’t really like the part where I’m converting the strings to integers since this involves going through nested lists. I would have liked to do this somehow withinRegex.scan/3, but I don’t know how. Maybe someone knows if it’s possible?I’m happy with everything else. Especially since doing part 2 simply meant turning the
andintoorfor the guard clauses in theEnum.reduce/3.https://github.com/dmarcoux/advent_of_code_2022/blob/main/lib/advent_of_code2022/day4.ex
Tiger
I went with a recursive solution for practice
dams
simple Elixir, using
MapSet.subset?andMapSet.disjoint?, both questions at the same timemarcelfahle
Yea, MapSet all the way on this one
tfwright
All my answers look the same
I thought about using a regex to extract the digits as I see others did with success, but I have a deeply embedded habit of strictly enforcing formatting rules for input like this (although I note @egze’s use does appear to enforce them without too much pain). Since there are a known quantity of sections though in a real case I would probably insist the format be changed to use leading zeros
egze
Part 1
Part 2
stefanluptak
https://github.com/stefanluptak/advent-of-code/blob/main/2022/day_04.livemd
bossek
day04.exs:
hst337
One more day for scanning
newton-peixoto
Probably not the most performant code but it does the job. Suggestions are appreciated
https://github.com/newton-peixoto/advent-of-code/blob/main/2022/livebooks/day-04.livemd