diff --git a/bin/auto-sync.txt b/bin/auto-sync.txt index 76fea216..ba848805 100644 --- a/bin/auto-sync.txt +++ b/bin/auto-sync.txt @@ -49,6 +49,7 @@ matching-brackets meetup micro-blog nucleotide-count +ocr-numbers pangram pascals-triangle phone-number diff --git a/config.json b/config.json index b3614357..2c4111f1 100644 --- a/config.json +++ b/config.json @@ -953,7 +953,7 @@ "uuid": "a7a269a5-e99c-4fcf-b331-9a130e94f9e4", "practices": [], "prerequisites": [], - "difficulty": 3, + "difficulty": 5, "topics": [ "algorithms", "strings", diff --git a/exercises/practice/ocr-numbers/.docs/instructions.md b/exercises/practice/ocr-numbers/.docs/instructions.md index 7beb2577..8a391ce4 100644 --- a/exercises/practice/ocr-numbers/.docs/instructions.md +++ b/exercises/practice/ocr-numbers/.docs/instructions.md @@ -1,79 +1,47 @@ # Instructions -Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled. +Optical Character Recognition or OCR is software that converts images of text into machine-readable text. +Given a grid of characters representing some digits, convert the grid to a string of digits. +If the grid has multiple rows of cells, the rows should be separated in the output with a `","`. -## Step One +- The grid is made of one of more lines of cells. +- Each line of the grid is made of one or more cells. +- Each cell is three columns wide and four rows high (3x4) and represents one digit. +- Digits are drawn using pipes (`"|"`), underscores (`"_"`), and spaces (`" "`). -To begin with, convert a simple binary font to a string containing 0 or 1. +## Edge cases -The binary font uses pipes and underscores, four rows high and three columns wide. +- If the input is not a valid size, your program should indicate there is an error. +- If the input is the correct size, but a cell is not recognizable, your program should output a `"?"` for that character. -```text - _ # - | | # zero. - |_| # - # the fourth row is always blank -``` +## Examples -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" +The following input (without the comments) is converted to `"1234567890"`. ```text _ _ _ _ _ _ _ _ # - | _| _||_||_ |_ ||_||_|| | # decimal numbers. + | _| _||_||_ |_ ||_||_|| | # Decimal numbers. ||_ _| | _||_| ||_| _||_| # - # fourth line is always blank + # The fourth line is always blank, ``` -Is converted to "1234567890" - -## Step Four +The following input is converted to `"123,456,789"`. -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 index 78bf120b..7867a652 100644 --- a/exercises/practice/ocr-numbers/.meta/config.json +++ b/exercises/practice/ocr-numbers/.meta/config.json @@ -6,7 +6,8 @@ "arueckauer", "G-Rath", "kytrinyx", - "petemcfarlane" + "petemcfarlane", + "mk-mxp" ], "files": { "solution": [ @@ -21,5 +22,5 @@ }, "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/cgi-bin/wiki.pl?KataBankOCR" + "source_url": "https://codingdojo.org/kata/BankOCR/" } diff --git a/exercises/practice/ocr-numbers/.meta/example.php b/exercises/practice/ocr-numbers/.meta/example.php index 0fdd8434..8e6e6193 100644 --- a/exercises/practice/ocr-numbers/.meta/example.php +++ b/exercises/practice/ocr-numbers/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); function recognize($ocr) diff --git a/exercises/practice/ocr-numbers/OcrNumbersTest.php b/exercises/practice/ocr-numbers/OcrNumbersTest.php index 6418bbbd..e79f3062 100644 --- a/exercises/practice/ocr-numbers/OcrNumbersTest.php +++ b/exercises/practice/ocr-numbers/OcrNumbersTest.php @@ -1,29 +1,8 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; class OcrNumbersTest extends TestCase @@ -34,9 +13,9 @@ public static function setUpBeforeClass(): void } /** - * Recognition result should be returned as a string + * uuid: 5ee54e1a-b554-4bf3-a056-9a7976c3f7e8 */ - + #[TestDox('Recognizes 0')] public function testRecognizes0(): void { $input = [ @@ -48,6 +27,10 @@ public function testRecognizes0(): void $this->assertSame('0', recognize($input)); } + /** + * uuid: 027ada25-17fd-4d78-aee6-35a19623639d + */ + #[TestDox('Recognizes 1')] public function testRecognizes1(): void { $input = [ @@ -60,9 +43,10 @@ public function testRecognizes1(): void } /** - * Unreadable but correctly sized inputs return ? + * uuid: 3cce2dbd-01d9-4f94-8fae-419a822e89bb */ - public function testUnreadable(): void + #[TestDox('Unreadable but correctly sized inputs return ?')] + public function testUnreadableButCorrectlySizedInputsReturnQuestionmark(): void { $input = [ " ", @@ -74,9 +58,10 @@ public function testUnreadable(): void } /** - * Input with a number of lines that is not a multiple of four raises an error + * uuid: cb19b733-4e36-4cf9-a4a1-6e6aac808b9a */ - public function testErrorWrongNumberOfLines(): void + #[TestDox('Input with a number of lines that is not a multiple of four raises an error')] + public function testInputWithANumberOfLinesThatIsNotAMultipleOfFourRaisesAnError(): void { $this->expectException(InvalidArgumentException::class); @@ -89,9 +74,10 @@ public function testErrorWrongNumberOfLines(): void } /** - * Input with a number of columns that is not a multiple of three raises an error + * uuid: 235f7bd1-991b-4587-98d4-84206eec4cc6 */ - public function testErrorWrongNumberOfColumns(): void + #[TestDox('Input with a number of columns that is not a multiple of three raises an error')] + public function testInputWithANumberOfColumnsThatIsNotAMultipleOfThreeRaisesAnError(): void { $this->expectException(InvalidArgumentException::class); @@ -104,6 +90,10 @@ public function testErrorWrongNumberOfColumns(): void recognize($input); } + /** + * uuid: 4a841794-73c9-4da9-a779-1f9837faff66 + */ + #[TestDox('Recognizes 110101100')] public function testRecognizes110101100(): void { $input = [ @@ -116,9 +106,10 @@ public function testRecognizes110101100(): void } /** - * Garbled numbers in a string are replaced with ? + * uuid: 70c338f9-85b1-4296-a3a8-122901cdfde8 */ - public function testGarbled(): void + #[TestDox('Garbled numbers in a string are replaced with ?')] + public function testGarbledNumbersInAStringAreReplacedWithQuestionmark(): void { $input = [ " _ _ _ ", @@ -129,6 +120,10 @@ public function testGarbled(): void $this->assertSame('11?10?1?0', recognize($input)); } + /** + * uuid: ea494ff4-3610-44d7-ab7e-72fdef0e0802 + */ + #[TestDox('Recognizes 2')] public function testRecognizes2(): void { $input = [ @@ -140,6 +135,10 @@ public function testRecognizes2(): void $this->assertSame('2', recognize($input)); } + /** + * uuid: 1acd2c00-412b-4268-93c2-bd7ff8e05a2c + */ + #[TestDox('Recognizes 3')] public function testRecognizes3(): void { $input = [ @@ -151,6 +150,10 @@ public function testRecognizes3(): void $this->assertSame('3', recognize($input)); } + /** + * uuid: eaec6a15-be17-4b6d-b895-596fae5d1329 + */ + #[TestDox('Recognizes 4')] public function testRecognizes4(): void { $input = [ @@ -162,6 +165,10 @@ public function testRecognizes4(): void $this->assertSame('4', recognize($input)); } + /** + * uuid: 440f397a-f046-4243-a6ca-81ab5406c56e + */ + #[TestDox('Recognizes 5')] public function testRecognizes5(): void { $input = [ @@ -173,6 +180,10 @@ public function testRecognizes5(): void $this->assertSame('5', recognize($input)); } + /** + * uuid: f4c9cf6a-f1e2-4878-bfc3-9b85b657caa0 + */ + #[TestDox('Recognizes 6')] public function testRecognizes6(): void { $input = [ @@ -184,6 +195,10 @@ public function testRecognizes6(): void $this->assertSame('6', recognize($input)); } + /** + * uuid: e24ebf80-c611-41bb-a25a-ac2c0f232df5 + */ + #[TestDox('Recognizes 7')] public function testRecognizes7(): void { $input = [ @@ -195,6 +210,10 @@ public function testRecognizes7(): void $this->assertSame('7', recognize($input)); } + /** + * uuid: b79cad4f-e264-4818-9d9e-77766792e233 + */ + #[TestDox('Recognizes 8')] public function testRecognizes8(): void { $input = [ @@ -206,6 +225,10 @@ public function testRecognizes8(): void $this->assertSame('8', recognize($input)); } + /** + * uuid: 5efc9cfc-9227-4688-b77d-845049299e66 + */ + #[TestDox('Recognizes 9')] public function testRecognizes9(): void { $input = [ @@ -217,6 +240,10 @@ public function testRecognizes9(): void $this->assertSame('9', recognize($input)); } + /** + * uuid: f60cb04a-42be-494e-a535-3451c8e097a4 + */ + #[TestDox('Recognizes string of decimal numbers')] public function testRecognizesStringOfDecimalNumbers(): void { $input = [ @@ -229,9 +256,10 @@ public function testRecognizesStringOfDecimalNumbers(): void } /** - * Numbers separated by empty lines are recognized. Lines are joined by commas. + * uuid: b73ecf8b-4423-4b36-860d-3710bdb8a491 */ - public function testLinesWithCommas(): void + #[TestDox('Numbers separated by empty lines are recognized. Lines are joined by commas.')] + public function testNumbersSeparatedByEmptyLinesAreRecognizedLinesAreJoinedByCommas(): void { $input = [ " _ _ ",