diff --git a/ocr-numbers.json b/ocr-numbers.json new file mode 100644 index 0000000000..4d422480aa --- /dev/null +++ b/ocr-numbers.json @@ -0,0 +1,187 @@ +{ + "#": [ + "An expectation of -1 indicates that a failure should be raised" + ], + "convert": { + "description": "Converts lines of OCR Numbers to a string of integers", + "cases": [ + { + "description": "Recognizes 0", + "input": [ + " _ ", + "| |", + "|_|", + " " + ], + "expected": "0" + }, + { + "description": "Recognizes 1", + "input": [ + " ", + " |", + " |", + " " + ], + "expected": "1" + }, + { + "description": "Unreadable but correctly sized inputs return ?", + "input": [ + " ", + " _", + " |", + " " + ], + "expected": "?" + }, + { + "description": "Input with a number of lines that is not a multiple of four raises an error", + "input": [ + " _ ", + "| |", + " " + ], + "expected": -1 + }, + { + "description": "Input with a number of columns that is not a multiple of three raises an error", + "input": [ + " ", + " |", + " |", + " " + ], + "expected": -1 + }, + { + "description": "Recognizes 110101100", + "input": [ + " _ _ _ _ ", + " | || | || | | || || |", + " | ||_| ||_| | ||_||_|", + " " + ], + "expected": "110101100" + }, + { + "description": "Garbled numbers in a string are replaced with ?", + "input": [ + " _ _ _ ", + " | || | || | || || |", + " | | _| ||_| | ||_||_|", + " " + ], + "expected": "11?10?1?0" + }, + { + "description": "Recognizes 2", + "input": [ + " _ ", + " _|", + "|_ ", + " " + ], + "expected": "2" + }, + { + "description": "Recognizes 3", + "input": [ + " _ ", + " _|", + " _|", + " " + ], + "expected": "3" + }, + { + "description": "Recognizes 4", + "input": [ + " ", + "|_|", + " |", + " " + ], + "expected": "4" + }, + { + "description": "Recognizes 5", + "input": [ + " _ ", + "|_ ", + " _|", + " " + ], + "expected": "5" + }, + { + "description": "Recognizes 6", + "input": [ + " _ ", + "|_ ", + "|_|", + " " + ], + "expected": "6" + }, + { + "description": "Recognizes 7", + "input": [ + " _ ", + " |", + " |", + " " + ], + "expected": "7" + }, + { + "description": "Recognizes 8", + "input": [ + " _ ", + "|_|", + "|_|", + " " + ], + "expected": "8" + }, + { + "description": "Recognizes 9", + "input": [ + " _ ", + "|_|", + " _|", + " " + ], + "expected": "9" + }, + { + "description": "Recognizes string of decimal numbers", + "input": [ + " _ _ _ _ _ _ _ _ ", + " | _| _||_||_ |_ ||_||_|| |", + " ||_ _| | _||_| ||_| _||_|", + " " + ], + "expected": "1234567890" + }, + { + "description": "Numbers separated by empty lines are recognized. Lines are joined by commas.", + "input": [ + " _ _ ", + " | _| _|", + " ||_ _|", + " ", + " _ _ ", + "|_||_ |_ ", + " | _||_|", + " ", + " _ _ _ ", + " ||_||_|", + " ||_| _|", + " " + ], + "expected": "123,456,789" + } + ] + } +} diff --git a/ocr-numbers.md b/ocr-numbers.md index bb412ce9cb..7628d55f31 100644 --- a/ocr-numbers.md +++ b/ocr-numbers.md @@ -1,36 +1,74 @@ -## Step 1 +# Step One -A simple binary font has been constructed using only pipes and -underscores. +To begin with, convert a simple binary font to a string containing 0 or 1. -The number is four rows high, three columns wide: +The binary font uses pipes and underscores, four rows high and three columns wide. +``` _ # | | # zero. |_| # # the fourth row is always blank +``` +Is converted to "0" + +``` # | # one. | # # (blank fourth row) +``` + +Is converted to "1" + +If the input is the correct size, but not recognizable, your program should return '?' + +If the input is the incorrect size, your program should return an error. + +# Step Two -Write a program that, given a 3 x 4 grid of pipes, underscores, and -spaces, can determine whether the the grid represents a zero, a one, or -garble. +Update your program to recognize multi-character binary strings, replacing garbled numbers with ? -Anything else is considered garble, and can be represented with a '?' +# Step Three -## Step 2 +Update your program to recognize all numbers 0 through 9, both individually and as part of a larger string. -A simple numeric font has been constructed using only pipes and -underscores. +``` + _ + _| +|_ + +``` -The number consists of four rows high, three columns wide: +Is converted to "2" +``` _ _ _ _ _ _ _ _ # | _| _||_||_ |_ ||_||_|| | # decimal numbers. ||_ _| | _||_| ||_| _||_| # # fourth line is always blank +``` + +Is converted to "1234567890" + +# Step Four + +Update your program to handle multiple numbers, one per line. When converting several lines, join the lines with commas. + +``` + _ _ + | _| _| + ||_ _| + + _ _ +|_||_ |_ + | _||_| + + _ _ _ + ||_||_| + ||_| _| + +``` -There may be several numbers in the input text, one per line. +Is converted to "123,456,789"