|
| 1 | +"""Functions to help Azara and Rui locate pirate treasure.""" |
| 2 | + |
| 3 | + |
| 4 | +def get_coordinate(record: tuple) -> str: |
| 5 | + """ |
| 6 | + Return coordinate value from a tuple containing the treasure name, |
| 7 | + and treasure coordinate. |
| 8 | +
|
| 9 | + :param record: tuple - with a (treasure, coordinate) pair. |
| 10 | + :return: str - the extracted map coordinate. |
| 11 | + """ |
| 12 | + return record[-1] |
| 13 | + |
| 14 | + |
| 15 | +def convert_coordinate(coordinate: str) -> tuple: |
| 16 | + """ |
| 17 | + Split the given coordinate into tuple containing its individual |
| 18 | + components. |
| 19 | +
|
| 20 | + :param coordinate: str - a string map coordinate |
| 21 | + :return: tuple - the string coordinate split into its individual |
| 22 | + components. |
| 23 | + """ |
| 24 | + return tuple(char for char in coordinate) |
| 25 | + |
| 26 | + |
| 27 | +def compare_records(azara_record: tuple, rui_record: tuple) -> bool: |
| 28 | + """ |
| 29 | + Compare two record types and determine if their coordinates match. |
| 30 | +
|
| 31 | + :param azara_record: tuple - a (treasure, coordinate) pair. |
| 32 | + :param rui_record: tuple - a |
| 33 | + (location, tuple(coordinate_1, coordinate_2), |
| 34 | + quadrant) |
| 35 | + trio. |
| 36 | + :return: bool - do the coordinates match? |
| 37 | + """ |
| 38 | + return azara_record[-1] == "".join(rui_record[1]) |
| 39 | + |
| 40 | + |
| 41 | +def create_record(azara_record: tuple, rui_record: tuple) -> (tuple, str): |
| 42 | + """ |
| 43 | + Combine the two record types (if possible) and create a combined record |
| 44 | + group. |
| 45 | +
|
| 46 | + :param azara_record: tuple - a (treasure, coordinate) pair. |
| 47 | + :param rui_record: tuple - a (location, coordinate, quadrant) trio. |
| 48 | + :return: tuple or str - the combined record (if compatible), or the string |
| 49 | + "not a match" (if incompatible). |
| 50 | + """ |
| 51 | + if compare_records(azara_record, rui_record): |
| 52 | + return azara_record + rui_record |
| 53 | + return "not a match" |
| 54 | + |
| 55 | + |
| 56 | +def clean_up(combined_record_group: tuple) -> str: |
| 57 | + """ |
| 58 | + Clean up a combined record group into a multi-line string of single |
| 59 | + records. |
| 60 | +
|
| 61 | + :param combined_record_group: tuple - everything from both participants. |
| 62 | + :return: str - everything "cleaned", excess coordinates and information |
| 63 | + are removed. |
| 64 | +
|
| 65 | + The return statement should be a multi-lined string with items separated |
| 66 | + by newlines. (see HINTS.md for an example). |
| 67 | + """ |
| 68 | + result: str = "" |
| 69 | + for line in combined_record_group: |
| 70 | + result += f"{tuple(item for i, item in enumerate(line) if i != 1)}\n" |
| 71 | + return result |
0 commit comments