Finished
11def 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)
358
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
Test NameStatus
test_garbled_numbers_in_a_string_are_replaced_with
Pass
test_input_with_a_number_of_columns_that_is_not_a_multiple_of_three_raises_an_error
Pass
test_input_with_a_number_of_lines_that_is_not_a_multiple_of_four_raises_an_error
Pass
test_numbers_separated_by_empty_lines_are_recognized_lines_are_joined_by_commas
Pass
test_recognizes_0
Pass
test_recognizes_1
Pass
test_recognizes_110101100
Pass
test_recognizes_2
Pass
test_recognizes_3
Pass
test_recognizes_4
Pass
test_recognizes_5
Pass
test_recognizes_6
Pass
test_recognizes_7
Pass
test_recognizes_8
Pass
test_recognizes_9
Pass
test_recognizes_string_of_decimal_numbers
Pass
test_unreadable_but_correctly_sized_inputs_return
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.