# Map sheets
**by [Matt Hall](https://github.com/kwinkunks)**
You might want to get a cup of coffee before reading this one.
We have a list of locations in Canada, given to 'quarter unit' accuracy. The locations use a highly esoteric addressing system, based on Canada's [National Topographic System](https://en.wikipedia.org/wiki/National_Topographic_System), and are accurate to about ±200 m or so, because each quarter unit is about 1/4 mile, or 400 m, on each side. In this exercise, we'll assume it is 400 m exactly.
Each location has two parts, separated by a `'/'`:
a-71-L/15-I-89
^^^^^^ ^^^^^^^
unit / sheet
The `unit` part gives the **quarter-unit** (a, b, c, or d), followed by the **unit** (1 to 100), followed by the **block** (A to L).
The `sheet` part gives the **map sheet** (1 to 16), followed by the **map area** (A to P), followed finally by the **map** (a 2-digit number).
In other words, it reads a bit like a postal address, starting with small-scale features (the quarter unit) and working up to a 'map', which measures hundreds of km along one side.
The tricky part is that, within each block type, the sub-blocks are labeled in very particular ways. All of them begin in the lower-right corner, but then they become quite idiosyncratic. This figure illustrates the relationships, **but the figure is not to scale** so don't read too much into it.
## Questions
Can you answer the following questions about this dataset:
1. How many map sheets contain **two or more** locations?
2. Look at the first location in your list. Find the **index** of the column that this location appears in, at each scale; **start with the map scale** and end with the quarter-unit scale. Submit a string representing a comma-separated sequence of indices.
3. What is the x-coordinate of the centre of the quarter-unit represented by the **first** location in your list?
4. Considering _only the blocks in your list_, which of them is **closest to the centroid** (mean central point) of all the locations in your list? Call this position **C**.
5. **Bonus question!** What is the full NTS 'address' of the quarter-unit **containing the centroid, C**? You must format your string exactly as in your input data.
You do not have to solve question 5 to get the key for the next challenge.
## Rules and assumptions
- Use the lower-left corner of map 97 as the origin for coordinates.
- Assume the smallest entity, the quarter-unit, is 400 m on a side.
- Your answers should be strings or integers. Note that the solution to question 2 should be a string like `"2,1,3,3,0,0"`.
## Example
Here are three locations:
c-70-H/16-K-77,b-41-I/08-D-87,a-74-D/16-K-77
We'd answer the questions as follows:
1. There is **`1`** unique map sheet with at least two locations, **`"16-K-77"`**.
2. The first location appears in the 3rd column, i.e. column index 2, at the map scale (`77`), the index 1 column at the map area scale (`K`), the index 3 column at the map sheet scale (`16`), etc. The correct reponse is **`"2,1,3,3,0,0"`**.
3. The first location is at (1272200, 277400) so the answer is (to the nearest metre) **`1272200`**.
4. The mean location is (1055000, 196866.667) and of the three blocks given, the block which is the shortest distance from this is **`"a-74-D/16-K-77"`**.
5. The mean location is in block **`"a-62-A/04-L-77"`**. Note that this block is not in your list.
## A quick reminder how this works
This document is formatted in [Markdown](https://daringfireball.net/projects/markdown/).
You can retrieve your data, which is always a string, by choosing a **``** (also a string). This ensures that you have different data from other people, so be creative.
```
url = 'https://kata.scienxlab.org/challenge/map-sheets'
params = {
'key': # Replace with your own string.
}
r = requests.get(url, params)
r.text
```
To answer question 1, change the `params`:
```
params = {
'key': , # Use the same key you used to get your input.
'question': 1,
'answer': 1234 # Your answer; can be a float, int, list or array;
# the challenge description will tell you which.
}
```
To get a hint for a question, provide the question number but no answer:
```
params = {
'question': 1,
}
```
[Complete instructions at kata.scienxlab.org](https://kata.scienxlab.org/challenge)
[An example notebook to get you started](https://gist.github.com/kwinkunks/50f11dac6ab7ff8c3e6c7b34536501a2)
----
© 2024 [Scienxlab](https://scienxlab.org/) — Code: openly licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) — Text: openly licensed under [CC BY](https://creativecommons.org/licenses/by/4.0/).