| 1 | import random |
| 2 | import string |
| 3 | |
| 1 | 4 | class Robot: |
| 5 | # Class variable to hold the name pool and track used names |
| 6 | _name_pool = [] |
| 7 | _used_names = set() |
| 8 | |
| 2 | 9 | def __init__(self): |
| 3 | | pass |
| 4 | | |
| 10 | # Edge Case: Initialize name pool if it's empty |
| 11 | if not Robot._name_pool: |
| 12 | self._generate_name_pool() |
| 13 | self._name = None |
| 14 | # Edge Case: Handle case where all names might be used (though practically impossible with 676000 possibilities) |
| 15 | if len(Robot._used_names) >= len(Robot._name_pool): |
| 16 | raise RuntimeError("All possible robot names have been used") |
| 17 | self._assign_name() |
| 18 | |
| 5 | 19 | @property |
| 6 | 20 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 21 | # Edge Case: Return the assigned name |
| 22 | return self._name |
| 23 | |
| 9 | 24 | def reset(self) -> None: |
| 10 | | pass |
| 25 | # Edge Case: Reset the robot's name by returning the current name to the pool and getting a new one |
| 26 | if self._name: |
| 27 | Robot._used_names.discard(self._name) |
| 28 | # Edge Case: Handle case where all names might be used |
| 29 | if len(Robot._used_names) >= len(Robot._name_pool): |
| 30 | raise RuntimeError("All possible robot names have been used") |
| 31 | self._assign_name() |
| 32 | |
| 33 | def _assign_name(self) -> None: |
| 34 | # Edge Case: Assign a new name from the pool |
| 35 | while True: |
| 36 | if not Robot._name_pool: |
| 37 | # This should never happen with 676000 possible names |
| 38 | raise RuntimeError("Name pool is unexpectedly empty") |
| 39 | candidate_name = Robot._name_pool.pop() |
| 40 | if candidate_name not in Robot._used_names: |
| 41 | self._name = candidate_name |
| 42 | Robot._used_names.add(self._name) |
| 43 | break |
| 44 | |
| 45 | @classmethod |
| 46 | def _generate_name_pool(cls) -> None: |
| 47 | # Edge Case: Generate all possible names and shuffle them |
| 48 | letters = string.ascii_uppercase |
| 49 | digits = string.digits |
| 50 | |
| 51 | # Generate all possible combinations |
| 52 | for first_letter in letters: |
| 53 | for second_letter in letters: |
| 54 | for digit1 in digits: |
| 55 | for digit2 in digits: |
| 56 | for digit3 in digits: |
| 57 | cls._name_pool.append(f"{first_letter}{second_letter}{digit1}{digit2}{digit3}") |
| 58 | |
| 59 | # Shuffle the pool randomly |
| 60 | random.shuffle(cls._name_pool) |
| 61 | |
| 62 | # Handled Edge Cases: Empty name pool initialization, all names used, name assignment, name reset, pool exhaustion |