-
Notifications
You must be signed in to change notification settings - Fork 0
/
012. tisbury treasure hunt.py
58 lines (43 loc) · 2.13 KB
/
012. tisbury treasure hunt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Learn about tuples by helping out competitors in the Tisbury Treasure Hunt.
"""
"""Functions to help Azara and Rui locate pirate treasure."""
def get_coordinate(record):
"""Return coordinate value from a tuple containing the treasure name, and treasure coordinate.
:param record: tuple - with a (treasure, coordinate) pair.
:return: str - the extracted map coordinate.
"""
return record[1]
def convert_coordinate(coordinate):
"""Split the given coordinate into tuple containing its individual components.
:param coordinate: str - a string map coordinate
:return: tuple - the string coordinate split into its individual components.
"""
return tuple(coordinate)
def compare_records(azara_record, rui_record):
"""Compare two record types and determine if their coordinates match.
:param azara_record: tuple - a (treasure, coordinate) pair.
:param rui_record: tuple - a (location, tuple(coordinate_1, coordinate_2), quadrant) trio.
:return: bool - do the coordinates match?
"""
return convert_coordinate(azara_record[1]) == rui_record[1]
def create_record(azara_record, rui_record):
"""Combine the two record types (if possible) and create a combined record group.
:param azara_record: tuple - a (treasure, coordinate) pair.
:param rui_record: tuple - a (location, coordinate, quadrant) trio.
:return: tuple or str - the combined record (if compatible), or the string "not a match" (if incompatible).
"""
if compare_records(azara_record, rui_record):
return azara_record + rui_record
return "not a match"
def clean_up(combined_record_group):
"""Clean up a combined record group into a multi-line string of single records.
:param combined_record_group: tuple - everything from both participants.
:return: str - everything "cleaned", excess coordinates and information are removed.
The return statement should be a multi-lined string with items separated by newlines.
(see HINTS.md for an example).
"""
cleaned = ""
for item in combined_record_group:
cleaned += f"{(item[0], item[2], item[3], item[4])}\n"
return cleaned