| 1 | 1 | def convert(input_grid): |
| 2 | | pass |
| 2 | # Edge Case: Empty input |
| 3 | if not input_grid: |
| 4 | return "" |
| 5 | |
| 6 | # Edge Case: Number of input lines is not a multiple of four |
| 7 | if len(input_grid) % 4 != 0: |
| 8 | raise ValueError("Number of input lines is not a multiple of four") |
| 9 | |
| 10 | # Edge Case: Inconsistent row lengths |
| 11 | row_length = len(input_grid[0]) |
| 12 | for row in input_grid: |
| 13 | if len(row) != row_length: |
| 14 | raise ValueError("All rows must have the same length") |
| 15 | |
| 16 | # Edge Case: Number of input columns is not a multiple of three |
| 17 | if row_length % 3 != 0: |
| 18 | raise ValueError("Number of input columns is not a multiple of three") |
| 19 | |
| 20 | # Define digit patterns |
| 21 | patterns = { |
| 22 | (" _ ", "| |", "|_|", " "): "0", |
| 23 | (" ", " |", " |", " "): "1", |
| 24 | (" _ ", " _|", "|_ ", " "): "2", |
| 25 | (" _ ", " _|", " _|", " "): "3", |
| 26 | (" ", "|_|", " |", " "): "4", |
| 27 | (" _ ", "|_ ", " _|", " "): "5", |
| 28 | (" _ ", "|_ ", "|_|", " "): "6", |
| 29 | (" _ ", " |", " |", " "): "7", |
| 30 | (" _ ", "|_|", "|_|", " "): "8", |
| 31 | (" _ ", "|_|", " _|", " "): "9" |
| 32 | } |
| 33 | |
| 34 | result_lines = [] |
| 35 | |
| 36 | # Process each 4-row group |
| 37 | for line_group_start in range(0, len(input_grid), 4): |
| 38 | line_group = input_grid[line_group_start:line_group_start+4] |
| 39 | num_digits = len(line_group[0]) // 3 |
| 40 | line_result = "" |
| 41 | |
| 42 | # Process each 3-column digit in the current line group |
| 43 | for digit_index in range(num_digits): |
| 44 | # Extract the 3x4 pattern for this digit |
| 45 | digit_pattern = [] |
| 46 | for row in range(4): |
| 47 | start_col = digit_index * 3 |
| 48 | end_col = start_col + 3 |
| 49 | digit_pattern.append(line_group[row][start_col:end_col]) |
| 50 | |
| 51 | # Convert pattern to digit or '?' |
| 52 | digit_tuple = tuple(digit_pattern) |
| 53 | line_result += patterns.get(digit_tuple, "?") |
| 54 | |
| 55 | result_lines.append(line_result) |
| 56 | |
| 57 | return ",".join(result_lines) |
| 3 | 58 | |
| 59 | # Handled Edge Cases: Empty input, Number of input lines is not a multiple of four, Inconsistent row lengths, Number of input columns is not a multiple of three |