shritesh
This was way too easy after the last few days. Simple map, filter and count.
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 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bjorng
I expected a twist in part 2, but there wasn’t any. My solution:
https://github.com/bjorng/advent-of-code-2023/blob/main/day06/lib/day06.ex
Aetherus
Today’s puzzle is all about quadratic equation.
If the total time of a game is
t, the speed of the boat (i.e. the time holding that button) isv, the distance the boat traveled iss, then the equation iswhich can be normalized to
All the speeds that result in better distance are between the two solutions of
vof that equation.Aetherus
Part 1
Part 2
lud
Aaaah. I wish I knew maths …
I hesitate to post my solution because it is so much more complex, but anyway.
Part 2 was around 4 seconds with the algorithm of part 1 so I used a binary search to find the two bounds:
And it takes less than 100µs for part 2 which is really nice.
But still, I would like to understand your maths
Aetherus
Your binary search part is brilliant. I know the optimal time of holding the button is just
time / 2, so I could have just used your strategy.About the math in my solution, first see this image that corresponds to the first game in Part 1 (total time = 7)
The horizontal axis is the speed (i.e. time of holding the button), and the vertical axis is how far the boat can travel.
The red line shows the relationship between the speed and the distance the boat can travel.
The green line is the distance that the last winner traveled.
To beat the last winner, my speed needs to be between the two cross points (the two black points) of the red line and the green line.
The rest is just to google how to solve a quadratic equation.
lud
Yes I figured out that the best distance would always be to hold for 0.5 * time, so I splitted my search here.
Ok so I googled a bit and that
-4seems to be inherent of this form of equation and not specific to those boats, which reassures me.Reminds me a long time ago in high school but I guess I had already bailed out of mathematics
trnasistor
My beginner’s solution, Day 06.
I was considering binary search as well when coming up with an efficient solution.
But naive approach turned out to be fast enough.
Aetherus
Inspired by the solution of @lud , I just tried another approach with Newton’s approximation because I don’t want to deal with floating point numbers
Prep
Part 2
mkasztelnik
I also considered the last race (when function breaking points are integers), that why my floor and ceil methods are more complicated:
Aetherus
I thought of that, too, but fortunately, my input doesn’t have that problem
Anyway, the Newton’s approximation approach should be fine in all cases.