2
\$\begingroup\$

Goal

Write a full program that generates a map showing the local train stations and which train station is the closest to every point on the map.

Requirements

Input

A set of tuples. The first is the (Width,Height) dimensions of the map. The following tuples are the (X,Y) coordinates of each train station. Coordinates are 0-based (ie the top-left corner of the map is (0,0)) The input may be taken in any reasonable format (string, int array, tuple array, etc.)

Assume:

  • The map has a positive width and height.
  • All train stations are inside the map.
  • There are between 1 and 26 train stations, inclusive.

Output

Write a rectangular output to the console.

The first train station is designated A, the second B and so on. Train stations should be shown with their upper-case letter.

Every other cell contains the lower-case letter of the closest train station. Where there is a draw, travel to the station with the earliest letter (ie. choose B over C if they have a draw.)

Distance is measured in taxi-cab distance: Δx + Δy

Example

Input

6,4 1,0 4,1 3,3

Output

aAaabb
aaabBb
aaccbb
cccCcc

Scoring

After one week, the source code in the least bytes wins.

\$\endgroup\$
2
  • \$\begingroup\$ @steveverrill No it was using the Manhattan distance too. \$\endgroup\$
    – flawr
    Nov 27, 2015 at 0:19
  • \$\begingroup\$ @flawr, agreed. I would never have thought to search for that term. I'll close this. \$\endgroup\$ Nov 27, 2015 at 0:55

0

Browse other questions tagged or ask your own question.