shritesh
This was way too easy after the last few days. Simple map, filter and count.
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
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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)
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.