Not sure where @RedNose is so I'll just post this. Post ur solutions below or whatever idc
Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!
Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app
What did you think about today's problem?
Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)
Jump in the discussion.
No email address required.
Solve each race in O(1) using highschool math
the distance you can travel is given by d = p(T-p), where T is the total amount of time, and p is how long you hold the button. (This is just d = v*t, but the time you have is also dependent on the velocity)
This forms a parabola with zeros at p = 0 (so you never press the button) and p = T (you never let go). Naturally the optimum is at T/2.
next find the p that corresponds the record distance. So do r = p(T-p), where r is the record distance. You'll use the quadratic formula and get two big equations which I won't type out here.
finally ge the distance between both values of p using subtraction. if you do this the terms cancel out and you are left with sqrt(T^2-4r). This is (pretty much) the value you are looking for
(You'll need to do some small adjustments but they are uninteresting)
Jump in the discussion.
No email address required.
More options
Context