+ 3

Python - Roadrunner - test case 3(hidden) fails - what am i missing?

dist_apart = 50 dist_to_safety = int(input()) rr_speed = int(input()) k_speed = int(input()) catch_rate = k_speed - rr_speed catch_time = dist_apart/catch_rate rr_safe_time = dist_to_safety/rr_speed if rr_safe_time > catch_time: print("Yum") elif rr_safe_time < catch_time: print("Meep Meep")

27th Jan 2020, 9:06 AM
Adam
Adam - avatar
14 Respuestas
+ 10
Your catch time is wrong. It is as if you considered that the road runner is not moving. The distance is changing with time, you forgot the add that as well. Here is a fix: Instead of trying to figure out catch_time, consider it as a race. If the coyote arrives first, he wins. Else, the road runner wins. Which means, catch_time will now represent the time needed for the coyote to go to safe zone. Thus this formula: catch_time = (dist_apart+dist_to_safety) / k_speed Also, catch_rate will be useless if you look at the situation like I did, so you can remoce it.
27th Jan 2020, 9:34 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
Adam technically, the road runner will be safe. If they voth arrive to safe zone same time, then the road runner will already be safe. But what matters is that you deliberately left it out, so no problem 👌
27th Jan 2020, 11:46 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
Thanks Aymane. The code below now passes all test cases. dist_apart = 50 dist_to_safety = int(input()) rr_speed = int(input()) k_speed = int(input()) k_finish_time = (dist_apart + dist_to_safety)/k_speed rr_finish_time = dist_to_safety/rr_speed if rr_finish_time > k_finish_time : print("Yum") elif rr_finish_time < k_finish_time : print("Meep Meep")
27th Jan 2020, 10:31 AM
Adam
Adam - avatar
+ 4
Adam even tho it is now fixed, you forgot about one test case: rr_finish_time == k_finish_time But nice code, and good choice of variables 😁👍
27th Jan 2020, 11:35 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
distance_safety = int(input()) roadrunners_speed = int(input()) coyotes_speed = int(input()) if distance_safety / roadrunners_speed < (distance_safety + 50) / coyotes_speed: print("Meep Meep") else: print("Yum")
18th Jun 2021, 7:05 AM
Przemysław Komański
Przemysław Komański - avatar
+ 1
Thanks Aymane. I deliberately left out that test case as the question doesn't specify what happens in the event of a draw.
27th Jan 2020, 11:43 AM
Adam
Adam - avatar
+ 1
Had the same problem with test case 3... Made modifications as suggested and all cases worked but I don't get why using closing speed didn't work.... In the first code above closing time was calculated using closing rate, not just the coyote speed... In my head using the rate here accounts for both parties moving... Speed 1 = 20 Speed 2 = 5 Closing rate = 15 So every second the become 15 feet closer.... I must be missing something!!
11th Jul 2020, 8:34 AM
Eoin
+ 1
I compare times needed to beat distances to safe place. If coyote beat this distance faster, that mean he coughts roadrunner.
18th Jun 2021, 7:13 AM
Przemysław Komański
Przemysław Komański - avatar
+ 1
s = int(input()) r = int(input()) c = int(input()) d = 50 if (s + d) / c < s / r: print("Yum") else: print("Meep Meep")
17th Oct 2021, 8:36 PM
Mateo González Bufi
Mateo González Bufi - avatar
0
For those who cant do math like me, just replecate a real race🏁, it works for me My roadrunner code rrposis = int(input()) rrspeed = int(input()) caospeed = int(input()) caoposis = rrposis + 50 while caoposis > rrposis and rrposis>0: rrposis -= rrspeed caoposis -= caospeed print(('Meep Meep','Yum')[rrposis>0]) The last print statment Is just a fancy if statment trick, basicly im printing yum if rrposis >0
27th Jun 2021, 8:03 AM
Britz
0
distancia = int(input()) roadrunner = int(input()) coyote =int(input()) coyote_t = 50/coyote roadrunner_t = distancia/roadrunner x= coyote_t - roadrunner_t if x>0: print('Meep Meep') else: print('Yum')
1st Mar 2022, 3:56 AM
Herbeth Cortez Gonzalo
Herbeth Cortez Gonzalo - avatar
0
distance = 50 distance_safe = int(input()) road_runner_speed = int(input()) coyote_speed = int(input()) time = distance_safe / road_runner_speed if time * coyote_speed <= distance: print('Meep Meep') else: print('Yum')
2nd Mar 2023, 1:22 AM
mohammad
0
d_safety= int(input()) r= int(input()) c= int(input()) time_c= (50+r)//c time_r = d_safety//r if time_r < time_c : print("Meep Meep") else: print("Yum")
7th Jun 2023, 7:06 AM
Teph Alajas
0
In test 3 the roadrunner's speed is greater than the coyote's speed. Thus catch_rate becomes negative and the program breaks. This fixes it: if rr_safe_time > catch_time and catch_time > 0
20th Nov 2023, 8:12 PM
Frode
Frode - avatar