| 1 | import random |
| 2 | import string |
| 3 | |
| 1 | 4 | class Robot: |
| 5 | """ |
| 6 | A class representing a robot with a randomly assigned name. |
| 7 | |
| 8 | The robot's name is generated in the format of two uppercase letters |
| 9 | followed by three digits (e.g., RX837 or BC811). All names are unique |
| 10 | and randomly assigned from a pre-generated pool. |
| 11 | |
| 12 | Attributes: |
| 13 | _name (str): The robot's current name. None if not yet assigned. |
| 14 | """ |
| 15 | |
| 16 | # Class variable to hold all possible names |
| 17 | _name_pool = [] |
| 18 | _used_names = set() |
| 19 | |
| 2 | 20 | def __init__(self): |
| 3 | | pass |
| 4 | | |
| 21 | """ |
| 22 | Initialize a new Robot instance with no name. |
| 23 | """ |
| 24 | self._name = None |
| 25 | |
| 5 | 26 | @property |
| 6 | 27 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 28 | """ |
| 29 | Get the robot's name. If the robot doesn't have a name yet, |
| 30 | assign one from the name pool. |
| 31 | |
| 32 | Returns: |
| 33 | str: The robot's name in format of two uppercase letters |
| 34 | followed by three digits. |
| 35 | """ |
| 36 | # Edge Case: Robot has no name yet, assign a new one |
| 37 | if self._name is None: |
| 38 | # Generate the name pool if it's empty |
| 39 | if not Robot._name_pool: |
| 40 | # Generate all possible names |
| 41 | letters = string.ascii_uppercase |
| 42 | digits = string.digits |
| 43 | all_names = [l1 + l2 + d1 + d2 + d3 |
| 44 | for l1 in letters |
| 45 | for l2 in letters |
| 46 | for d1 in digits |
| 47 | for d2 in digits |
| 48 | for d3 in digits] |
| 49 | |
| 50 | # Shuffle the names randomly |
| 51 | random.shuffle(all_names) |
| 52 | Robot._name_pool = all_names |
| 53 | |
| 54 | # Edge Case: All possible names have been used |
| 55 | if not Robot._name_pool: |
| 56 | raise RuntimeError("No more names available") |
| 57 | |
| 58 | # Assign the next name from the pool |
| 59 | self._name = Robot._name_pool.pop() |
| 60 | Robot._used_names.add(self._name) |
| 61 | |
| 62 | return self._name |
| 63 | |
| 9 | 64 | def reset(self) -> None: |
| 10 | | pass |
| 65 | """ |
| 66 | Reset the robot to its factory settings, wiping its name. |
| 67 | The name is returned to the pool for potential reuse. |
| 68 | """ |
| 69 | # Edge Case: Robot has a name that needs to be returned to the pool |
| 70 | if self._name is not None: |
| 71 | # In a real implementation with a large pool, we might return the name to the pool |
| 72 | # For this implementation, we'll just remove it from used names and set to None |
| 73 | Robot._used_names.discard(self._name) |
| 74 | self._name = None |
| 75 | |
| 76 | # Handled Edge Cases: Robot has no name yet, assign a new one; All possible names have been used |