>>> parse_moves("0 1, 1 1") [(0, 1), (1, 1)] >>> parse_moves("0 1, 1 1, 2") Traceback (most recent call last): ... ValueError: Each move must have exactly two numbers. >>> parse_moves("0 1, 1 1, 2 4 5 6") Traceback (most recent call last): ... ValueEr
(input_str: str)
| 103 | |
| 104 | |
| 105 | def parse_moves(input_str: str) -> list[tuple[int, int]]: |
| 106 | """ |
| 107 | >>> parse_moves("0 1, 1 1") |
| 108 | [(0, 1), (1, 1)] |
| 109 | >>> parse_moves("0 1, 1 1, 2") |
| 110 | Traceback (most recent call last): |
| 111 | ... |
| 112 | ValueError: Each move must have exactly two numbers. |
| 113 | >>> parse_moves("0 1, 1 1, 2 4 5 6") |
| 114 | Traceback (most recent call last): |
| 115 | ... |
| 116 | ValueError: Each move must have exactly two numbers. |
| 117 | """ |
| 118 | moves = [] |
| 119 | for pair in input_str.split(","): |
| 120 | parts = pair.strip().split() |
| 121 | if len(parts) != 2: |
| 122 | raise ValueError("Each move must have exactly two numbers.") |
| 123 | x, y = map(int, parts) |
| 124 | moves.append((x, y)) |
| 125 | return moves |
| 126 | |
| 127 | |
| 128 | def find_repeat( |
no test coverage detected