Dcoder icon

The shortest Path Algo(Simple) @ Dcoder

By Lochard | As a newbie programmer | 22 Jul 2023

Problem: The Jones Trucking Company tracks the location of each of its trucks on a grid similar to an (x, y) plane. The home office is at location (0, 0). Read the coordinates of truck A and the coordinates of truck B and determine which is closer to the office.

Input: Input contains 4 space separated integers, first 2 are x,y for truck A, next are x,y for truck B.

Output: Output will be either A or B, bases on which one is closer to home office.

Constraints: The x-coordinate is in the range –20 .. 20. The y-coordinate is in the range –20 .. 20

Sample Input: 3 -2 -5 -3

Sample Output: 


x1, y1, x2, y2 = map(int, input().split())
print('A' if (x1**2 + y1**2)**.5 < (x2**2 + y2**2)**.5 else 'B')

How do you rate this article?



Asylum seeker in Lithuania. My short-lifed daily on GitHub https://github.com/locharp/asylum_daily/tree/main/en

As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.