/gold-mines

Algorithm challenge: best location for a gold mine

Primary LanguageJavaScript

Gold Mines

You will be provided data about lands in California and the location of gold mines within these lands.

You will also receive the size of the future exploitation that you can afford.

Your goal is to write a program able to calculate the coordinates of the most profitable location to set up your exploitation. In short, you need to find the parcel with the most gold mines within.

Example

Given a land of 6km by 4km containing gold mines at coordinates (1, 0), (5, 0), (2,2) and (3, 3), and considering that you can afford only a 2km x 2km exploitation, your program should decide to set up your company at (2,2) in order to own 2 gold mine.

Here is a graphic example: Graphic example

Concrete coding concerns

In your index.js, your program should expose a method findBestSpot that will accept the following parameters:

  • landWidth : the width of the land
  • landHeight : the height of the land
  • exploitationWidth : the width of the exploitation you can afford
  • exploitationHeight : the height of the exploitation you can afford
  • goldMines : a list of coordinates corresponding to the location of each gold mine on the land.

coordinates are objects containing the properties x and y, x and y being integers. For instance {x:2, y:3}.

Your method findBestSpot should return an object containing the following properties:

  • coordinates : the coordinates of the top-left corner of your future exploitation
  • goldMines : the number of gold mines you will be owning

IMPORTANT if there is more than one solution, your program should return the solution with the lowest values for x, and for y with this priority. For instance, if possible coordinates are (1,2), (2,1) and (2,2), your program should return (1,2) as coordinates for your exploitation.