diff --git a/exercises/practice/alphametics/.docs/instructions.md b/exercises/practice/alphametics/.docs/instructions.md index 649576ec..ef2cbb4a 100644 --- a/exercises/practice/alphametics/.docs/instructions.md +++ b/exercises/practice/alphametics/.docs/instructions.md @@ -1,6 +1,6 @@ # Instructions -Write a function to solve alphametics puzzles. +Given an alphametics puzzle, find the correct solution. [Alphametics][alphametics] is a puzzle where letters in words are replaced with numbers. @@ -26,6 +26,4 @@ This is correct because every letter is replaced by a different number and the w Each letter must represent a different digit, and the leading digit of a multi-digit number must not be zero. -Write a function to solve alphametics puzzles. - [alphametics]: https://en.wikipedia.org/wiki/Alphametics diff --git a/exercises/practice/alphametics/.meta/config.json b/exercises/practice/alphametics/.meta/config.json index 773a5ffd..99ba16f5 100644 --- a/exercises/practice/alphametics/.meta/config.json +++ b/exercises/practice/alphametics/.meta/config.json @@ -13,5 +13,5 @@ ".meta/example.php" ] }, - "blurb": "Write a function to solve alphametics puzzles." + "blurb": "Given an alphametics puzzle, find the correct solution." } diff --git a/exercises/practice/alphametics/.meta/example.php b/exercises/practice/alphametics/.meta/example.php index 1e3da79c..a4d34efe 100644 --- a/exercises/practice/alphametics/.meta/example.php +++ b/exercises/practice/alphametics/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); class Alphametics diff --git a/exercises/practice/alphametics/.meta/tests.toml b/exercises/practice/alphametics/.meta/tests.toml new file mode 100644 index 00000000..f599b3da --- /dev/null +++ b/exercises/practice/alphametics/.meta/tests.toml @@ -0,0 +1,40 @@ +# 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. + +[e0c08b07-9028-4d5f-91e1-d178fead8e1a] +description = "puzzle with three letters" + +[a504ee41-cb92-4ec2-9f11-c37e95ab3f25] +description = "solution must have unique value for each letter" + +[4e3b81d2-be7b-4c5c-9a80-cd72bc6d465a] +description = "leading zero solution is invalid" + +[8a3e3168-d1ee-4df7-94c7-b9c54845ac3a] +description = "puzzle with two digits final carry" + +[a9630645-15bd-48b6-a61e-d85c4021cc09] +description = "puzzle with four letters" + +[3d905a86-5a52-4e4e-bf80-8951535791bd] +description = "puzzle with six letters" + +[4febca56-e7b7-4789-97b9-530d09ba95f0] +description = "puzzle with seven letters" + +[12125a75-7284-4f9a-a5fa-191471e0d44f] +description = "puzzle with eight letters" + +[fb05955f-38dc-477a-a0b6-5ef78969fffa] +description = "puzzle with ten letters" + +[9a101e81-9216-472b-b458-b513a7adacf7] +description = "puzzle with ten letters and 199 addends" diff --git a/exercises/practice/alphametics/AlphameticsTest.php b/exercises/practice/alphametics/AlphameticsTest.php index 39ffbb74..a0e4f13c 100644 --- a/exercises/practice/alphametics/AlphameticsTest.php +++ b/exercises/practice/alphametics/AlphameticsTest.php @@ -1,91 +1,107 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); class AlphameticsTest extends PHPUnit\Framework\TestCase { - private Alphametics $alphametics; - public static function setUpBeforeClass(): void { require_once 'Alphametics.php'; } - public function setUp(): void - { - $this->alphametics = new Alphametics(); - } - + /** + * uuid e0c08b07-9028-4d5f-91e1-d178fead8e1a + * @testdox puzzle with three letters + */ public function testSolveThreeLetterPuzzle(): void { - $this->assertEquals(['I' => 1, 'B' => 9, 'L' => 0], $this->alphametics->solve('I + BB == ILL')); + $alphametics = new Alphametics(); + $this->assertEquals(['I' => 1, 'B' => 9, 'L' => 0], $alphametics->solve('I + BB == ILL')); } + /** + * uuid a504ee41-cb92-4ec2-9f11-c37e95ab3f25 + * @testdox solution must have unique value for each letter + */ public function testSolutionsMustHaveUniqueValuesForLetters(): void { - $this->assertEquals(null, $this->alphametics->solve('A == B')); + $alphametics = new Alphametics(); + $this->assertEquals(null, $alphametics->solve('A == B')); } + /** + * uuid 4e3b81d2-be7b-4c5c-9a80-cd72bc6d465a + * @testdox leading zero solution is invalid + */ public function testLeadingZerosAreInvalid(): void { - $this->assertEquals(null, $this->alphametics->solve('ACA + DD == BD')); + $alphametics = new Alphametics(); + $this->assertEquals(null, $alphametics->solve('ACA + DD == BD')); } + /** + * uuid 8a3e3168-d1ee-4df7-94c7-b9c54845ac3a + * @testdox puzzle with two digits final carry + */ public function testPuzzleWithTwoDigitsFinalCarry(): void { - $result = $this->alphametics->solve('A + A + A + A + A + A + A + A + A + A + A + B == BCC'); + $alphametics = new Alphametics(); + $result = $alphametics->solve('A + A + A + A + A + A + A + A + A + A + A + B == BCC'); $this->assertEquals(['A' => 9, 'B' => 1, 'C' => 0], $result); } + /** + * uuid a9630645-15bd-48b6-a61e-d85c4021cc09 + * @testdox puzzle with four letters + */ public function testPuzzleWithFourLetters(): void { - $result = $this->alphametics->solve('AS + A == MOM'); + $alphametics = new Alphametics(); + $result = $alphametics->solve('AS + A == MOM'); $this->assertEquals(['A' => 9, 'S' => 2, 'M' => 1, 'O' => 0], $result); } + /** + * uuid 3d905a86-5a52-4e4e-bf80-8951535791bd + * @testdox puzzle with six letters + */ public function testPuzzleWithSixLetters(): void { - $result = $this->alphametics->solve('NO + NO + TOO == LATE'); + $alphametics = new Alphametics(); + $result = $alphametics->solve('NO + NO + TOO == LATE'); $this->assertEquals(['N' => 7, 'O' => 4, 'T' => 9, 'L' => 1, 'A' => 0, 'E' => 2], $result); } + /** + * uuid 4febca56-e7b7-4789-97b9-530d09ba95f0 + * @testdox puzzle with seven letters + */ public function testPuzzleWithSevenLetter(): void { - $result = $this->alphametics->solve('HE + SEES + THE == LIGHT'); + $alphametics = new Alphametics(); + $result = $alphametics->solve('HE + SEES + THE == LIGHT'); $this->assertEquals(['E' => 4, 'G' => 2, 'H' => 5, 'I' => 0, 'L' => 1, 'S' => 9, 'T' => 7], $result); } + /** + * uuid 12125a75-7284-4f9a-a5fa-191471e0d44f + * @testdox puzzle with eight letters + */ public function testPuzzleWithEightLetters(): void { - $result = $this->alphametics->solve('SEND + MORE == MONEY'); + $alphametics = new Alphametics(); + $result = $alphametics->solve('SEND + MORE == MONEY'); $this->assertEquals(['S' => 9, 'E' => 5, 'N' => 6, 'D' => 7, 'M' => 1, 'O' => 0, 'R' => 8, 'Y' => 2], $result); } + /** + * uuid fb05955f-38dc-477a-a0b6-5ef78969fffa + * @testdox puzzle with ten letters + */ public function testPuzzleWithTenLetters(): void { - $result = $this->alphametics->solve('AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE'); + $alphametics = new Alphametics(); + $result = $alphametics->solve('AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE'); $this->assertEquals([ 'A' => 5, 'D' => 3, @@ -100,8 +116,13 @@ public function testPuzzleWithTenLetters(): void ], $result); } + /** + * uuid 9a101e81-9216-472b-b458-b513a7adacf7 + * @testdox puzzle with ten letters and 199 addends + */ public function testPuzzleWithTenLettersAnd199Addends(): void { + $alphametics = new Alphametics(); $puzzle = 'THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS' . ' + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST' . ' + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE' . @@ -117,7 +138,7 @@ public function testPuzzleWithTenLettersAnd199Addends(): void ' + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE' . ' + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A' . ' + ROOFS + FOR + THEIR + SAFE == FORTRESSES'; - $result = $this->alphametics->solve($puzzle); + $result = $alphametics->solve($puzzle); $this->assertEquals([ 'A' => 1, 'E' => 0,