diff --git a/exercises/practice/binary-search-tree/.docs/instructions.md b/exercises/practice/binary-search-tree/.docs/instructions.md index c9bbba5b..7625220e 100644 --- a/exercises/practice/binary-search-tree/.docs/instructions.md +++ b/exercises/practice/binary-search-tree/.docs/instructions.md @@ -19,29 +19,52 @@ All data in the left subtree is less than or equal to the current node's data, a For example, if we had a node containing the data 4, and we added the data 2, our tree would look like this: +![A graph with root node 4 and a single child node 2.](https://assets.exercism.org/images/exercises/binary-search-tree/tree-4-2.svg) + +```text 4 / 2 +``` If we then added 6, it would look like this: +![A graph with root node 4 and two child nodes 2 and 6.](https://assets.exercism.org/images/exercises/binary-search-tree/tree-4-2-6.svg) + +```text 4 / \ 2 6 +``` If we then added 3, it would look like this +![A graph with root node 4, two child nodes 2 and 6, and a grandchild node 3.](https://assets.exercism.org/images/exercises/binary-search-tree/tree-4-2-6-3.svg) + +```text 4 / \ 2 6 \ 3 +``` And if we then added 1, 5, and 7, it would look like this +![A graph with root node 4, two child nodes 2 and 6, and four grandchild nodes 1, 3, 5 and 7.](https://assets.exercism.org/images/exercises/binary-search-tree/tree-4-2-6-1-3-5-7.svg) + +```text 4 / \ / \ 2 6 / \ / \ 1 3 5 7 +``` + +## Credit + +The images were created by [habere-et-dispertire][habere-et-dispertire] using [PGF/TikZ][pgf-tikz] by Till Tantau. + +[habere-et-dispertire]: https://exercism.org/profiles/habere-et-dispertire +[pgf-tikz]: https://en.wikipedia.org/wiki/PGF/TikZ diff --git a/exercises/practice/bob/.meta/tests.toml b/exercises/practice/bob/.meta/tests.toml index ea47d6bb..5299e289 100644 --- a/exercises/practice/bob/.meta/tests.toml +++ b/exercises/practice/bob/.meta/tests.toml @@ -71,6 +71,7 @@ description = "alternate silence" [66953780-165b-4e7e-8ce3-4bcb80b6385a] description = "multiple line question" +include = false [5371ef75-d9ea-4103-bcfa-2da973ddec1b] description = "starting with whitespace" @@ -83,3 +84,7 @@ description = "other whitespace" [12983553-8601-46a8-92fa-fcaa3bc4a2a0] description = "non-question ending with whitespace" + +[2c7278ac-f955-4eb4-bf8f-e33eb4116a15] +description = "multiple line question" +reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a" diff --git a/exercises/practice/bob/BobResponse.tests.ps1 b/exercises/practice/bob/BobResponse.tests.ps1 index 7d77a393..f0a962e8 100644 --- a/exercises/practice/bob/BobResponse.tests.ps1 +++ b/exercises/practice/bob/BobResponse.tests.ps1 @@ -85,7 +85,7 @@ Describe "Test Get-BobResponse" { } It "multiple line question" { - Get-BobResponse -HeyBob "`nDoes this cryogenic chamber make me look fat?`nno" | Should -BeExactly "Whatever." + Get-BobResponse -HeyBob "`nDoes this cryogenic chamber make`n me look fat?" | Should -BeExactly "Sure." } It "starting with whitespace" { diff --git a/exercises/practice/crypto-square/.meta/tests.toml b/exercises/practice/crypto-square/.meta/tests.toml index 085d142e..94ef0819 100644 --- a/exercises/practice/crypto-square/.meta/tests.toml +++ b/exercises/practice/crypto-square/.meta/tests.toml @@ -32,3 +32,8 @@ description = "8 character plaintext results in 3 chunks, the last one with a tr [fbcb0c6d-4c39-4a31-83f6-c473baa6af80] description = "54 character plaintext results in 7 chunks, the last two with trailing spaces" +include = false + +[33fd914e-fa44-445b-8f38-ff8fbc9fe6e6] +description = "54 character plaintext results in 8 chunks, the last two with trailing spaces" +reimplements = "fbcb0c6d-4c39-4a31-83f6-c473baa6af80" diff --git a/exercises/practice/crypto-square/CryptoSquare.tests.ps1 b/exercises/practice/crypto-square/CryptoSquare.tests.ps1 index 68ad6927..7dde9e6b 100644 --- a/exercises/practice/crypto-square/CryptoSquare.tests.ps1 +++ b/exercises/practice/crypto-square/CryptoSquare.tests.ps1 @@ -52,7 +52,7 @@ Describe "CryptoSquare test cases" { $got | Should -BeExactly $want } - It "54 character plaintext results in 7 chunks, the last two with trailing spaces" { + It "54 character plaintext results in 8 chunks, the last two with trailing spaces" { $got = Invoke-CryptoSquare -PlainText "If man was meant to stay on the ground, god would have given us roots." $want = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau " diff --git a/exercises/practice/dot-dsl/.docs/instructions.md b/exercises/practice/dot-dsl/.docs/instructions.md index b3a63996..5e65ebef 100644 --- a/exercises/practice/dot-dsl/.docs/instructions.md +++ b/exercises/practice/dot-dsl/.docs/instructions.md @@ -22,7 +22,7 @@ Write a Domain Specific Language similar to the Graphviz dot language. Our DSL is similar to the Graphviz dot language in that our DSL will be used to create graph data structures. However, unlike the DOT Language, our DSL will be an internal DSL for use only in our language. -More information about the difference between internal and external DSLs can be found [here][fowler-dsl]. +[Learn more about the difference between internal and external DSLs][fowler-dsl]. [dsl]: https://en.wikipedia.org/wiki/Domain-specific_language [dot-language]: https://en.wikipedia.org/wiki/DOT_(graph_description_language) diff --git a/exercises/practice/eliuds-eggs/.docs/introduction.md b/exercises/practice/eliuds-eggs/.docs/introduction.md index 81989748..2b2e5c43 100644 --- a/exercises/practice/eliuds-eggs/.docs/introduction.md +++ b/exercises/practice/eliuds-eggs/.docs/introduction.md @@ -58,7 +58,7 @@ The position information encoding is calculated as follows: ### Decimal number on the display -16 +8 ### Actual eggs in the coop diff --git a/exercises/practice/flatten-array/.meta/tests.toml b/exercises/practice/flatten-array/.meta/tests.toml index 6300219d..44acf175 100644 --- a/exercises/practice/flatten-array/.meta/tests.toml +++ b/exercises/practice/flatten-array/.meta/tests.toml @@ -32,12 +32,32 @@ description = "null values are omitted from the final result" [c6cf26de-8ccd-4410-84bd-b9efd88fd2bc] description = "consecutive null values at the front of the list are omitted from the final result" +include = false + +[bc72da10-5f55-4ada-baf3-50e4da02ec8e] +description = "consecutive null values at the front of the array are omitted from the final result" +reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc" [382c5242-587e-4577-b8ce-a5fb51e385a1] description = "consecutive null values in the middle of the list are omitted from the final result" +include = false + +[6991836d-0d9b-4703-80a0-3f1f23eb5981] +description = "consecutive null values in the middle of the array are omitted from the final result" +reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1" [ef1d4790-1b1e-4939-a179-51ace0829dbd] description = "6 level nest list with null values" +include = false + +[dc90a09c-5376-449c-a7b3-c2d20d540069] +description = "6 level nested array with null values" +reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd" [85721643-705a-4150-93ab-7ae398e2942d] description = "all values in nested list are null" +include = false + +[51f5d9af-8f7f-4fb5-a156-69e8282cb275] +description = "all values in nested array are null" +reimplements = "85721643-705a-4150-93ab-7ae398e2942d" diff --git a/exercises/practice/flatten-array/FlattenArray.tests.ps1 b/exercises/practice/flatten-array/FlattenArray.tests.ps1 index 5d291482..a73e5221 100644 --- a/exercises/practice/flatten-array/FlattenArray.tests.ps1 +++ b/exercises/practice/flatten-array/FlattenArray.tests.ps1 @@ -52,28 +52,28 @@ Describe "flatten array test cases" { $got | Should -BeExactly $want } - It "consecutive null values at the front of the list are omitted from the final result" { + It "consecutive null values at the front of the array are omitted from the final result" { $got = Invoke-FlattenArray -Array @($null, $null, 5) $want = @(5) $got | Should -BeExactly $want } - It "consecutive null values in the middle of the list are omitted from the final result" { + It "consecutive null values in the middle of the array are omitted from the final result" { $got = Invoke-FlattenArray -Array @(1, $null, $null, 4) $want = @(1, 4) $got | Should -BeExactly $want } - It "6 level nest list with null values" { + It "6 level nest array with null values" { $got = Invoke-FlattenArray -Array @(0, 2, @(@(2, 3), 8, @(@(100)), $null, @(@($null))), -2) $want = @(0, 2, 2, 3, 8, 100, -2) $got | Should -BeExactly $want } - It "all values in nested list are null" { + It "all values in nested array are null" { $got = Invoke-FlattenArray -Array @($null, @(@(@($null))), $null, $null, @(@($null, $null), $null), $null) $want = @() diff --git a/exercises/practice/forth/.meta/tests.toml b/exercises/practice/forth/.meta/tests.toml index c9c1d637..d1e146a1 100644 --- a/exercises/practice/forth/.meta/tests.toml +++ b/exercises/practice/forth/.meta/tests.toml @@ -24,6 +24,9 @@ description = "addition -> errors if there is nothing on the stack" [06efb9a4-817a-435e-b509-06166993c1b8] description = "addition -> errors if there is only one value on the stack" +[1e07a098-c5fa-4c66-97b2-3c81205dbc2f] +description = "addition -> more than two values on the stack" + [09687c99-7bbc-44af-8526-e402f997ccbf] description = "subtraction -> can subtract two numbers" @@ -33,6 +36,9 @@ description = "subtraction -> errors if there is nothing on the stack" [b3cee1b2-9159-418a-b00d-a1bb3765c23b] description = "subtraction -> errors if there is only one value on the stack" +[2c8cc5ed-da97-4cb1-8b98-fa7b526644f4] +description = "subtraction -> more than two values on the stack" + [5df0ceb5-922e-401f-974d-8287427dbf21] description = "multiplication -> can multiply two numbers" @@ -42,6 +48,9 @@ description = "multiplication -> errors if there is nothing on the stack" [8ba4b432-9f94-41e0-8fae-3b3712bd51b3] description = "multiplication -> errors if there is only one value on the stack" +[5cd085b5-deb1-43cc-9c17-6b1c38bc9970] +description = "multiplication -> more than two values on the stack" + [e74c2204-b057-4cff-9aa9-31c7c97a93f5] description = "division -> can divide two numbers" @@ -57,12 +66,21 @@ description = "division -> errors if there is nothing on the stack" [d5547f43-c2ff-4d5c-9cb0-2a4f6684c20d] description = "division -> errors if there is only one value on the stack" +[f224f3e0-b6b6-4864-81de-9769ecefa03f] +description = "division -> more than two values on the stack" + [ee28d729-6692-4a30-b9be-0d830c52a68c] description = "combined arithmetic -> addition and subtraction" [40b197da-fa4b-4aca-a50b-f000d19422c1] description = "combined arithmetic -> multiplication and division" +[f749b540-53aa-458e-87ec-a70797eddbcb] +description = "combined arithmetic -> multiplication and addition" + +[c8e5a4c2-f9bf-4805-9a35-3c3314e4989a] +description = "combined arithmetic -> addition and multiplication" + [c5758235-6eef-4bf6-ab62-c878e50b9957] description = "dup -> copies a value on the stack" diff --git a/exercises/practice/forth/Forth.tests.ps1 b/exercises/practice/forth/Forth.tests.ps1 index aa3f813a..efabf1c4 100644 --- a/exercises/practice/forth/Forth.tests.ps1 +++ b/exercises/practice/forth/Forth.tests.ps1 @@ -32,6 +32,11 @@ Describe "Forth test cases" { It "addition -> errors if there is only one value on the stack" { {$forth.Evaluate(@("1 +"))} | Should -Throw "*Not enough items in stack to perform operation*" } + + It "addition -> more than two values on the stack" { + $forth.Evaluate(@("1 2 3 +")) + $forth.GetStack() | Should -Be @(1, 5) + } It "subtraction -> can subtract two numbers" { $forth.Evaluate(@("3 4 -")) @@ -45,6 +50,11 @@ Describe "Forth test cases" { It "subtraction -> errors if there is only one value on the stack" { {$forth.Evaluate(@("1 -"))} | Should -Throw "*Not enough items in stack to perform operation*" } + + It "subtraction -> more than two values on the stack" { + $forth.Evaluate(@("1 12 3 -")) + $forth.GetStack() | Should -Be @(1, 9) + } It "multiplication -> can multiply two numbers" { $forth.Evaluate(@("2 4 *")) @@ -58,6 +68,11 @@ Describe "Forth test cases" { It "multiplication -> errors if there is only one value on the stack" { {$forth.Evaluate(@("1 *"))} | Should -Throw "*Not enough items in stack to perform operation*" } + + It "multiplication -> more than two values on the stack" { + $forth.Evaluate(@("1 2 3 *")) + $forth.GetStack() | Should -Be @(1, 6) + } It "division -> can divide two numbers" { $forth.Evaluate(@("12 3 /")) @@ -76,6 +91,11 @@ Describe "Forth test cases" { It "division -> errors if there is nothing on the stack" { {$forth.Evaluate(@("/"))} | Should -Throw "*Stack is empty*" } + + It "division -> more than two values on the stack" { + $forth.Evaluate(@("1 12 3 /")) + $forth.GetStack() | Should -Be @(1, 4) + } It "division -> errors if there is only one value on the stack" { {$forth.Evaluate(@("1 /"))} | Should -Throw "*Not enough items in stack to perform operation*" @@ -90,6 +110,16 @@ Describe "Forth test cases" { $forth.Evaluate(@("2 4 * 3 /")) $forth.GetStack() | Should -Be @(2) } + + It "combined arithmetic -> multiplication and addition" { + $forth.Evaluate(@("1 3 4 * +")) + $forth.GetStack() | Should -Be @(13) + } + + It "combined arithmetic -> addition and multiplication" { + $forth.Evaluate(@("1 3 4 + *")) + $forth.GetStack() | Should -Be @(7) + } } Context "stack manipulation operations" { diff --git a/exercises/practice/largest-series-product/.meta/LargestSeriesProduct.example.ps1 b/exercises/practice/largest-series-product/.meta/LargestSeriesProduct.example.ps1 index bc28cbb6..a855abea 100644 --- a/exercises/practice/largest-series-product/.meta/LargestSeriesProduct.example.ps1 +++ b/exercises/practice/largest-series-product/.meta/LargestSeriesProduct.example.ps1 @@ -49,7 +49,7 @@ Function Validator() { Throw "digits input must only contain digits" } if ($Span -gt $Digits.Length) { - Throw "span must be smaller than string length" + Throw "span must not exceed string length" } if ($Span -lt 0) { Throw "span must not be negative" diff --git a/exercises/practice/largest-series-product/.meta/tests.toml b/exercises/practice/largest-series-product/.meta/tests.toml index 6c111adf..5a62d619 100644 --- a/exercises/practice/largest-series-product/.meta/tests.toml +++ b/exercises/practice/largest-series-product/.meta/tests.toml @@ -38,6 +38,11 @@ description = "reports zero if all spans include zero" [5d81aaf7-4f67-4125-bf33-11493cc7eab7] description = "rejects span longer than string length" +include = false + +[0ae1ce53-d9ba-41bb-827f-2fceb64f058b] +description = "rejects span longer than string length" +reimplements = "5d81aaf7-4f67-4125-bf33-11493cc7eab7" [06bc8b90-0c51-4c54-ac22-3ec3893a079e] description = "reports 1 for empty string and empty product (0 span)" @@ -47,6 +52,11 @@ description = "reports 1 for nonempty string and empty product (0 span)" [6d96c691-4374-4404-80ee-2ea8f3613dd4] description = "rejects empty string and nonzero span" +include = false + +[6cf66098-a6af-4223-aab1-26aeeefc7402] +description = "rejects empty string and nonzero span" +reimplements = "6d96c691-4374-4404-80ee-2ea8f3613dd4" [7a38f2d6-3c35-45f6-8d6f-12e6e32d4d74] description = "rejects invalid character in digits" diff --git a/exercises/practice/largest-series-product/LargestSeriesProduct.tests.ps1 b/exercises/practice/largest-series-product/LargestSeriesProduct.tests.ps1 index 10696303..e9eae4eb 100644 --- a/exercises/practice/largest-series-product/LargestSeriesProduct.tests.ps1 +++ b/exercises/practice/largest-series-product/LargestSeriesProduct.tests.ps1 @@ -43,11 +43,11 @@ Describe "Test LargestSeriesProduct Cases" { Context "Invalid Inputs" { It "rejects span longer than string length" { - { Get-LargestSeriesProduct -Digits "123" -Span 4 } | Should -Throw "*span must be smaller than string length*" + { Get-LargestSeriesProduct -Digits "123" -Span 4 } | Should -Throw "*span must not exceed string length*" } It "rejects empty string and nonzero span" { - { Get-LargestSeriesProduct -Digits "" -Span 2 } | Should -Throw "*span must be smaller than string length*" + { Get-LargestSeriesProduct -Digits "" -Span 2 } | Should -Throw "*span must not exceed string length*" } It "rejects invalid character in digits" { diff --git a/exercises/practice/luhn/.docs/instructions.md b/exercises/practice/luhn/.docs/instructions.md index 5bbf007b..7702c6bb 100644 --- a/exercises/practice/luhn/.docs/instructions.md +++ b/exercises/practice/luhn/.docs/instructions.md @@ -1,6 +1,6 @@ # Instructions -Determine whether a credit card number is valid according to the [Luhn formula][luhn]. +Determine whether a number is valid according to the [Luhn formula][luhn]. The number will be provided as a string. @@ -10,54 +10,59 @@ Strings of length 1 or less are not valid. Spaces are allowed in the input, but they should be stripped before checking. All other non-digit characters are disallowed. -### Example 1: valid credit card number +## Examples -```text -4539 3195 0343 6467 -``` +### Valid credit card number -The first step of the Luhn algorithm is to double every second digit, starting from the right. -We will be doubling +The number to be checked is `4539 3195 0343 6467`. + +The first step of the Luhn algorithm is to start at the end of the number and double every second digit, beginning with the second digit from the right and moving left. ```text 4539 3195 0343 6467 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ (double these) ``` -If doubling the number results in a number greater than 9 then subtract 9 from the product. -The results of our doubling: +If the result of doubling a digit is greater than 9, we subtract 9 from that result. +We end up with: ```text 8569 6195 0383 3437 ``` -Then sum all of the digits: +Finally, we sum all digits. +If the sum is evenly divisible by 10, the original number is valid. ```text -8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80 +8 + 5 + 6 + 9 + 6 + 1 + 9 + 5 + 0 + 3 + 8 + 3 + 3 + 4 + 3 + 7 = 80 ``` -If the sum is evenly divisible by 10, then the number is valid. -This number is valid! +80 is evenly divisible by 10, so number `4539 3195 0343 6467` is valid! + +### Invalid Canadian SIN + +The number to be checked is `066 123 478`. -### Example 2: invalid credit card number +We start at the end of the number and double every second digit, beginning with the second digit from the right and moving left. ```text -8273 1232 7352 0569 +066 123 478 + ↑ ↑ ↑ ↑ (double these) ``` -Double the second digits, starting from the right +If the result of doubling a digit is greater than 9, we subtract 9 from that result. +We end up with: ```text -7253 2262 5312 0539 +036 226 458 ``` -Sum the digits +We sum the digits: ```text -7+2+5+3+2+2+6+2+5+3+1+2+0+5+3+9 = 57 +0 + 3 + 6 + 2 + 2 + 6 + 4 + 5 + 8 = 36 ``` -57 is not evenly divisible by 10, so this number is not valid. +36 is not evenly divisible by 10, so number `066 123 478` is not valid! [luhn]: https://en.wikipedia.org/wiki/Luhn_algorithm diff --git a/exercises/practice/luhn/.docs/introduction.md b/exercises/practice/luhn/.docs/introduction.md index ec2bd709..dee48006 100644 --- a/exercises/practice/luhn/.docs/introduction.md +++ b/exercises/practice/luhn/.docs/introduction.md @@ -2,10 +2,10 @@ At the Global Verification Authority, you've just been entrusted with a critical assignment. Across the city, from online purchases to secure logins, countless operations rely on the accuracy of numerical identifiers like credit card numbers, bank account numbers, transaction codes, and tracking IDs. -The Luhn algorithm is a simple checksum formula used to ensure these numbers are valid and error-free. +The Luhn algorithm is a simple checksum formula used to help identify mistyped numbers. A batch of identifiers has just arrived on your desk. All of them must pass the Luhn test to ensure they're legitimate. -If any fail, they'll be flagged as invalid, preventing errors or fraud, such as incorrect transactions or unauthorized access. +If any fail, they'll be flagged as invalid, preventing mistakes such as incorrect transactions or failed account verifications. Can you ensure this is done right? The integrity of many services depends on you. diff --git a/exercises/practice/meetup/.docs/instructions.md b/exercises/practice/meetup/.docs/instructions.md index 000de2fd..8b1bda5e 100644 --- a/exercises/practice/meetup/.docs/instructions.md +++ b/exercises/practice/meetup/.docs/instructions.md @@ -2,7 +2,7 @@ Your task is to find the exact date of a meetup, given a month, year, weekday and week. -There are five week values to consider: `first`, `second`, `third`, `fourth`, `last`, `teenth`. +There are six week values to consider: `first`, `second`, `third`, `fourth`, `last`, `teenth`. For example, you might be asked to find the date for the meetup on the first Monday in January 2018 (January 1, 2018). diff --git a/exercises/practice/phone-number/.docs/instructions.md b/exercises/practice/phone-number/.docs/instructions.md index 62ba48e9..5d4d3739 100644 --- a/exercises/practice/phone-number/.docs/instructions.md +++ b/exercises/practice/phone-number/.docs/instructions.md @@ -1,6 +1,6 @@ # Instructions -Clean up user-entered phone numbers so that they can be sent SMS messages. +Clean up phone numbers so that they can be sent SMS messages. The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda. All NANP-countries share the same international country code: `1`. diff --git a/exercises/practice/pig-latin/.meta/tests.toml b/exercises/practice/pig-latin/.meta/tests.toml index c29168c5..d524305b 100644 --- a/exercises/practice/pig-latin/.meta/tests.toml +++ b/exercises/practice/pig-latin/.meta/tests.toml @@ -39,6 +39,9 @@ description = "first letter and ay are moved to the end of words that start with [bce94a7a-a94e-4e2b-80f4-b2bb02e40f71] description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with q without a following u" +[e59dbbe8-ccee-4619-a8e9-ce017489bfc0] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with consonant and vowel containing qu" + [c01e049a-e3e2-451c-bf8e-e2abb7e438b8] description = "some letter clusters are treated like a single consonant -> word beginning with ch" diff --git a/exercises/practice/pig-latin/PigLatin.tests.ps1 b/exercises/practice/pig-latin/PigLatin.tests.ps1 index 59ea5afa..22a63e65 100644 --- a/exercises/practice/pig-latin/PigLatin.tests.ps1 +++ b/exercises/practice/pig-latin/PigLatin.tests.ps1 @@ -25,6 +25,7 @@ Describe "PigLatin test cases" { @{Text = "koala" ; want = "oalakay" ; Desc = "k"} @{Text = "xenon" ; want = "enonxay" ; Desc = "x"} @{Text = "qat" ; want = "atqay" ; Desc = "q without a following u"} + @{Text = "liquid"; want = "iquidlay"; Desc = "consonant and vowel containing qu"} ) { param($Text, $want) $got = Invoke-PigLatin -Text $Text diff --git a/exercises/practice/protein-translation/.docs/instructions.md b/exercises/practice/protein-translation/.docs/instructions.md index 44880802..35c953b1 100644 --- a/exercises/practice/protein-translation/.docs/instructions.md +++ b/exercises/practice/protein-translation/.docs/instructions.md @@ -1,36 +1,17 @@ # Instructions -Translate RNA sequences into proteins. +Your job is to translate RNA sequences into proteins. -RNA can be broken into three-nucleotide sequences called codons, and then translated to a protein like so: +RNA strands are made up of three-nucleotide sequences called **codons**. +Each codon translates to an **amino acid**. +When joined together, those amino acids make a protein. -RNA: `"AUGUUUUCU"` => translates to - -Codons: `"AUG", "UUU", "UCU"` -=> which become a protein with the following sequence => - -Protein: `"Methionine", "Phenylalanine", "Serine"` - -There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise. -If it works for one codon, the program should work for all of them. -However, feel free to expand the list in the test suite to include them all. - -There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated. - -All subsequent codons after are ignored, like this: - -RNA: `"AUGUUUUCUUAAAUG"` => - -Codons: `"AUG", "UUU", "UCU", "UAA", "AUG"` => - -Protein: `"Methionine", "Phenylalanine", "Serine"` - -Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence. - -Below are the codons and resulting amino acids needed for the exercise. +In the real world, there are 64 codons, which in turn correspond to 20 amino acids. +However, for this exercise, you’ll only use a few of the possible 64. +They are listed below: | Codon | Amino Acid | -| :----------------- | :------------ | +| ------------------ | ------------- | | AUG | Methionine | | UUU, UUC | Phenylalanine | | UUA, UUG | Leucine | @@ -40,6 +21,18 @@ Below are the codons and resulting amino acids needed for the exercise. | UGG | Tryptophan | | UAA, UAG, UGA | STOP | +For example, the RNA string “AUGUUUUCU” has three codons: “AUG”, “UUU” and “UCU”. +These map to Methionine, Phenylalanine, and Serine. + +## “STOP” Codons + +You’ll note from the table above that there are three **“STOP” codons**. +If you encounter any of these codons, ignore the rest of the sequence — the protein is complete. + +For example, “AUGUUUUCUUAAAUG” contains a STOP codon (“UAA”). +Once we reach that point, we stop processing. +We therefore only consider the part before it (i.e. “AUGUUUUCU”), not any further codons after it (i.e. “AUG”). + Learn more about [protein translation on Wikipedia][protein-translation]. [protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology) diff --git a/exercises/practice/relative-distance/.docs/instructions.md b/exercises/practice/relative-distance/.docs/instructions.md index 91dd5762..9046aee7 100644 --- a/exercises/practice/relative-distance/.docs/instructions.md +++ b/exercises/practice/relative-distance/.docs/instructions.md @@ -1,6 +1,7 @@ # Instructions Your task is to determine the degree of separation between two individuals in a family tree. +This is similar to the pop culture idea that every Hollywood actor is [within six degrees of Kevin Bacon][six-bacons]. - You will be given an input, with all parent names and their children. - Each name is unique, a child _can_ have one or two parents. @@ -13,22 +14,21 @@ Your task is to determine the degree of separation between two individuals in a Given the following family tree: ```text - ┌──────────┐ ┌──────────┐ ┌───────────┐ - │ Helena │ │ Erdős │ │ Shusaku │ - └───┬───┬──┘ └─────┬────┘ └──────┬────┘ - ┌───┘ └───────┐ └──────┬──────┘ - ▼ ▼ ▼ -┌──────────┐ ┌────────┐ ┌──────────┐ -│ Isla │ │ Tariq │ │ Kevin │ -└────┬─────┘ └────┬───┘ └──────────┘ - ▼ ▼ -┌─────────┐ ┌────────┐ + ┌──────────┐ ┌──────────┐ ┌───────────┐ + │ Helena │ │ Erdős ├─────┤ Shusaku │ + └───┬───┬──┘ └─────┬────┘ └────┬──────┘ + ┌───┘ └───────┐ └───────┬───────┘ +┌─────┴────┐ ┌────┴───┐ ┌─────┴────┐ +│ Isla ├─────┤ Tariq │ │ Kevin │ +└────┬─────┘ └────┬───┘ └──────────┘ + │ │ +┌────┴────┐ ┌────┴───┐ │ Uma │ │ Morphy │ └─────────┘ └────────┘ ``` -The degree of separation between Tariq and Uma is 3 (Tariq → Helena → Isla → Uma). -There's no known relationship between Isla and [Kevin][six-bacons], as there is no connection in the given data. +The degree of separation between Tariq and Uma is 2 (Tariq → Isla → Uma). +There's no known relationship between Isla and Kevin, as there is no connection in the given data. The degree of separation between Uma and Isla is 1. ~~~~exercism/note diff --git a/exercises/practice/relative-distance/.docs/introduction.md b/exercises/practice/relative-distance/.docs/introduction.md index cb9fee6c..34073b40 100644 --- a/exercises/practice/relative-distance/.docs/introduction.md +++ b/exercises/practice/relative-distance/.docs/introduction.md @@ -9,4 +9,4 @@ Your algorithm will determine the **degree of separation** between two individua Will your app help crown a perfect match? -[islendiga-app]: http://www.islendingaapp.is/information-in-english/ +[islendiga-app]: https://web.archive.org/web/20250816223614/http://www.islendingaapp.is/information-in-english/ diff --git a/exercises/practice/say/.docs/instructions.md b/exercises/practice/say/.docs/instructions.md index ad3d3477..3251c519 100644 --- a/exercises/practice/say/.docs/instructions.md +++ b/exercises/practice/say/.docs/instructions.md @@ -1,48 +1,12 @@ # Instructions -Given a number from 0 to 999,999,999,999, spell out that number in English. +Given a number, your task is to express it in English words exactly as your friend should say it out loud. +Yaʻqūb expects to use numbers from 0 up to 999,999,999,999. -## Step 1 +Examples: -Handle the basic case of 0 through 99. - -If the input to the program is `22`, then the output should be `'twenty-two'`. - -Your program should complain loudly if given a number outside the blessed range. - -Some good test cases for this program are: - -- 0 -- 14 -- 50 -- 98 -- -1 -- 100 - -### Extension - -If you're on a Mac, shell out to Mac OS X's `say` program to talk out loud. -If you're on Linux or Windows, eSpeakNG may be available with the command `espeak`. - -## Step 2 - -Implement breaking a number up into chunks of thousands. - -So `1234567890` should yield a list like 1, 234, 567, and 890, while the far simpler `1000` should yield just 1 and 0. - -## Step 3 - -Now handle inserting the appropriate scale word between those chunks. - -So `1234567890` should yield `'1 billion 234 million 567 thousand 890'` - -The program must also report any values that are out of range. -It's fine to stop at "trillion". - -## Step 4 - -Put it all together to get nothing but plain English. - -`12345` should give `twelve thousand three hundred forty-five`. - -The program must also report any values that are out of range. +- 0 → zero +- 1 → one +- 12 → twelve +- 123 → one hundred twenty-three +- 1,234 → one thousand two hundred thirty-four diff --git a/exercises/practice/say/.docs/introduction.md b/exercises/practice/say/.docs/introduction.md new file mode 100644 index 00000000..abd22851 --- /dev/null +++ b/exercises/practice/say/.docs/introduction.md @@ -0,0 +1,6 @@ +# Introduction + +Your friend Yaʻqūb works the counter at the busiest deli in town, slicing, weighing, and wrapping orders for a never-ending line of hungry customers. +To keep things moving, each customer takes a numbered ticket when they arrive. + +When it’s time to call the next person, Yaʻqūb reads their number out loud, always in full English words to make sure everyone hears it clearly. diff --git a/exercises/practice/simple-cipher/.docs/instructions.md b/exercises/practice/simple-cipher/.docs/instructions.md index 33785744..afd0b57d 100644 --- a/exercises/practice/simple-cipher/.docs/instructions.md +++ b/exercises/practice/simple-cipher/.docs/instructions.md @@ -1,66 +1,40 @@ # Instructions -Implement a simple shift cipher like Caesar and a more secure substitution cipher. +Create an implementation of the [Vigenère cipher][wiki]. +The Vigenère cipher is a simple substitution cipher. -## Step 1 +## Cipher terminology -"If he had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out. -If anyone wishes to decipher these, and get at their meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the others." -—Suetonius, Life of Julius Caesar +A cipher is an algorithm used to encrypt, or encode, a string. +The unencrypted string is called the _plaintext_ and the encrypted string is called the _ciphertext_. +Converting plaintext to ciphertext is called _encoding_ while the reverse is called _decoding_. -Ciphers are very straight-forward algorithms that allow us to render text less readable while still allowing easy deciphering. -They are vulnerable to many forms of cryptanalysis, but Caesar was lucky that his enemies were not cryptanalysts. +In a _substitution cipher_, each plaintext letter is replaced with a ciphertext letter which is computed with the help of a _key_. +(Note, it is possible for replacement letter to be the same as the original letter.) -The Caesar cipher was used for some messages from Julius Caesar that were sent afield. -Now Caesar knew that the cipher wasn't very good, but he had one ally in that respect: almost nobody could read well. -So even being a couple letters off was sufficient so that people couldn't recognize the few words that they did know. +## Encoding details -Your task is to create a simple shift cipher like the Caesar cipher. -This image is a great example of the Caesar cipher: +In this cipher, the key is a series of lowercase letters, such as `"abcd"`. +Each letter of the plaintext is _shifted_ or _rotated_ by a distance based on a corresponding letter in the key. +An `"a"` in the key means a shift of 0 (that is, no shift). +A `"b"` in the key means a shift of 1. +A `"c"` in the key means a shift of 2, and so on. -![Caesar cipher][img-caesar-cipher] +The first letter of the plaintext uses the first letter of the key, the second letter of the plaintext uses the second letter of the key and so on. +If you run out of letters in the key before you run out of letters in the plaintext, start over from the start of the key again. -For example: +If the key only contains one letter, such as `"dddddd"`, then all letters of the plaintext are shifted by the same amount (three in this example), which would make this the same as a rotational cipher or shift cipher (sometimes called a Caesar cipher). +For example, the plaintext `"iamapandabear"` would become `"ldpdsdqgdehdu"`. -Giving "iamapandabear" as input to the encode function returns the cipher "ldpdsdqgdehdu". -Obscure enough to keep our message secret in transit. +If the key only contains the letter `"a"` (one or more times), the shift distance is zero and the ciphertext is the same as the plaintext. -When "ldpdsdqgdehdu" is put into the decode function it would return the original "iamapandabear" letting your friend read your original message. +Usually the key is more complicated than that, though! +If the key is `"abcd"` then letters of the plaintext would be shifted by a distance of 0, 1, 2, and 3. +If the plaintext is `"hello"`, we need 5 shifts so the key would wrap around, giving shift distances of 0, 1, 2, 3, and 0. +Applying those shifts to the letters of `"hello"` we get `"hfnoo"`. -## Step 2 +## Random keys -Shift ciphers quickly cease to be useful when the opposition commander figures them out. -So instead, let's try using a substitution cipher. -Try amending the code to allow us to specify a key and use that for the shift distance. +If no key is provided, generate a key which consists of at least 100 random lowercase letters from the Latin alphabet. -Here's an example: - -Given the key "aaaaaaaaaaaaaaaaaa", encoding the string "iamapandabear" -would return the original "iamapandabear". - -Given the key "ddddddddddddddddd", encoding our string "iamapandabear" -would return the obscured "ldpdsdqgdehdu" - -In the example above, we've set a = 0 for the key value. -So when the plaintext is added to the key, we end up with the same message coming out. -So "aaaa" is not an ideal key. -But if we set the key to "dddd", we would get the same thing as the Caesar cipher. - -## Step 3 - -The weakest link in any cipher is the human being. -Let's make your substitution cipher a little more fault tolerant by providing a source of randomness and ensuring that the key contains only lowercase letters. - -If someone doesn't submit a key at all, generate a truly random key of at least 100 lowercase characters in length. - -## Extensions - -Shift ciphers work by making the text slightly odd, but are vulnerable to frequency analysis. -Substitution ciphers help that, but are still very vulnerable when the key is short or if spaces are preserved. -Later on you'll see one solution to this problem in the exercise "crypto-square". - -If you want to go farther in this field, the questions begin to be about how we can exchange keys in a secure way. -Take a look at [Diffie-Hellman on Wikipedia][dh] for one of the first implementations of this scheme. - -[img-caesar-cipher]: https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Caesar_cipher_left_shift_of_3.svg/320px-Caesar_cipher_left_shift_of_3.svg.png -[dh]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange +[wiki]: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher diff --git a/exercises/practice/simple-cipher/.meta/config.json b/exercises/practice/simple-cipher/.meta/config.json index dd04f5e8..3ef45db1 100644 --- a/exercises/practice/simple-cipher/.meta/config.json +++ b/exercises/practice/simple-cipher/.meta/config.json @@ -13,7 +13,7 @@ ".meta/SimpleCipher.example.ps1" ] }, - "blurb": "Implement a simple shift cipher like Caesar and a more secure substitution cipher.", + "blurb": "Implement the Vigenère cipher, a simple substitution cipher.", "source": "Substitution Cipher at Wikipedia", "source_url": "https://en.wikipedia.org/wiki/Substitution_cipher" } diff --git a/exercises/practice/triangle/.docs/instructions.md b/exercises/practice/triangle/.docs/instructions.md index ac390087..e9b053dc 100644 --- a/exercises/practice/triangle/.docs/instructions.md +++ b/exercises/practice/triangle/.docs/instructions.md @@ -13,6 +13,12 @@ A _scalene_ triangle has all sides of different lengths. For a shape to be a triangle at all, all sides have to be of length > 0, and the sum of the lengths of any two sides must be greater than or equal to the length of the third side. +~~~~exercism/note +_Degenerate triangles_ are triangles where the sum of the length of two sides is **equal** to the length of the third side, e.g. `1, 1, 2`. +We opted to not include tests for degenerate triangles in this exercise. +You may handle those situations if you wish to do so, or safely ignore them. +~~~~ + In equations: Let `a`, `b`, and `c` be sides of the triangle. diff --git a/exercises/practice/two-bucket/.meta/tests.toml b/exercises/practice/two-bucket/.meta/tests.toml index d6ff02f5..a3fe533e 100644 --- a/exercises/practice/two-bucket/.meta/tests.toml +++ b/exercises/practice/two-bucket/.meta/tests.toml @@ -27,6 +27,12 @@ description = "Measure one step using bucket one of size 1 and bucket two of siz [eb329c63-5540-4735-b30b-97f7f4df0f84] description = "Measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two" +[58d70152-bf2b-46bb-ad54-be58ebe94c03] +description = "Measure using bucket one much bigger than bucket two" + +[9dbe6499-caa5-4a58-b5ce-c988d71b8981] +description = "Measure using bucket one much smaller than bucket two" + [449be72d-b10a-4f4b-a959-ca741e333b72] description = "Not possible to reach the goal" diff --git a/exercises/practice/two-bucket/TwoBucket.tests.ps1 b/exercises/practice/two-bucket/TwoBucket.tests.ps1 index 70b8ac04..e9ec5ceb 100644 --- a/exercises/practice/two-bucket/TwoBucket.tests.ps1 +++ b/exercises/practice/two-bucket/TwoBucket.tests.ps1 @@ -80,4 +80,22 @@ Describe "TwoBucket test cases" { $buckets = [TwoBucket]::new(5, 5, "one") { $buckets.Measure(4) } | Should -Throw "*Two buckets can't be of the same size*" } + + It "Measure using bucket one much bigger than bucket two" { + $buckets = [TwoBucket]::new(5, 1, "one") + $got = $buckets.Measure(2) + + $got.Moves | Should -BeExactly 6 + $got.GoalBucket | Should -BeExactly "one" + $got.OtherBucket | Should -BeExactly 1 + } + + It "Measure using bucket one much smaller than bucket two" { + $buckets = [TwoBucket]::new(3, 15, "one") + $got = $buckets.Measure(9) + + $got.Moves | Should -BeExactly 6 + $got.GoalBucket | Should -BeExactly "two" + $got.OtherBucket | Should -BeExactly 0 + } } diff --git a/exercises/practice/variable-length-quantity/.meta/tests.toml b/exercises/practice/variable-length-quantity/.meta/tests.toml index c9af549f..53be789a 100644 --- a/exercises/practice/variable-length-quantity/.meta/tests.toml +++ b/exercises/practice/variable-length-quantity/.meta/tests.toml @@ -15,6 +15,9 @@ description = "Encode a series of integers, producing a series of bytes. -> zero [be44d299-a151-4604-a10e-d4b867f41540] description = "Encode a series of integers, producing a series of bytes. -> arbitrary single byte" +[890bc344-cb80-45af-b316-6806a6971e81] +description = "Encode a series of integers, producing a series of bytes. -> asymmetric single byte" + [ea399615-d274-4af6-bbef-a1c23c9e1346] description = "Encode a series of integers, producing a series of bytes. -> largest single byte" @@ -24,6 +27,9 @@ description = "Encode a series of integers, producing a series of bytes. -> smal [63955a49-2690-4e22-a556-0040648d6b2d] description = "Encode a series of integers, producing a series of bytes. -> arbitrary double byte" +[4977d113-251b-4d10-a3ad-2f5a7756bb58] +description = "Encode a series of integers, producing a series of bytes. -> asymmetric double byte" + [29da7031-0067-43d3-83a7-4f14b29ed97a] description = "Encode a series of integers, producing a series of bytes. -> largest double byte" @@ -33,6 +39,9 @@ description = "Encode a series of integers, producing a series of bytes. -> smal [5df0bc2d-2a57-4300-a653-a75ee4bd0bee] description = "Encode a series of integers, producing a series of bytes. -> arbitrary triple byte" +[6731045f-1e00-4192-b5ae-98b22e17e9f7] +description = "Encode a series of integers, producing a series of bytes. -> asymmetric triple byte" + [f51d8539-312d-4db1-945c-250222c6aa22] description = "Encode a series of integers, producing a series of bytes. -> largest triple byte" @@ -42,6 +51,9 @@ description = "Encode a series of integers, producing a series of bytes. -> smal [11ed3469-a933-46f1-996f-2231e05d7bb6] description = "Encode a series of integers, producing a series of bytes. -> arbitrary quadruple byte" +[b45ef770-cbba-48c2-bd3c-c6362679516e] +description = "Encode a series of integers, producing a series of bytes. -> asymmetric quadruple byte" + [d5f3f3c3-e0f1-4e7f-aad0-18a44f223d1c] description = "Encode a series of integers, producing a series of bytes. -> largest quadruple byte" @@ -51,6 +63,9 @@ description = "Encode a series of integers, producing a series of bytes. -> smal [5f34ff12-2952-4669-95fe-2d11b693d331] description = "Encode a series of integers, producing a series of bytes. -> arbitrary quintuple byte" +[9be46731-7cd5-415c-b960-48061cbc1154] +description = "Encode a series of integers, producing a series of bytes. -> asymmetric quintuple byte" + [7489694b-88c3-4078-9864-6fe802411009] description = "Encode a series of integers, producing a series of bytes. -> maximum 32-bit integer input" diff --git a/exercises/practice/variable-length-quantity/VariableLengthQuantity.tests.ps1 b/exercises/practice/variable-length-quantity/VariableLengthQuantity.tests.ps1 index 035d4134..1536f232 100644 --- a/exercises/practice/variable-length-quantity/VariableLengthQuantity.tests.ps1 +++ b/exercises/practice/variable-length-quantity/VariableLengthQuantity.tests.ps1 @@ -145,6 +145,41 @@ Describe "VariableLengthQuantity test cases" { $got | Should -BeExactly $want } + + It "asymmetric single byte" { + $got = Invoke-EncodeVLQ -Bytes @(83) + $want = @(83) + + $got | Should -BeExactly $want + } + + It "asymmetric double byte" { + $got = Invoke-EncodeVLQ -Bytes @(173) + $want = @(129, 45) + + $got | Should -BeExactly $want + } + + It "asymmetric triple byte" { + $got = Invoke-EncodeVLQ -Bytes @(120220) + $want = @(135, 171, 28) + + $got | Should -BeExactly $want + } + + It "asymmetric quadruple byte" { + $got = Invoke-EncodeVLQ -Bytes @(3503876) + $want = @(129, 213, 238, 4) + + $got | Should -BeExactly $want + } + + It "asymmetric quintuple byte" { + $got = Invoke-EncodeVLQ -Bytes @(2254790917) + $want = @(136, 179, 149, 194, 5) + + $got | Should -BeExactly $want + } } Context "Decode a series of bytes, producing a series of integers." { diff --git a/exercises/practice/wordy/.meta/tests.toml b/exercises/practice/wordy/.meta/tests.toml index f812dfa9..a0a83ed0 100644 --- a/exercises/practice/wordy/.meta/tests.toml +++ b/exercises/practice/wordy/.meta/tests.toml @@ -12,9 +12,21 @@ [88bf4b28-0de3-4883-93c7-db1b14aa806e] description = "just a number" +[18983214-1dfc-4ebd-ac77-c110dde699ce] +description = "just a zero" + +[607c08ee-2241-4288-916d-dae5455c87e6] +description = "just a negative number" + [bb8c655c-cf42-4dfc-90e0-152fcfd8d4e0] description = "addition" +[bb9f2082-171c-46ad-ad4e-c3f72087c1b5] +description = "addition with a left hand zero" + +[6fa05f17-405a-4742-80ae-5d1a8edb0d5d] +description = "addition with a right hand zero" + [79e49e06-c5ae-40aa-a352-7a3a01f70015] description = "more addition" diff --git a/exercises/practice/wordy/Wordy.tests.ps1 b/exercises/practice/wordy/Wordy.tests.ps1 index 7d9c13dc..8e3ec0c1 100644 --- a/exercises/practice/wordy/Wordy.tests.ps1 +++ b/exercises/practice/wordy/Wordy.tests.ps1 @@ -10,6 +10,20 @@ Describe "Wordy test cases" { $got | Should -BeExactly $want } + + It "just a zero" { + $got = Get-Answer -Question "What is 0?" + $want = 0 + + $got | Should -BeExactly $want + } + + It "just a negative number" { + $got = Get-Answer -Question "What is -123?" + $want = -123 + + $got | Should -BeExactly $want + } It "addition" { $got = Get-Answer -Question "What is 1 plus 1?" @@ -31,6 +45,20 @@ Describe "Wordy test cases" { $got | Should -BeExactly $want } + + It "addition with a left hand zero" { + $got = Get-Answer -Question "What is 0 plus 2?" + $want = 2 + + $got | Should -BeExactly $want + } + + It "addition with a right hand zero" { + $got = Get-Answer -Question "What is 3 plus 0?" + $want = 3 + + $got | Should -BeExactly $want + } It "large addition" { $got = Get-Answer -Question "What is 123 plus 45678?"