I also found Day 6 much easier than day 5. By using a little bit of maths we can implement a “no loops required” solution using quadratic inequalities…
Day 6 spoilers
If we name the time that the player holds in the button variable x, then we want to solve the following equation for all values of x…
(time - x) * x > distance
Using the quadratic formula we can solve x and get two answers a and b like follow…
a = (time - Sqrt(time * time - 4 * distance)) / 2
b = (time - Sqrt(time * time - 4 * distance)) / 2
Your wins given the hold time and a record of distance will now be…
wins = Ceil(b) - Floor(a) - 1
Final CalculateWins function…
Function CalculateWins(time As Integer, distance As Integer) As Integer
Var a As Double
Var b As Double
Var wins As Integer
a = (time - Sqrt(time * time - 4 * distance)) / 2
b = (time + Sqrt(time * time - 4 * distance)) / 2
wins = Ceil(b) - Floor(a) - 1
return wins
End Function
Runs 0.05ms in IDE.
Show off.
But isn’t that the same formula for a and b?
Haha… I’m just glad I didn’t end up with a slow 15s run like with yesterday’s puzzle
I fixed the formula, a has a -, and b has a +
1 Like
Perhaps for next year’s AoC event we could try and convince the Xojo marketing team to set up an official Xojo leaderboard on AoS, and sponsor a 1-year Xojo Pro license as the first prize to the winner?
It could be a great way to motivate people to join the AoC event, while showcasing Xojo as a programming language?
I see that is what Kotlin is doing on AoC to bring attention to their programming language, and attract new users.
@Dana_Brown ^
1 Like
Your hurriedness paid off Robert, because you completed the puzzle in a very respectable time
Took me a while to get the maths right
I think you mean @April_Baynes . Dana is no longer with Xojo.
2 Likes
Oh, I didn’t realize Dana moved on… been a while since I’ve been active on the Xojo forums.
Thank you for rectifying Kem.
Such a competition would be a bit unfair for those of us in Europe, though, because we’d have to get up very early in the morning to be able to compete.
Also, as soon as there are prizes involved, there’s a possibility that people cheat by looking up solutions and then re-coding them in Xojo instead of doing the full works.
Might still be worth considering an “official” Xojo competition regardless.
You are making a few valid points that I didn’t think of Thomas.
Perhaps one could have a leaderboard/prize per region to accommodate for the time differences, but I guess there won’t be an easy way to deal with any kind of cheating. Might still be worth it though, because cheating or not… if it raises awareness about Xojo as a programming language, and get people to try the language it is a win for Xojo.
If Xojo had to host their own competition I would definitely join, but it would be difficult to reproduce the level of puzzles that AoS created. I can only imagine that a lot of thought, time and testing goes into creating these puzzles.
I found Day 7 to be a nice change. It was more in line with the kind of programming that I typically do. However, my code had several obscure errors that still managed to give correct answers for part 1 and the example data in part 2, but then gave the wrong answer for the full part 2 data. Took a while to chase those down.
This year I’m a bit behind the schedule. With a little 10 months old girl around I don’t have too much spare time, so I’ve completed Day 5 and 6 by brute force.
No regrets
About doing a competition with AoC, that would be nice and fun. The leaderboard isn’t fair, because of the different timezones… and can be cheated (we’ve seen this last year), so we’ll have to think about a different way.
Yeah… day 7’s puzzle feels a lot more like logical programming than the previous puzzles.
I definitely like the diversity of these puzzles.
Had a business function today so only had time to complete part 1 of day 7… I’m going to tackle part 2 now.
I hear you Ricardo… my boy is now 13 months old… babies definitely command their slice of time.
1 Like
I’ve been sick for the past few days so decided to forgo AoC in favor of sleep. I haven’t even looked at day 7 yet, and given work demands, may have to circle back later.
1 Like
Hope you feel better soon Kem.
2 Likes