+ 3

Trip planner problem. Why both give the correct result?

Hi! Anybody, please, explain the difference. I solve the travel planner problem, where you need to find the travel time when you know the speed and distance. why do both expressions give the correct result? minutes = distance / speed *60 minutes = distance/(40/60)

20th May 2021, 5:00 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
27 Respostas
+ 8
This post inspired me to create this code which is relevant to this discussion. 😂🤣 https://code.sololearn.com/ca4A19a13a69/?ref=app
20th May 2021, 10:58 PM
David Carroll
David Carroll - avatar
+ 5
oh no! my bad... a/(b/c) == a/b*c
20th May 2021, 5:16 PM
visph
visph - avatar
+ 2
Yaroslav Vernigora , what do you mean? Speed is known by the task description. What are your doubts?
20th May 2021, 5:15 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
speed === 40
20th May 2021, 5:16 PM
Apongpoh Gilbert
Apongpoh Gilbert - avatar
+ 2
because: a/(b/c) == a*(c/b)
20th May 2021, 5:17 PM
visph
visph - avatar
+ 2
not VERY good... but I have my basics ;)
20th May 2021, 5:49 PM
visph
visph - avatar
+ 2
Yaroslav Vernigora distance/speed *60=distance*60/speed And distance /(40/60)=distance/40/60=distance/40*60
20th May 2021, 6:36 PM
Atul [Inactive]
+ 1
does the trip planner code coach have only once test? if then, that mean that the value used for speed*60 should be equals to 40/60 ^^
20th May 2021, 5:13 PM
visph
visph - avatar
+ 1
that works also if speed is a constant and there are many tests ;P
20th May 2021, 5:14 PM
visph
visph - avatar
+ 1
yes, you are right, we have one constant - speed. it is equal to 40
20th May 2021, 5:15 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
🤭
20th May 2021, 5:16 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
visph no, wait... let's look at the first expression you wrote. I did not change the constant speed of 40 from 60. in one case, we multiply, in the second, we divide... and both expressions are correct! how can this be?
20th May 2021, 5:21 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Simba you wrote a/b/c = a*c/b but I have written: a / b * c == a / (b / c)
20th May 2021, 5:24 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
your first expression is a/b*c wich is evaluated as c*a/b coz left to right precedence (same precedence for / and *) your second one is a/(b/c) wich is equal to a*(c/b) and equal to a*c/b or c*a/b or a/b*c
20th May 2021, 5:24 PM
visph
visph - avatar
+ 1
thank you very much! I'll need more time to figure this out. and repeat the priority of rolling out the operators
20th May 2021, 5:27 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thank y'all!
20th May 2021, 5:28 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
this is just maths ;) n x * n x * ------ == ------------ d d and left to right precedence when same operators precedences
20th May 2021, 5:29 PM
visph
visph - avatar
+ 1
there is also the result in the correct answer in parentheses. if you remove them, the answer will be incorrect
20th May 2021, 5:43 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I see, you very good know math! 👏👍
20th May 2021, 5:47 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
distance = 5 speed = 40 Example 1: t = 5/40 × 60 1) 5/40 = 1/8 2) 1/8 × 60 = 60/8 = 15/2 = 7.5 Example 2: t = 5 ÷ 40/60 1) 40/60 = 4/6 = 2/3 2) 5 ÷ 2/3 = 5 × 3/2 = 15/2 = 7.5 Check: distance = 7.5 × 40 ÷ 60 1) 7.5 × 40 = 300 2) 300 ÷ 60 = 5 Conclusion: example1 == example2
22nd May 2021, 10:40 AM
Solo
Solo - avatar