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
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)
code-shoily
I am grateful for
MapSetmodule. Not every language is blessed with a set API that has common set operations.https://github.com/code-shoily/advent_of_code/blob/master/lib/2022/day_04.ex
srowley
Second half was actually a little simpler.
stevensonmt
Basically did the same. I wasn’t as clever with your use of the
&&and||operators to convert to numbers. I just filtered and counted.deadbeef
Like others, using
Rangehttps://github.com/ed-flanagan/advent-of-code-solutions-elixir/blob/main/lib/advent/y2022/d04.ex
adamu
Ooh, TIL, I started with
Ranges, but then converted them toMapSets - I didn’t consider that we can do it, especially part 2, directly with the range. This is why AoC is greathttps://git.adamu.jp/adam/AdventOfCode/src/branch/main/2022/day4.exs
lkuty
part 1
part 2 is very similar to part 1.
mudasobwa
and then
kwando
clever parsing
markholmes
I’ve been working through AOC using Gleam this year! This is probably pretty terrible Gleam code, but it’s Elixir-adjacent so I thought I’d share
https://github.com/markholmes/aoc/blob/main/src/y_22/d_04.gleam
christhekeele
I also went with parsing into
Ranges, and was also surprised to learn aboutRange.disjoint?/2solving part two that literally did all the work compared to part one.What I really found impressive is that
disjoint?handles steps with ranges, as well! That’s a cool technique.