Skip to content

Commit 9fca33e

Browse files
authored
Update rational-numbers tests (#1036)
1 parent 2b4347e commit 9fca33e

File tree

6 files changed

+59
-29
lines changed

6 files changed

+59
-29
lines changed
+26-24
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# Instructions
22

3-
Create an implementation of the affine cipher,
4-
an ancient encryption system created in the Middle East.
3+
Create an implementation of the affine cipher, an ancient encryption system created in the Middle East.
54

6-
The affine cipher is a type of mono-alphabetic substitution cipher.
7-
Each character is mapped to its numeric equivalent, encrypted with
8-
a mathematical function and then converted to the letter relating to
9-
its new numeric value. Although all mono-alphabetic ciphers are weak,
10-
the affine cipher is much stronger than the atbash cipher,
11-
because it has many more keys.
5+
The affine cipher is a type of monoalphabetic substitution cipher.
6+
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.
7+
Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the atbash cipher, because it has many more keys.
8+
9+
[comment]: # ( monoalphabetic as spelled by Merriam-Webster, compare to polyalphabetic )
1210

1311
## Encryption
1412

@@ -18,20 +16,21 @@ The encryption function is:
1816
E(x) = (ai + b) mod m
1917
```
2018

21-
- where `i` is the letter's index from `0` to the length of the alphabet - 1
22-
- `m` is the length of the alphabet. For the Roman alphabet `m` is `26`.
19+
Where:
20+
21+
- `i` is the letter's index from `0` to the length of the alphabet - 1
22+
- `m` is the length of the alphabet.
23+
For the Roman alphabet `m` is `26`.
2324
- `a` and `b` are integers which make the encryption key
2425

25-
Values `a` and `m` must be *coprime* (or, *relatively prime*) for automatic decryption to succeed,
26-
ie. they have number `1` as their only common factor (more information can be found in the
27-
[Wikipedia article about coprime integers](https://en.wikipedia.org/wiki/Coprime_integers)). In case `a` is
28-
not coprime to `m`, your program should indicate that this is an error. Otherwise it should
29-
encrypt or decrypt with the provided key.
26+
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]).
27+
In case `a` is not coprime to `m`, your program should indicate that this is an error.
28+
Otherwise it should encrypt or decrypt with the provided key.
3029

31-
For the purpose of this exercise, digits are valid input but they are not encrypted. Spaces and punctuation
32-
characters are excluded. Ciphertext is written out in groups of fixed length separated by space,
33-
the traditional group size being `5` letters. This is to make it harder to guess encrypted text based
34-
on word boundaries.
30+
For the purpose of this exercise, digits are valid input but they are not encrypted.
31+
Spaces and punctuation characters are excluded.
32+
Ciphertext is written out in groups of fixed length separated by space, the traditional group size being `5` letters.
33+
This is to make it harder to guess encrypted text based on word boundaries.
3534

3635
## Decryption
3736

@@ -41,9 +40,10 @@ The decryption function is:
4140
D(y) = (a^-1)(y - b) mod m
4241
```
4342

44-
- where `y` is the numeric value of an encrypted letter, ie. `y = E(x)`
45-
- it is important to note that `a^-1` is the modular multiplicative inverse (MMI)
46-
of `a mod m`
43+
Where:
44+
45+
- `y` is the numeric value of an encrypted letter, i.e., `y = E(x)`
46+
- it is important to note that `a^-1` is the modular multiplicative inverse (MMI) of `a mod m`
4747
- the modular multiplicative inverse only exists if `a` and `m` are coprime.
4848

4949
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`:
5252
ax mod m = 1
5353
```
5454

55-
More information regarding how to find a Modular Multiplicative Inverse
56-
and what it means can be found in the [related Wikipedia article](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse).
55+
More information regarding how to find a Modular Multiplicative Inverse and what it means can be found in the [related Wikipedia article][MMI].
5756

5857
## General Examples
5958

@@ -70,3 +69,6 @@ Finding MMI for `a = 15`:
7069
- `(15 * x) mod 26 = 1`
7170
- `(15 * 7) mod 26 = 1`, ie. `105 mod 26 = 1`
7271
- `7` is the MMI of `15 mod 26`
72+
73+
[MMI]: https://en.wikipedia.org/wiki/Modular_multiplicative_inverse
74+
[coprime-integers]: https://en.wikipedia.org/wiki/Coprime_integers

Diff for: exercises/practice/book-store/.docs/instructions.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ This would give a total of:
4343

4444
Resulting in:
4545

46-
- 5 * (8 - 2.00) == 5 * 6.00 == $30.00
47-
- +3 * (8 - 0.80) == 3 * 7.20 == $21.60
46+
- 5 × (8 - 2.00) = 5 × 6.00 = $30.00
47+
- +3 × (8 - 0.80) = 3 × 7.20 = $21.60
4848

4949
For a total of $51.60
5050

@@ -60,8 +60,8 @@ This would give a total of:
6060

6161
Resulting in:
6262

63-
- 4 * (8 - 1.60) == 4 * 6.40 == $25.60
64-
- +4 * (8 - 1.60) == 4 * 6.40 == $25.60
63+
- 4 × (8 - 1.60) = 4 × 6.40 = $25.60
64+
- +4 × (8 - 1.60) = 4 × 6.40 = $25.60
6565

6666
For a total of $51.20
6767

Diff for: exercises/practice/largest-series-product/.docs/instructions.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ in the input; the digits need not be *numerically consecutive*.
1212

1313
For the input `'73167176531330624919225119674426574742355349194934'`,
1414
the largest product for a series of 6 digits is 23520.
15+
16+
For a series of zero digits, the largest product is 1 because 1 is the multiplicative identity.
17+
(You don't need to know what a multiplicative identity is to solve this problem;
18+
it just means that multiplying a number by 1 gives you the same number.)

Diff for: exercises/practice/pov/.docs/instructions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ This exercise involves taking an input tree and re-orientating it from the point
4343
of view of one of the nodes.
4444

4545
[wiki-graph]: https://en.wikipedia.org/wiki/Tree_(graph_theory)
46-
[wiki-tree]: https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)
46+
[wiki-tree]: https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)

