[Community Puzzle] The Frog Jump 1


#1

https://www.codingame.com/training/easy/the-frog-jump-1

Send your feedback or ask for help here!

Created by @Pyoroalb,validated by @tarapitha,@dbdr and @BlaiseEbuth.
If you have any issues, feel free to ping them.


#2

Sorry but Wikipedia’s solution won’t work when x,y≠0,0.


#3

For me x,y≠0,0 work in ide but not in the validation


#4

The same here.


#5

Why mass m is in the input but not used in the given formula?

Besides, typo should be further fixed - there is now two “Step 3”


#7

@nicola1 & @baddger: The other frogs “distances” are to be considered as landing x positions. @tarapitha & I have tried to fix that and improve the statement.


#8

So why does only the validator fail?


#9

Purely coincidental I guess. I’m not in the author’s mind and his official solution is kinda ambiguous: Either it’s wrong as he has forgotten to subtract x0 from the calculated landing position, or we have to interpret the given distances as positions. The second interpretation does not require to modify the testcases.


#10

Please, how to calculate distance ?
This does not work but it’s just like description :

double speed_x = Math.cos(alpha)*speed;    
double speed_y = Math.sin(alpha)*speed;
double delta = speed_y*speed_y - 4.0*(b*0.5)*y;
double time = (-speed_y - Math.sqrt(delta))/(2.0*b*0.5);
double distance = a*0.5*time*time+speed_x*time;

Thanks in advance.


#11

java?
Be aware that Math.cos() accepts an angle in radian.


#12

@Niako

---

unless you changed the wording in the puzzle statement, the given values for the other frogs are not related to x0. There is no information about where they started their jumps from, only the distance that they achieved. So there’s really no reason to even consider subtracting x0 from the values. :slight_smile:

Sorry, i misinterpreted your statement about subtracting x0. Your comment is completely correct.


#13

@Cx1 Ok but thanks for you comment anyway, the problem is that obviously distances have to be interpreted as positions, but somebody kinda reverted my modification (without mentioning it in the comments):
Input Line 2 was initially “The distance in meters of each frog separated by spaces.
I replaced it by “The landing x coordinate in meters of each frog separated by spaces.” which provides a correct interpretation to solve the problem.
And now it’s “Frogs jump lengths in meters of each frog separated by spaces.” which is wrong again…


#14

Indeed your phrasing was best, since it fits neatly with that 1st rule of ranking: “The further the frog lands, the better the frog’s place.” – it’s not the jump length that is scored, but the landing position!


#15

@Cx1 Actually that ranking rule initially was about the longest jump but was modified by @tarapitha to fit in with the testcases. As I said, there is a tradeoff between modifying the statement to fit in with the testcases and the other way round. The second alternative would have the serious disadvantage of making all currently validated solutions wrong.


#16

Thanks, that was the problem with Java :slight_smile:


#17

I’m encountering the same problem as @yoles:
when I do the calculations, I get 0 for distance whereas I should get (according to the test case 1) 0.09 or 0.08.

I’m quite sure I’m missing something, but I dunno what.

Thanks in advance.


#18

This same problem has the same solution - feed radian to your cos function.


#19

Thx @java_coffee_cup.

I also had to feed radian to the sin function.


#20

I got the same problem, did you manage to fix it?


#21

Using the provided calculations, my code fails only for both On Jupiter and A strongest frog tests (and only in On Jupiter validator when submitting my code)…
On Jupiter: My code computes a 0.0363m long jump. With 6 higher jumps, my frog is 7th but expected is 5.

speed_x:0.8833, speed_y:0.5100, delta:0.2601, time:0.0411, jump:0.0363

A strongest frog: I get a 0.077m long jump which is the third best jump but expected is 2.

speed_x:1.1881, speed_y:0.3183, delta:0.1013, time:0.0649, jump:0.0771

Could anyone tell me which intermediate value is wrong ?
Thanks