Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rational-numbers tests #1036

Merged
merged 2 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions exercises/practice/affine-cipher/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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`:
Expand All @@ -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

Expand All @@ -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
8 changes: 4 additions & 4 deletions exercises/practice/book-store/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
2 changes: 1 addition & 1 deletion exercises/practice/pov/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[wiki-tree]: https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)
9 changes: 9 additions & 0 deletions exercises/practice/rational-numbers/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
15 changes: 15 additions & 0 deletions exercises/practice/rational-numbers/test/rational_numbers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down