Diff for: exercises/practice/rational-numbers/.meta/tests.toml

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ description = "Exponentiation of a rational number -> Raise a positive rational
8484
[8168edd2-0af3-45b1-b03f-72c01332e10a]
8585
description = "Exponentiation of a rational number -> Raise a negative rational number to a positive integer power"
8686

87+
[c291cfae-cfd8-44f5-aa6c-b175c148a492]
88+
description = "Exponentiation of a rational number -> Raise a positive rational number to a negative integer power"
89+
90+
[45cb3288-4ae4-4465-9ae5-c129de4fac8e]
91+
description = "Exponentiation of a rational number -> Raise a negative rational number to an even negative integer power"
92+
93+
[2d47f945-ffe1-4916-a399-c2e8c27d7f72]
94+
description = "Exponentiation of a rational number -> Raise a negative rational number to an odd negative integer power"
95+
8796
[e2f25b1d-e4de-4102-abc3-c2bb7c4591e4]
8897
description = "Exponentiation of a rational number -> Raise zero to an integer power"
8998

Diff for: exercises/practice/rational-numbers/test/rational_numbers_test.exs

+15
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ defmodule RationalNumbersTest do
137137
assert RationalNumbers.pow_rational({-1, 2}, 3) == {-1, 8}
138138
end
139139

140+
@tag :pending
141+
test "Raise a positive rational number to a negative integer power" do
142+
assert RationalNumbers.pow_rational({3, 5}, -2) == {25, 9}
143+
end
144+
145+
@tag :pending
146+
test "Raise a negative rational number to an even negative integer power" do
147+
assert RationalNumbers.pow_rational({-3, 5}, -2) == {25, 9}
148+
end
149+
150+
@tag :pending
151+
test "Raise a negative rational number to an odd negative integer power" do
152+
assert RationalNumbers.pow_rational({-3, 5}, -3) == {-125, 27}
153+
end
154+
140155
@tag :pending
141156
test "Raise zero to an integer power" do
142157
assert RationalNumbers.pow_rational({0, 1}, 5) == {0, 1}

0 commit comments

Comments
 (0)