From 895a4362a18395f2382f5d90b76c83034ab469a3 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 26 Nov 2025 17:13:47 +0100 Subject: [PATCH 1/6] Run bin/configlet sync --- .../ocr-numbers/.docs/instructions.md | 80 ++++++------------- .../practice/ocr-numbers/.meta/config.json | 2 +- 2 files changed, 25 insertions(+), 57 deletions(-) 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..fd67fb75 100644 --- a/exercises/practice/ocr-numbers/.meta/config.json +++ b/exercises/practice/ocr-numbers/.meta/config.json @@ -21,5 +21,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/" } From 16a06b802fe9783d641453462784c2acc97a6814 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 26 Nov 2025 17:15:55 +0100 Subject: [PATCH 2/6] Drop strict types comments --- .../practice/ocr-numbers/.meta/example.php | 22 ------------------- .../practice/ocr-numbers/OcrNumbersTest.php | 22 ------------------- 2 files changed, 44 deletions(-) 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..132ad45a 100644 --- a/exercises/practice/ocr-numbers/OcrNumbersTest.php +++ b/exercises/practice/ocr-numbers/OcrNumbersTest.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); use PHPUnit\Framework\TestCase; From ffa844ddc332de1471aedff06ad7b1f9878a16cf Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 26 Nov 2025 17:16:14 +0100 Subject: [PATCH 3/6] Raise to medium difficulty --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 3e9b916bc150a92065a43e55d4dbd3bf76232345 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 26 Nov 2025 17:16:27 +0100 Subject: [PATCH 4/6] Add me as contributor --- exercises/practice/ocr-numbers/.meta/config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/practice/ocr-numbers/.meta/config.json b/exercises/practice/ocr-numbers/.meta/config.json index fd67fb75..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": [ From 7c2e5ff19256a0b61d9bdc2f6affde1d65cc5a5f Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 26 Nov 2025 17:31:43 +0100 Subject: [PATCH 5/6] Add and sync test meta data to tests --- .../practice/ocr-numbers/OcrNumbersTest.php | 74 ++++++++++++++++--- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/exercises/practice/ocr-numbers/OcrNumbersTest.php b/exercises/practice/ocr-numbers/OcrNumbersTest.php index 132ad45a..e79f3062 100644 --- a/exercises/practice/ocr-numbers/OcrNumbersTest.php +++ b/exercises/practice/ocr-numbers/OcrNumbersTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; class OcrNumbersTest extends TestCase @@ -12,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 = [ @@ -26,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 = [ @@ -38,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 = [ " ", @@ -52,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); @@ -67,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); @@ -82,6 +90,10 @@ public function testErrorWrongNumberOfColumns(): void recognize($input); } + /** + * uuid: 4a841794-73c9-4da9-a779-1f9837faff66 + */ + #[TestDox('Recognizes 110101100')] public function testRecognizes110101100(): void { $input = [ @@ -94,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 = [ " _ _ _ ", @@ -107,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 = [ @@ -118,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 = [ @@ -129,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 = [ @@ -140,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 = [ @@ -151,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 = [ @@ -162,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 = [ @@ -173,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 = [ @@ -184,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 = [ @@ -195,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 = [ @@ -207,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 = [ " _ _ ", From 72293e4afd15c79524baba922160edb2269dc673 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 26 Nov 2025 17:32:00 +0100 Subject: [PATCH 6/6] Add exercise to bin/auto-sync.txt --- bin/auto-sync.txt | 1 + 1 file changed, 1 insertion(+) 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