From 9fca33e6a3ed42a5b1da9cb1ada7f847ec2664e4 Mon Sep 17 00:00:00 2001 From: Eduard Nicodei Date: Sun, 16 Jan 2022 14:13:09 +0000 Subject: [PATCH] Update `rational-numbers` tests (#1036) --- .../affine-cipher/.docs/instructions.md | 50 ++++++++++--------- .../practice/book-store/.docs/instructions.md | 8 +-- .../.docs/instructions.md | 4 ++ exercises/practice/pov/.docs/instructions.md | 2 +- .../rational-numbers/.meta/tests.toml | 9 ++++ .../test/rational_numbers_test.exs | 15 ++++++ 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/exercises/practice/affine-cipher/.docs/instructions.md b/exercises/practice/affine-cipher/.docs/instructions.md index 919e3811d8..6855736fa7 100644 --- a/exercises/practice/affine-cipher/.docs/instructions.md +++ b/exercises/practice/affine-cipher/.docs/instructions.md @@ -1,14 +1,12 @@ # Instructions -Create an implementation of the affine cipher, -an ancient encryption system created in the Middle East. +Create an implementation of the affine cipher, an ancient encryption system created in the Middle East. -The affine cipher is a type of mono-alphabetic substitution cipher. -Each character is mapped to its numeric equivalent, encrypted with -a mathematical function and then converted to the letter relating to -its new numeric value. Although all mono-alphabetic ciphers are weak, -the affine cipher is much stronger than the atbash cipher, -because it has many more keys. +The affine cipher is a type of monoalphabetic substitution cipher. +Each character is mapped to its numeric equivalent, encrypted with a mathematical function and then converted to the letter relating to its new numeric value. +Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the atbash cipher, because it has many more keys. + +[comment]: # ( monoalphabetic as spelled by Merriam-Webster, compare to polyalphabetic ) ## Encryption @@ -18,20 +16,21 @@ The encryption function is: E(x) = (ai + b) mod m ``` -- where `i` is the letter's index from `0` to the length of the alphabet - 1 -- `m` is the length of the alphabet. For the Roman alphabet `m` is `26`. +Where: + +- `i` is the letter's index from `0` to the length of the alphabet - 1 +- `m` is the length of the alphabet. + For the Roman alphabet `m` is `26`. - `a` and `b` are integers which make the encryption key -Values `a` and `m` must be *coprime* (or, *relatively prime*) for automatic decryption to succeed, -ie. they have number `1` as their only common factor (more information can be found in the -[Wikipedia article about coprime integers](https://en.wikipedia.org/wiki/Coprime_integers)). In case `a` is -not coprime to `m`, your program should indicate that this is an error. Otherwise it should -encrypt or decrypt with the provided key. +Values `a` and `m` must be *coprime* (or, *relatively prime*) for automatic decryption to succeed, i.e., they have number `1` as their only common factor (more information can be found in the [Wikipedia article about coprime integers][coprime-integers]). +In case `a` is not coprime to `m`, your program should indicate that this is an error. +Otherwise it should encrypt or decrypt with the provided key. -For the purpose of this exercise, digits are valid input but they are not encrypted. Spaces and punctuation -characters are excluded. Ciphertext is written out in groups of fixed length separated by space, -the traditional group size being `5` letters. This is to make it harder to guess encrypted text based -on word boundaries. +For the purpose of this exercise, digits are valid input but they are not encrypted. +Spaces and punctuation characters are excluded. +Ciphertext is written out in groups of fixed length separated by space, the traditional group size being `5` letters. +This is to make it harder to guess encrypted text based on word boundaries. ## Decryption @@ -41,9 +40,10 @@ The decryption function is: D(y) = (a^-1)(y - b) mod m ``` -- where `y` is the numeric value of an encrypted letter, ie. `y = E(x)` -- it is important to note that `a^-1` is the modular multiplicative inverse (MMI) - of `a mod m` +Where: + +- `y` is the numeric value of an encrypted letter, i.e., `y = E(x)` +- it is important to note that `a^-1` is the modular multiplicative inverse (MMI) of `a mod m` - the modular multiplicative inverse only exists if `a` and `m` are coprime. The MMI of `a` is `x` such that the remainder after dividing `ax` by `m` is `1`: @@ -52,8 +52,7 @@ The MMI of `a` is `x` such that the remainder after dividing `ax` by `m` is `1`: ax mod m = 1 ``` -More information regarding how to find a Modular Multiplicative Inverse -and what it means can be found in the [related Wikipedia article](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse). +More information regarding how to find a Modular Multiplicative Inverse and what it means can be found in the [related Wikipedia article][MMI]. ## General Examples @@ -70,3 +69,6 @@ Finding MMI for `a = 15`: - `(15 * x) mod 26 = 1` - `(15 * 7) mod 26 = 1`, ie. `105 mod 26 = 1` - `7` is the MMI of `15 mod 26` + +[MMI]: https://en.wikipedia.org/wiki/Modular_multiplicative_inverse +[coprime-integers]: https://en.wikipedia.org/wiki/Coprime_integers diff --git a/exercises/practice/book-store/.docs/instructions.md b/exercises/practice/book-store/.docs/instructions.md index bf49e39da1..cce9deea01 100644 --- a/exercises/practice/book-store/.docs/instructions.md +++ b/exercises/practice/book-store/.docs/instructions.md @@ -43,8 +43,8 @@ This would give a total of: Resulting in: -- 5 * (8 - 2.00) == 5 * 6.00 == $30.00 -- +3 * (8 - 0.80) == 3 * 7.20 == $21.60 +- 5 × (8 - 2.00) = 5 × 6.00 = $30.00 +- +3 × (8 - 0.80) = 3 × 7.20 = $21.60 For a total of $51.60 @@ -60,8 +60,8 @@ This would give a total of: Resulting in: -- 4 * (8 - 1.60) == 4 * 6.40 == $25.60 -- +4 * (8 - 1.60) == 4 * 6.40 == $25.60 +- 4 × (8 - 1.60) = 4 × 6.40 = $25.60 +- +4 × (8 - 1.60) = 4 × 6.40 = $25.60 For a total of $51.20 diff --git a/exercises/practice/largest-series-product/.docs/instructions.md b/exercises/practice/largest-series-product/.docs/instructions.md index b7df99d147..5a3c18de5c 100644 --- a/exercises/practice/largest-series-product/.docs/instructions.md +++ b/exercises/practice/largest-series-product/.docs/instructions.md @@ -12,3 +12,7 @@ in the input; the digits need not be *numerically consecutive*. For the input `'73167176531330624919225119674426574742355349194934'`, the largest product for a series of 6 digits is 23520. + +For a series of zero digits, the largest product is 1 because 1 is the multiplicative identity. +(You don't need to know what a multiplicative identity is to solve this problem; +it just means that multiplying a number by 1 gives you the same number.) diff --git a/exercises/practice/pov/.docs/instructions.md b/exercises/practice/pov/.docs/instructions.md index 1523c03153..8c89be730a 100644 --- a/exercises/practice/pov/.docs/instructions.md +++ b/exercises/practice/pov/.docs/instructions.md @@ -43,4 +43,4 @@ This exercise involves taking an input tree and re-orientating it from the point of view of one of the nodes. [wiki-graph]: https://en.wikipedia.org/wiki/Tree_(graph_theory) -[wiki-tree]: https://en.wikipedia.org/wiki/Graph_(discrete_mathematics) \ No newline at end of file +[wiki-tree]: https://en.wikipedia.org/wiki/Graph_(discrete_mathematics) diff --git a/exercises/practice/rational-numbers/.meta/tests.toml b/exercises/practice/rational-numbers/.meta/tests.toml index 30cf65def6..a1eb2996c5 100644 --- a/exercises/practice/rational-numbers/.meta/tests.toml +++ b/exercises/practice/rational-numbers/.meta/tests.toml @@ -84,6 +84,15 @@ description = "Exponentiation of a rational number -> Raise a positive rational [8168edd2-0af3-45b1-b03f-72c01332e10a] description = "Exponentiation of a rational number -> Raise a negative rational number to a positive integer power" +[c291cfae-cfd8-44f5-aa6c-b175c148a492] +description = "Exponentiation of a rational number -> Raise a positive rational number to a negative integer power" + +[45cb3288-4ae4-4465-9ae5-c129de4fac8e] +description = "Exponentiation of a rational number -> Raise a negative rational number to an even negative integer power" + +[2d47f945-ffe1-4916-a399-c2e8c27d7f72] +description = "Exponentiation of a rational number -> Raise a negative rational number to an odd negative integer power" + [e2f25b1d-e4de-4102-abc3-c2bb7c4591e4] description = "Exponentiation of a rational number -> Raise zero to an integer power" diff --git a/exercises/practice/rational-numbers/test/rational_numbers_test.exs b/exercises/practice/rational-numbers/test/rational_numbers_test.exs index 46d0bf55cb..45e217df78 100644 --- a/exercises/practice/rational-numbers/test/rational_numbers_test.exs +++ b/exercises/practice/rational-numbers/test/rational_numbers_test.exs @@ -137,6 +137,21 @@ defmodule RationalNumbersTest do assert RationalNumbers.pow_rational({-1, 2}, 3) == {-1, 8} end + @tag :pending + test "Raise a positive rational number to a negative integer power" do + assert RationalNumbers.pow_rational({3, 5}, -2) == {25, 9} + end + + @tag :pending + test "Raise a negative rational number to an even negative integer power" do + assert RationalNumbers.pow_rational({-3, 5}, -2) == {25, 9} + end + + @tag :pending + test "Raise a negative rational number to an odd negative integer power" do + assert RationalNumbers.pow_rational({-3, 5}, -3) == {-125, 27} + end + @tag :pending test "Raise zero to an integer power" do assert RationalNumbers.pow_rational({0, 1}, 5) == {0, 1}