Solving a Programming Contest Problem, Part 1 of 2 (Think Like a Programmer)

preview_player
Показать описание
A two-parter. I walk through a tricky problem half-remembered from a programming contest many years ago. Only basic programming skills are needed here.

Your comments and suggestions for future videos are welcome.

"Think Like a Programmer" is a book I've written to help programmers with problem solving. If you've found that you are able to read programs and understand programming language syntax but aren't always confident writing programs from scratch, my book may be able to help.

For more information on the book head to one of these:

Connect with me:
Рекомендации по теме
Комментарии
Автор

It's all derived from the same formula. When we subtract one x coordinate from the other, and one y coordinate from the other, we're just finding the lengths of the shorter sides of the right triangle.

vantonspraul
Автор

This problem seems fairly straightforward. Since the robber is making a "beeline" (straight line) towards the door/exit, we really only need to know that initial distance, and the rate of speed when exiting, and we are already about halfway done solving this. The 2nd part would be to update the positions of both perhaps every 1 second, to initially simplify things. Once we get that to appear to be working (from reasonable positions reported), then we just update positions in finer increments, perhaps 1/100th of a second.

davidjames
Автор

Using simple math (vectors), I was able to make a formula for this problem in about 5 mins. Then it was solved in constant time and space. Math is really useful. :)

abhishek.rathore
Автор

Just one thought...can we use distance formula in co-ordinate geometry to solve this? if we know the distance travelled and the coordinates of the starting point, we can find out the co-ordinates of the ending point. Or maybe we can find the distance of robber and guard from the door and then find the time taken based on their speed and relate that somehow? Correct me if i'm wrong. And btw thank you for these videos. Really helpfull!

mmosenpai
Автор

You can use vectors. Either make a vector 2 for the robber position, and vector 2 for the door position. If you subtract the robber position from the door position, it should move towards the door. And do the same thing for the cop

SharkFin.pppppppppppp
Автор

Just a thought... can you also use pythagorean theorem here? E.g. x^2 + y^2 = d^2? I guess you'd still need a square root method.

asartalo
Автор

Actually there is abig right triangle. And we require the length of the hypotenuse, so we can just use the pythagoras theorem.

alkamishra
Автор

Yeah, it's been 25 years since high school math for me, so Trig isn't fresh on my mind.

Sniderpower
Автор

Their distance is the same, so it's whichever has the fastest speed.

dannyjack
Автор

Sir, I hope you still use this channel and hope you answer me .I am non technical background. I am learning javascript and it's my first programming language . I cleared basics but I don't know how to solve problem or how to think in programing. . Will this useful for me ?

abhishekhsharma
Автор

Sir can you tell me which or what method should i learn to become more problem solver.? Please sir. I love solving problems but im not very good at it. I hopee you read this. And answer me thankyouuu so much.

leomermenang
Автор

Pythagoras theorem!!!
Every Game dev should know this by heart

RamonChiNangWong
Автор

How many years have you been programming? By the way, this is very easy if you know game development. In my mind i decided to solve the whole problem. The tricky part is arctangent and its conversion to degrees.

Anothergames
Автор

This video and the next one convinced me to run away from programming

mustafawahbi
Автор

You should translate the book into spanish

regino
Автор

U=speed m=distance s= sexonds u=m*s m=u/s =m=11*1 =11 easy

themanoskouts
join shbcf.ru