6 kyu

Optimum coding school location

183 of 427chrizzzer

Description:

Preface

You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school. In order to make this decision data about the location of students and potential locations is collected.

Problem

In order to be able to attract and teach as many students as possible we want to minimize the total traveling distance for potential students. The streets system is organized in a traditional grid system and students can only travel horizontally or vertically (not diagonal).

The locations of interested students is given as an array with the first value of each entry presenting the x coordinate and the second value presenting the y coordinate:

var students = [[3,7],[2,2],[14,1], ...];
students = [[3,7],[2,2],[14,1], ...];
students = [[3,7],[2,2],[14,1], ...];

Potential locations are passed as an array of objects with an unique id, a x and y coordinate:

var locations = [{id: 1, x: 3, y: 4}, {id: 2, x: 8, y: 2}, ...];
locations = [{"id"=> 1, "x"=> 3, "y"=> 4}, {"id"=> 2, "x"=> 8, "y"=> 2}, ...];
locations = [{"id": 1, "x": 3, "y": 4}, {"id": 2, "x": 8, "y": 2}, ...];

Your task is now to evaluate which of the school locations would be best to minimize the distance for all potential students to the school.

The desired output should consist of a string indicating the ID of the best suitable location and the x and y coordinates in the following form:

"The best location is number 1 with the coordinates x = 3 and y = 4"
Algorithms

More By Author:

Check out these other kata created by chrizzzer

Stats:

CreatedJun 7, 2015
PublishedJun 8, 2015
Warriors Trained804
Total Skips54
Total Code Submissions1601
Total Times Completed427
JavaScript Completions183
Ruby Completions67
Python Completions199
Total Stars20
% of votes with a positive feedback rating90% of 91
Total "Very Satisfied" Votes75
Total "Somewhat Satisfied" Votes14
Total "Not Satisfied" Votes2
Ad
Contributors
  • chrizzzer Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad