From e9fb90b68fa3c132ad7e4d9943907ea0fc78baea Mon Sep 17 00:00:00 2001 From: Obinna Emmanuel Obi-Akwari Date: Tue, 19 May 2026 17:17:29 +0100 Subject: [PATCH 1/3] sync palindrome-products docs --- .../palindrome-products/.docs/instructions.md | 21 +++++++++------- .../palindrome-products/.meta/tests.toml | 24 +++++++++++++------ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/exercises/practice/palindrome-products/.docs/instructions.md b/exercises/practice/palindrome-products/.docs/instructions.md index fd9a44124..aac66521c 100644 --- a/exercises/practice/palindrome-products/.docs/instructions.md +++ b/exercises/practice/palindrome-products/.docs/instructions.md @@ -2,15 +2,14 @@ Detect palindrome products in a given range. -A palindromic number is a number that remains the same when its digits are -reversed. For example, `121` is a palindromic number but `112` is not. +A palindromic number is a number that remains the same when its digits are reversed. +For example, `121` is a palindromic number but `112` is not. Given a range of numbers, find the largest and smallest palindromes which are products of two numbers within that range. -Your solution should return the largest and smallest palindromes, along with the -factors of each within the range. If the largest or smallest palindrome has more -than one pair of factors within the range, then return all the pairs. +Your solution should return the largest and smallest palindromes, along with the factors of each within the range. +If the largest or smallest palindrome has more than one pair of factors within the range, then return all the pairs. ## Example 1 @@ -22,12 +21,16 @@ And given the list of all possible products within this range: The palindrome products are all single digit numbers (in this case): `[1, 2, 3, 4, 5, 6, 7, 8, 9]` -The smallest palindrome product is `1`. Its factors are `(1, 1)`. -The largest palindrome product is `9`. Its factors are `(1, 9)` and `(3, 3)`. +The smallest palindrome product is `1`. +Its factors are `(1, 1)`. +The largest palindrome product is `9`. +Its factors are `(1, 9)` and `(3, 3)`. ## Example 2 Given the range `[10, 99]` (both inclusive)... -The smallest palindrome product is `121`. Its factors are `(11, 11)`. -The largest palindrome product is `9009`. Its factors are `(91, 99)`. +The smallest palindrome product is `121`. +Its factors are `(11, 11)`. +The largest palindrome product is `9009`. +Its factors are `(91, 99)`. diff --git a/exercises/practice/palindrome-products/.meta/tests.toml b/exercises/practice/palindrome-products/.meta/tests.toml index b34cb0d47..a3bc41750 100644 --- a/exercises/practice/palindrome-products/.meta/tests.toml +++ b/exercises/practice/palindrome-products/.meta/tests.toml @@ -1,12 +1,19 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# 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. [5cff78fe-cf02-459d-85c2-ce584679f887] -description = "finds the smallest palindrome from single digit factors" +description = "find the smallest palindrome from single digit factors" [0853f82c-5fc4-44ae-be38-fadb2cced92d] -description = "finds the largest palindrome from single digit factors" +description = "find the largest palindrome from single digit factors" [66c3b496-bdec-4103-9129-3fcb5a9063e1] description = "find the smallest palindrome from double digit factors" @@ -15,13 +22,13 @@ description = "find the smallest palindrome from double digit factors" description = "find the largest palindrome from double digit factors" [cecb5a35-46d1-4666-9719-fa2c3af7499d] -description = "find smallest palindrome from triple digit factors" +description = "find the smallest palindrome from triple digit factors" [edab43e1-c35f-4ea3-8c55-2f31dddd92e5] description = "find the largest palindrome from triple digit factors" [4f802b5a-9d74-4026-a70f-b53ff9234e4e] -description = "find smallest palindrome from four digit factors" +description = "find the smallest palindrome from four digit factors" [787525e0-a5f9-40f3-8cb2-23b52cf5d0be] description = "find the largest palindrome from four digit factors" @@ -37,3 +44,6 @@ description = "error result for smallest if min is more than max" [eeeb5bff-3f47-4b1e-892f-05829277bd74] description = "error result for largest if min is more than max" + +[16481711-26c4-42e0-9180-e2e4e8b29c23] +description = "smallest product does not use the smallest factor" From 7fb787f0d4f17c4aa451459ff11b26f08828bb34 Mon Sep 17 00:00:00 2001 From: Obinna Emmanuel Obi-Akwari Date: Tue, 19 May 2026 17:51:48 +0100 Subject: [PATCH 2/3] Add exercise to auto-sync.txt and adjust test cases and add missing test --- bin/auto-sync.txt | 1 + .../palindrome-products/.meta/config.json | 3 +- .../palindrome-products/.meta/example.php | 22 ----- .../PalindromeProductsTest.php | 90 ++++++++++++++----- 4 files changed, 71 insertions(+), 45 deletions(-) diff --git a/bin/auto-sync.txt b/bin/auto-sync.txt index e778bab71..914780102 100644 --- a/bin/auto-sync.txt +++ b/bin/auto-sync.txt @@ -53,6 +53,7 @@ nth-prime micro-blog nucleotide-count ocr-numbers +palindrome-products pangram pascals-triangle perfect-numbers diff --git a/exercises/practice/palindrome-products/.meta/config.json b/exercises/practice/palindrome-products/.meta/config.json index 1f49ebd30..1a13c19f4 100644 --- a/exercises/practice/palindrome-products/.meta/config.json +++ b/exercises/practice/palindrome-products/.meta/config.json @@ -4,7 +4,8 @@ ], "contributors": [ "arueckauer", - "yisraeldov" + "yisraeldov", + "A-O-Emmanuel" ], "files": { "solution": [ diff --git a/exercises/practice/palindrome-products/.meta/example.php b/exercises/practice/palindrome-products/.meta/example.php index 0cf31d8e3..c036c83c7 100644 --- a/exercises/practice/palindrome-products/.meta/example.php +++ b/exercises/practice/palindrome-products/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); function generatePalindromeProduct(array $range): ?int diff --git a/exercises/practice/palindrome-products/PalindromeProductsTest.php b/exercises/practice/palindrome-products/PalindromeProductsTest.php index e01673f2a..0aa7f8545 100644 --- a/exercises/practice/palindrome-products/PalindromeProductsTest.php +++ b/exercises/practice/palindrome-products/PalindromeProductsTest.php @@ -1,30 +1,9 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\TestDox; class PalindromeProductsTest extends TestCase { @@ -33,6 +12,10 @@ public static function setUpBeforeClass(): void require_once 'PalindromeProducts.php'; } + /** + * uuid: 5cff78fe-cf02-459d-85c2-ce584679f887 + */ + #[TestDox('find the smallest palindrome from single digit factors')] public function testFindsTheSmallestPalindromeFromSingleDigitFactors(): void { [$value, $factors] = smallest(1, 9); @@ -42,6 +25,10 @@ public function testFindsTheSmallestPalindromeFromSingleDigitFactors(): void ]); } + /** + * uuid: 0853f82c-5fc4-44ae-be38-fadb2cced92d + */ + #[TestDox('find the largest palindrome from single digit factors')] public function testFindsTheLargestPalindromeFromSingleDigitFactors(): void { [$value, $factors] = largest(1, 9); @@ -52,6 +39,10 @@ public function testFindsTheLargestPalindromeFromSingleDigitFactors(): void ]); } + /** + * uuid: 66c3b496-bdec-4103-9129-3fcb5a9063e1 + */ + #[TestDox('find the smallest palindrome from double digit factors')] public function testFindTheSmallestPalindromeFromDoubleDigitFactors(): void { [$value, $factors] = smallest(10, 99); @@ -61,6 +52,10 @@ public function testFindTheSmallestPalindromeFromDoubleDigitFactors(): void ]); } + /** + * uuid: a10682ae-530a-4e56-b89d-69664feafe53 + */ + #[TestDox('find the largest palindrome from double digit factors')] public function testFindTheLargestPalindromeFromDoubleDigitFactors(): void { [$value, $factors] = largest(10, 99); @@ -70,6 +65,10 @@ public function testFindTheLargestPalindromeFromDoubleDigitFactors(): void ]); } + /** + * uuid: cecb5a35-46d1-4666-9719-fa2c3af7499d + */ + #[TestDox('find the smallest palindrome from triple digit factors')] public function testFindSmallestPalindromeFromTripleDigitFactors(): void { [$value, $factors] = smallest(100, 999); @@ -79,6 +78,10 @@ public function testFindSmallestPalindromeFromTripleDigitFactors(): void ]); } + /** + * uuid: edab43e1-c35f-4ea3-8c55-2f31dddd92e5 + */ + #[TestDox('find the largest palindrome from triple digit factors')] public function testFindTheLargestPalindromeFromTripleDigitFactors(): void { [$value, $factors] = largest(100, 999); @@ -88,6 +91,10 @@ public function testFindTheLargestPalindromeFromTripleDigitFactors(): void ]); } + /** + * uuid: 4f802b5a-9d74-4026-a70f-b53ff9234e4e + */ + #[TestDox('find the smallest palindrome from four digit factors')] public function testFindSmallestPalindromeFromFourDigitFactors(): void { [$value, $factors] = smallest(1000, 9999); @@ -97,6 +104,12 @@ public function testFindSmallestPalindromeFromFourDigitFactors(): void ]); } + + + /** + * uuid: 787525e0-a5f9-40f3-8cb2-23b52cf5d0be + */ + #[TestDox('find the largest palindrome from four digit factors')] public function testFindTheLargestPalindromeFromFourDigitFactors(): void { [$value, $factors] = largest(1000, 9999); @@ -106,27 +119,60 @@ public function testFindTheLargestPalindromeFromFourDigitFactors(): void ]); } + + /** + * uuid: 58fb1d63-fddb-4409-ab84-a7a8e58d9ea0 + */ + #[TestDox('empty result for smallest if no palindrome in the range')] public function testEmptyResultForSmallestIfNoPalindromeInTheRange(): void { $this->expectException(Exception::class); smallest(1002, 1003); } + + /** + * uuid: 9de9e9da-f1d9-49a5-8bfc-3d322efbdd02 + */ + #[TestDox('empty result for largest if no palindrome in the range')] public function testEmptyResultForLargestIfNoPalindromeInTheRange(): void { $this->expectException(Exception::class); largest(15, 15); } + + /** + * uuid: 12e73aac-d7ee-4877-b8aa-2aa3dcdb9f8a + */ + #[TestDox('error result for smallest if min is more than max')] public function testErrorResultForSmallestIfMinIsMoreThanMax(): void { $this->expectException(Exception::class); smallest(10000, 1); } + + /** + * uuid: eeeb5bff-3f47-4b1e-892f-05829277bd74 + */ + #[TestDox('error result for largest if min is more than max')] public function testErrorResultForLargestIfMinIsMoreThanMax(): void { $this->expectException(Exception::class); largest(2, 1); } + + /** + * uuid: 16481711-26c4-42e0-9180-e2e4e8b29c23 + */ + #[TestDox('smallest product does not use the smallest factor')] + public function testSmallestProductDoesNotUseTheSmallestFactor(): void + { + [$value, $factors] = smallest(3215, 4000); + $this->assertEquals(10988901, $value); + $this->assertEquals([ + [3297, 3333], + ], $factors); + } } From 28dbcd32e1ab052c2db1e291749b077165b71e0f Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Fri, 22 May 2026 18:23:28 +0200 Subject: [PATCH 3/3] Fix whitespace trouble --- .../PalindromeProductsTest.php | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/exercises/practice/palindrome-products/PalindromeProductsTest.php b/exercises/practice/palindrome-products/PalindromeProductsTest.php index 0aa7f8545..88f5bacde 100644 --- a/exercises/practice/palindrome-products/PalindromeProductsTest.php +++ b/exercises/practice/palindrome-products/PalindromeProductsTest.php @@ -25,7 +25,7 @@ public function testFindsTheSmallestPalindromeFromSingleDigitFactors(): void ]); } - /** + /** * uuid: 0853f82c-5fc4-44ae-be38-fadb2cced92d */ #[TestDox('find the largest palindrome from single digit factors')] @@ -39,7 +39,7 @@ public function testFindsTheLargestPalindromeFromSingleDigitFactors(): void ]); } - /** + /** * uuid: 66c3b496-bdec-4103-9129-3fcb5a9063e1 */ #[TestDox('find the smallest palindrome from double digit factors')] @@ -52,7 +52,7 @@ public function testFindTheSmallestPalindromeFromDoubleDigitFactors(): void ]); } - /** + /** * uuid: a10682ae-530a-4e56-b89d-69664feafe53 */ #[TestDox('find the largest palindrome from double digit factors')] @@ -65,7 +65,7 @@ public function testFindTheLargestPalindromeFromDoubleDigitFactors(): void ]); } - /** + /** * uuid: cecb5a35-46d1-4666-9719-fa2c3af7499d */ #[TestDox('find the smallest palindrome from triple digit factors')] @@ -104,8 +104,6 @@ public function testFindSmallestPalindromeFromFourDigitFactors(): void ]); } - - /** * uuid: 787525e0-a5f9-40f3-8cb2-23b52cf5d0be */ @@ -119,8 +117,7 @@ public function testFindTheLargestPalindromeFromFourDigitFactors(): void ]); } - - /** + /** * uuid: 58fb1d63-fddb-4409-ab84-a7a8e58d9ea0 */ #[TestDox('empty result for smallest if no palindrome in the range')] @@ -131,7 +128,7 @@ public function testEmptyResultForSmallestIfNoPalindromeInTheRange(): void } - /** + /** * uuid: 9de9e9da-f1d9-49a5-8bfc-3d322efbdd02 */ #[TestDox('empty result for largest if no palindrome in the range')] @@ -142,7 +139,7 @@ public function testEmptyResultForLargestIfNoPalindromeInTheRange(): void } - /** + /** * uuid: 12e73aac-d7ee-4877-b8aa-2aa3dcdb9f8a */ #[TestDox('error result for smallest if min is more than max')] @@ -153,7 +150,7 @@ public function testErrorResultForSmallestIfMinIsMoreThanMax(): void } - /** + /** * uuid: eeeb5bff-3f47-4b1e-892f-05829277bd74 */ #[TestDox('error result for largest if min is more than max')] @@ -163,7 +160,7 @@ public function testErrorResultForLargestIfMinIsMoreThanMax(): void largest(2, 1); } - /** + /** * uuid: 16481711-26c4-42e0-9180-e2e4e8b29c23 */ #[TestDox('smallest product does not use the smallest factor')]