Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
O(1) solution. Awesome. Wish I would've figured it out. Very nice
This comment is hidden because it contains spoiler information about the solution
give some theory about this solution pls)
At first, I also performed the solution with a loop, but then I thought that it was known in advance how many times the ball would fly near the window, which means there must be a mathematical formula.
Exactly something I was expecting while solving this Kata with boring loop
Gotta get my maths skills up I guess
But it is an effective solution and have a constant time, when the traditional method has a linear time. So it is better, though the comprehensibility isn't good without comments, but perfomance is actually better
Converting to int makes the * 2 + 1 operations done in integer arithmetics, which probably ends up saving a few cpu cycles.
Also prevents warnings about losing precision when implicitly converting from double to int.
This solution does not actually pass the tests...
As mentioned, it should take into account the case where the ball bounces at the exact height of the window.
It would have been nice if it worked like this.
And I think that (int)floor() is redundant.
It is actually quite straightforward, if you know geometric sequence and logarithm base change formulas.
This shouldn't be considered "Best Practices", it's not easy to figure out what does it do.
Very "Clever" though.
Awesome!!! I am loving this place.
Best answer ever. GJ