I am a beginner Go student and I've been given the following assignment that needs to be built in Go:
-Read in a data file that contains all 83 counties of Michigan and the coordinates (in decimal) for each county seat.
-Set beginning coordinates to the college I attend.
-Prompt user for a direction (n,s,e,w) and the program then finds the closest county seat in that specified direction. The found county seat then becomes the new starting point and the program starts over with the direction prompt.
-the program needs to show an error if the user hits water or is about to leave the state.
I am able to do most of this without issue, but here is where I'm hitting a brick wall: My plan is to use two arrays; one for latitude and one for longitude. I need to sort each array so that the numbers are in order from the eastern most county seat to the western most county seat (for latitude and the same for longtitude). My thinking is that if the user enters that they want to go west, the program will take the latitude coordinate of the starting point, determine where in the array it is supposed to be positioned then the program selects the closest coordinate in the numbers to the right of starting coordinate. The program should then take the determined coordinate and reference the main map of coordinates, find the matching complete set of coordinates then set the starting point to the new coordinates. I'm using float64s for the coordinate data types.
So to break it down: the data file reads in the coordinates of {1, 1.2} {2,1.3} {3, 2.4} {4, 5.4} {5, 6.6}; the starting point is (1,2) and the user wants to go west. So the latitude array holds {1.2, 1.3, 2.4, 5.4, 6.6} and the program needs to take the 2 from the starting, determine that it belongs between the 1.3 and 2.4, the determine that the 2.4 is the closest coordinate to the starting point. Then it takes the 2.4 and compares it to the data file coordinates to match the {3, 2.4}. The starting point is now {3, 2.4}. Then the program starts over from the user choosing a direction.
I apologize for the novel but I wanted to make sure I was as clear (as mud, I know LOL) as possible. How do I code the sort and comparisons? If there is an easier way to complete this assignment, I would be incredibly grateful for any help. Please keep in mind, I've only been working with Go for about a month and a half. Please be gentle with complicated code. LOL Thank you!