diff --git a/config.json b/config.json index 85dbb26..85a074a 100644 --- a/config.json +++ b/config.json @@ -586,6 +586,14 @@ "prerequisites": [], "difficulty": 6 }, + { + "slug": "ocr-numbers", + "name": "OCR Numbers", + "uuid": "c4ffd3ea-1586-4fb0-9738-f4a0d232e118", + "practices": [], + "prerequisites": [], + "difficulty": 6 + }, { "slug": "parallel-letter-frequency", "name": "Parallel Letter Frequency", diff --git a/exercises/practice/ocr-numbers/.docs/instructions.md b/exercises/practice/ocr-numbers/.docs/instructions.md new file mode 100644 index 0000000..7beb257 --- /dev/null +++ b/exercises/practice/ocr-numbers/.docs/instructions.md @@ -0,0 +1,79 @@ +# Instructions + +Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled. + +## Step One + +To begin with, convert a simple binary font to a string containing 0 or 1. + +The binary font uses pipes and underscores, four rows high and three columns wide. + +```text + _ # + | | # zero. + |_| # + # the fourth row is always blank +``` + +Is converted to "0" + +```text + # + | # 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 + +Update your program to recognize multi-character binary strings, replacing garbled numbers with ? + +## Step Three + +Update your program to recognize all numbers 0 through 9, both individually and as part of a larger string. + +```text + _ + _| +|_ + +``` + +Is converted to "2" + +```text + _ _ _ _ _ _ _ _ # + | _| _||_||_ |_ ||_||_|| | # 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. + +```text + _ _ + | _| _| + ||_ _| + + _ _ +|_||_ |_ + | _||_| + + _ _ _ + ||_||_| + ||_| _| + +``` + +Is converted to "123,456,789". diff --git a/exercises/practice/ocr-numbers/.meta/config.json b/exercises/practice/ocr-numbers/.meta/config.json new file mode 100644 index 0000000..232e1c5 --- /dev/null +++ b/exercises/practice/ocr-numbers/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "erikschierboom" + ], + "files": { + "solution": [ + "ocr-numbers.ua" + ], + "test": [ + "tests.ua" + ], + "example": [ + ".meta/example.ua" + ] + }, + "blurb": "Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.", + "source": "Inspired by the Bank OCR kata", + "source_url": "https://codingdojo.org/kata/BankOCR/" +} diff --git a/exercises/practice/ocr-numbers/.meta/example.ua b/exercises/practice/ocr-numbers/.meta/example.ua new file mode 100644 index 0000000..f63c6ed --- /dev/null +++ b/exercises/practice/ocr-numbers/.meta/example.ua @@ -0,0 +1,31 @@ +Shapes ← [ + " " + " |" + " _ " + " _|" + "| |" + "|_ " + "|_|" +] +Encodings ← [ + 2_4_6_0 + 0_1_1_0 + 2_3_5_0 + 2_3_3_0 + 0_6_1_0 + 2_5_3_0 + 2_5_6_0 + 2_1_1_0 + 2_6_6_0 + 2_6_3_0 +] +Encoding ← ≡(⊗⟜Shapes) +Lines ← ≡(↙4↘)×4⊙¤⇡÷4⊢△. +Digits ← ≡≡(↙3↘)×3⊙¤⇡÷3⊣△. +Number ← ⨬("?"|°⋕) <10. ⊗⟜Encodings Encoding +Numbers ← /⊂≡Number Digits +Validate ← ⊃( + ⍤"Number of input lines is not a multiple of four"=0◿4⊢ +| ⍤"Number of input columns is not a multiple of three"=0◿3⊣ +) △ +Convert ← /$"_,_" ≡Numbers Lines ⊸Validate diff --git a/exercises/practice/ocr-numbers/.meta/tests.toml b/exercises/practice/ocr-numbers/.meta/tests.toml new file mode 100644 index 0000000..0d7a5b7 --- /dev/null +++ b/exercises/practice/ocr-numbers/.meta/tests.toml @@ -0,0 +1,61 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[5ee54e1a-b554-4bf3-a056-9a7976c3f7e8] +description = "Recognizes 0" + +[027ada25-17fd-4d78-aee6-35a19623639d] +description = "Recognizes 1" + +[3cce2dbd-01d9-4f94-8fae-419a822e89bb] +description = "Unreadable but correctly sized inputs return ?" + +[cb19b733-4e36-4cf9-a4a1-6e6aac808b9a] +description = "Input with a number of lines that is not a multiple of four raises an error" + +[235f7bd1-991b-4587-98d4-84206eec4cc6] +description = "Input with a number of columns that is not a multiple of three raises an error" + +[4a841794-73c9-4da9-a779-1f9837faff66] +description = "Recognizes 110101100" + +[70c338f9-85b1-4296-a3a8-122901cdfde8] +description = "Garbled numbers in a string are replaced with ?" + +[ea494ff4-3610-44d7-ab7e-72fdef0e0802] +description = "Recognizes 2" + +[1acd2c00-412b-4268-93c2-bd7ff8e05a2c] +description = "Recognizes 3" + +[eaec6a15-be17-4b6d-b895-596fae5d1329] +description = "Recognizes 4" + +[440f397a-f046-4243-a6ca-81ab5406c56e] +description = "Recognizes 5" + +[f4c9cf6a-f1e2-4878-bfc3-9b85b657caa0] +description = "Recognizes 6" + +[e24ebf80-c611-41bb-a25a-ac2c0f232df5] +description = "Recognizes 7" + +[b79cad4f-e264-4818-9d9e-77766792e233] +description = "Recognizes 8" + +[5efc9cfc-9227-4688-b77d-845049299e66] +description = "Recognizes 9" + +[f60cb04a-42be-494e-a535-3451c8e097a4] +description = "Recognizes string of decimal numbers" + +[b73ecf8b-4423-4b36-860d-3710bdb8a491] +description = "Numbers separated by empty lines are recognized. Lines are joined by commas." diff --git a/exercises/practice/ocr-numbers/ocr-numbers.ua b/exercises/practice/ocr-numbers/ocr-numbers.ua new file mode 100644 index 0000000..3bb5d8e --- /dev/null +++ b/exercises/practice/ocr-numbers/ocr-numbers.ua @@ -0,0 +1,3 @@ +# Convert a display of digits to their numeric counterparts +# Result ? Display +Convert ← |1 ⊙(⍤"Please implement Convert" 0) diff --git a/exercises/practice/ocr-numbers/tests.ua b/exercises/practice/ocr-numbers/tests.ua new file mode 100644 index 0000000..8004b6b --- /dev/null +++ b/exercises/practice/ocr-numbers/tests.ua @@ -0,0 +1,161 @@ +~ "ocr-numbers.ua" ~ Convert + +# Recognizes 0 +Display ← [ + " _ " + "| |" + "|_|" + " " +] +⍤⤙≍ "0" Convert Display + +# Recognizes 1 +Display ← [ + " " + " |" + " |" + " " +] +⍤⤙≍ "1" Convert Display + +# Unreadable but correctly sized displays return ? +Display ← [ + " " + " _" + " |" + " " +] +⍤⤙≍ "?" Convert Display + +# Display with a number of lines that is not a multiple of four raises an error +Display ← [ + " _ " + "| |" + " " +] +⍤⤙≍ "Number of input lines is not a multiple of four" ⍣(Convert Display) + +# Display with a number of columns that is not a multiple of three raises an error +Display ← [ + " " + " |" + " |" + " " +] +⍤⤙≍ "Number of input columns is not a multiple of three" ⍣(Convert Display) + +# Recognizes 110101100 +Display ← [ + " _ _ _ _ " + " | || | || | | || || |" + " | ||_| ||_| | ||_||_|" + " " +] +⍤⤙≍ "110101100" Convert Display + +# Garbled numbers in a string are replaced with ? +Display ← [ + " _ _ _ " + " | || | || | || || |" + " | | _| ||_| | ||_||_|" + " " +] +⍤⤙≍ "11?10?1?0" Convert Display + +# Recognizes 2 +Display ← [ + " _ " + " _|" + "|_ " + " " +] +⍤⤙≍ "2" Convert Display + +# Recognizes 3 +Display ← [ + " _ " + " _|" + " _|" + " " +] +⍤⤙≍ "3" Convert Display + +# Recognizes 4 +Display ← [ + " " + "|_|" + " |" + " " +] +⍤⤙≍ "4" Convert Display + +# Recognizes 5 +Display ← [ + " _ " + "|_ " + " _|" + " " +] +⍤⤙≍ "5" Convert Display + +# Recognizes 6 +Display ← [ + " _ " + "|_ " + "|_|" + " " +] +⍤⤙≍ "6" Convert Display + +# Recognizes 7 +Display ← [ + " _ " + " |" + " |" + " " +] +⍤⤙≍ "7" Convert Display + +# Recognizes 8 +Display ← [ + " _ " + "|_|" + "|_|" + " " +] +⍤⤙≍ "8" Convert Display + +# Recognizes 9 +Display ← [ + " _ " + "|_|" + " _|" + " " +] +⍤⤙≍ "9" Convert Display + +# Recognizes string of decimal numbers +Display ← [ + " _ _ _ _ _ _ _ _ " + " | _| _||_||_ |_ ||_||_|| |" + " ||_ _| | _||_| ||_| _||_|" + " " +] +⍤⤙≍ "1234567890" Convert Display + +# Numbers separated by empty lines are recognized. Lines are joined by commas. +Display ← [ + " _ _ " + " | _| _|" + " ||_ _|" + " " + " _ _ " + "|_||_ |_ " + " | _||_|" + " " + " _ _ _ " + " ||_||_|" + " ||_| _|" + " " +] +⍤⤙≍ "123,456,789" Convert Display