66.3k views
18 votes
Write a program to calculate the farthest in each direction that Gracie was located throughout her travels. Add four print statements to the lines of code above that output the following, where the number signs are replaced with the correct values from the correct list:

1 Answer

13 votes

Answer:

If you're given a set of coordinates that Gracie has travelled to, you can find the farthest in each direction with something like this (I'll use pseudocode in lieu of a specified language):

left = right = top = bottom = null

for each location traveled{

if left == null or location.x < left {

left = location.x

}

if right == null or location.x > right {

right = location.x

}

// note that I'm assuming that the vertical position increases going downward

if top == null or location.y < top {

top = location.y

}

if bottom == null or location.y > bottom {

bottom = location.y

}

}

As for the four print statements and other information, insufficient information is provided to complete that.

User Mirko Brombin
by
5.5k points