Skip to content

[Maintenance]: Sync Practice Exercises from Problem Specification Repo #2914

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

Merged
merged 22 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1224d4c
Sync practice exercise instructions with problem-specifications.
BethanyG Feb 9, 2022
caffc49
Updated practice exericse config.json files.
BethanyG Feb 9, 2022
50e3d6b
Updated Bowling tests toml and regenerated test file.
BethanyG Feb 9, 2022
e9bda61
Updated collatz-conjecture from problem-specifications.
BethanyG Feb 9, 2022
15eef70
Updated Flatten Array.
BethanyG Feb 9, 2022
1caed2d
Updated Forth from cannonical data.
BethanyG Feb 9, 2022
7203e18
Updated Largest Series Product from problem-specifications.
BethanyG Feb 9, 2022
c392693
Updated List Ops from problem-specifications.
BethanyG Feb 9, 2022
26c6789
Updated Matching Brackets from problem-specifications.
BethanyG Feb 9, 2022
baddde0
Updated Pangram from problem-specifications.
BethanyG Feb 10, 2022
84982e8
Updated Protein Translation from problem-specifications.
BethanyG Feb 10, 2022
ac0a919
Updated Queen Attack from problem-specifications.
BethanyG Feb 10, 2022
02e5794
Updated Rational Numbers from problem-specifications.
BethanyG Feb 10, 2022
d0be1c2
Updated Roman Numerals from problem-specifications.
BethanyG Feb 10, 2022
a1ecf42
Reverted stub to remove solution.
BethanyG Feb 10, 2022
9d605b7
Updated Scale Generator from problem-speifications.
BethanyG Feb 10, 2022
5f4a529
Updated tests.toml from problem-specifications.
BethanyG Feb 10, 2022
a2687ec
Updated Word Search from problem specifications.
BethanyG Feb 10, 2022
8ac1f7a
Updated Zipper from problem specifications.
BethanyG Feb 10, 2022
01bbcd3
Updated Two Bucket from problem-specifications.
BethanyG Feb 10, 2022
ef199c1
Regenerated test file for meetup exercise.
BethanyG Feb 10, 2022
2c5a839
Removed example solution code from stub file.
BethanyG Feb 10, 2022
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
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Convert a long phrase to its acronym",
"blurb": "Convert a long phrase to its acronym.",
"authors": [
"rootulp"
],
Expand Down
108 changes: 56 additions & 52 deletions exercises/practice/affine-cipher/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,74 @@
# 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 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 cypher is much stronger than the atbash cipher,
because it has many more keys.
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

The encryption function is:

`E(x) = (ax + b) mod m`
- where `x` is the letter's index from 0 - length of alphabet - 1
- `m` is the length of the alphabet. For the roman alphabet `m == 26`.
- and `a` and `b` make the key
```text
E(x) = (ai + b) mod m
```

The decryption function is:
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, 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.

`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
of `a mod m`
- the modular multiplicative inverse of `a` only exists if `a` and `m` are
coprime.
## Decryption

To find the MMI of `a`:
The decryption function is:

```text
D(y) = (a^-1)(y - b) mod m
```

`an mod m = 1`
- where `n` is the modular multiplicative inverse of `a mod m`
Where:

More information regarding how to find a Modular Multiplicative Inverse
and what it means can be found [here.](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse)
- `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.

Because automatic decryption fails if `a` is not coprime to `m` your
program should return status 1 and `"Error: a and m must be coprime."`
if they are not. Otherwise it should encode or decode with the
provided key.
The MMI of `a` is `x` such that the remainder after dividing `ax` by `m` is `1`:

The Caesar (shift) cipher is a simple affine cipher where `a` is 1 and
`b` as the magnitude results in a static displacement of the letters.
This is much less secure than a full implementation of the affine cipher.
```text
ax mod m = 1
```

Ciphertext is written out in groups of fixed length, the traditional group
size being 5 letters, and punctuation is excluded. This is to make it
harder to guess things based on word boundaries.
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

- Encoding `test` gives `ybty` with the key a=5 b=7
- Decoding `ybty` gives `test` with the key a=5 b=7
- Decoding `ybty` gives `lqul` with the wrong key a=11 b=7
- Decoding `kqlfd jzvgy tpaet icdhm rtwly kqlon ubstx`
- gives `thequickbrownfoxjumpsoverthelazydog` with the key a=19 b=13
- Encoding `test` with the key a=18 b=13
- gives `Error: a and m must be coprime.`
- because a and m are not relatively prime

## Examples of finding a Modular Multiplicative Inverse (MMI)

- simple example:
- `9 mod 26 = 9`
- `9 * 3 mod 26 = 27 mod 26 = 1`
- `3` is the MMI of `9 mod 26`
- a more complicated example:
- `15 mod 26 = 15`
- `15 * 7 mod 26 = 105 mod 26 = 1`
- `7` is the MMI of `15 mod 26`
- Encrypting `"test"` gives `"ybty"` with the key `a = 5`, `b = 7`
- Decrypting `"ybty"` gives `"test"` with the key `a = 5`, `b = 7`
- Decrypting `"ybty"` gives `"lqul"` with the wrong key `a = 11`, `b = 7`
- Decrypting `"kqlfd jzvgy tpaet icdhm rtwly kqlon ubstx"` gives `"thequickbrownfoxjumpsoverthelazydog"` with the key `a = 19`, `b = 13`
- Encrypting `"test"` with the key `a = 18`, `b = 13` is an error because `18` and `26` are not coprime

## Example of finding a Modular Multiplicative Inverse (MMI)

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
6 changes: 3 additions & 3 deletions exercises/practice/all-your-base/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ combination of powers of **b**.

The number 42, *in base 10*, means:

(4 * 10^1) + (2 * 10^0)
(4 \* 10^1) + (2 \* 10^0)

The number 101010, *in base 2*, means:

(1 * 2^5) + (0 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (0 * 2^0)
(1 \* 2^5) + (0 \* 2^4) + (1 \* 2^3) + (0 \* 2^2) + (1 \* 2^1) + (0 \* 2^0)

The number 1120, *in base 3*, means:

(1 * 3^3) + (1 * 3^2) + (2 * 3^1) + (0 * 3^0)
(1 \* 3^3) + (1 \* 3^2) + (2 \* 3^1) + (0 \* 3^0)

I think you got the idea!

Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/allergies/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ So if Tom is allergic to peanuts and chocolate, he gets a score of 34.

Now, given just that score of 34, your program should be able to say:

- Whether Tom is allergic to any one of those allergens listed above.
- All the allergens Tom is allergic to.
* Whether Tom is allergic to any one of those allergens listed above.
* All the allergens Tom is allergic to.

Note: a given score may include allergens **not** listed above (i.e.
allergens that score 256, 512, 1024, etc.). Your program should
Expand Down
15 changes: 10 additions & 5 deletions exercises/practice/anagram/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Instructions

An anagram is a rearrangement of letters to form a new word.
Given a word and a list of candidates, select the sublist of anagrams of the given word.
An anagram is a rearrangement of letters to form a new word: for example `"owns"` is an anagram of `"snow"`.
A word is not its own anagram: for example, `"stop"` is not an anagram of `"stop"`.

Given `"listen"` and a list of candidates like `"enlists" "google"
"inlets" "banana"` the program should return a list containing
`"inlets"`.
Given a target word and a set of candidate words, this exercise requests the anagram set: the subset of the candidates that are anagrams of the target.

The target and candidates are words of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`).
Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `StoP` is not an anagram of `sTOp`.
The anagram set is the subset of the candidate set that are anagrams of the target (in any order).
Words in the anagram set should have the same letter case as in the candidate set.

Given the target `"stone"` and candidates `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, `"Seton"`, the anagram set is `"tones"`, `"notes"`, `"Seton"`.
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Determine if a number is an Armstrong number",
"blurb": "Determine if a number is an Armstrong number.",
"authors": [
"pheanex"
],
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/atbash-cipher/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ Cipher: zyxwvutsrqponmlkjihgfedcba
```

It is a very weak cipher because it only has one possible key, and it is
a simple monoalphabetic substitution cipher. However, this may not have
a simple mono-alphabetic substitution cipher. However, this may not have
been an issue in the cipher's time.

Ciphertext is written out in groups of fixed length, the traditional group size
being 5 letters, and punctuation is excluded. This is to make it harder to guess
things based on word boundaries.
being 5 letters, leaving numbers unchanged, and punctuation is excluded.
This is to make it harder to guess things based on word boundaries.

## Examples

- Encoding `test` gives `gvhg`
- Encoding `x123 yes` gives `c123b vh`
- Decoding `gvhg` gives `test`
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`
2 changes: 1 addition & 1 deletion exercises/practice/binary/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles",
"blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.",
"authors": [],
"contributors": [
"behrtam",
Expand Down
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
4 changes: 2 additions & 2 deletions exercises/practice/bowling/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Score a bowling game",
"blurb": "Score a bowling game.",
"authors": [
"aes421"
],
Expand All @@ -22,6 +22,6 @@
".meta/example.py"
]
},
"source": "The Bowling Game Kata at but UncleBob",
"source": "The Bowling Game Kata from UncleBob",
"source_url": "http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata"
}
16 changes: 13 additions & 3 deletions exercises/practice/bowling/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# 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.

[656ae006-25c2-438c-a549-f338e7ec7441]
description = "should be able to score a game with all zeros"
Expand Down Expand Up @@ -38,6 +45,9 @@ description = "rolling a spare with the two roll bonus does not get a bonus roll
[576faac1-7cff-4029-ad72-c16bcada79b5]
description = "strikes with the two roll bonus do not get bonus rolls"

[efb426ec-7e15-42e6-9b96-b4fca3ec2359]
description = "last two strikes followed by only last bonus with non strike points"

[72e24404-b6c6-46af-b188-875514c0377b]
description = "a strike with the one roll bonus after a spare in the last frame does not get a bonus"

Expand Down
5 changes: 5 additions & 0 deletions exercises/practice/bowling/bowling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def test_strikes_with_the_two_roll_bonus_do_not_get_bonus_rolls(self):
game = self.roll_new_game(rolls)
self.assertEqual(game.score(), 30)

def test_last_two_strikes_followed_by_only_last_bonus_with_non_strike_points(self):
rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 0, 1]
game = self.roll_new_game(rolls)
self.assertEqual(game.score(), 31)

def test_a_strike_with_the_one_roll_bonus_after_a_spare_in_the_last_frame_does_not_get_a_bonus(
self,
):
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/change/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Correctly determine change to be given using the least number of coins",
"blurb": "Correctly determine change to be given using the least number of coins.",
"authors": [
"justani"
],
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/collatz-conjecture/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture",
"blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture.",
"authors": [
"zwaltman"
],
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/collatz-conjecture/.meta/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def steps(number):
if number <= 0:
raise ValueError('Only positive numbers are allowed')
raise ValueError('Only positive integers are allowed')

step_count = 0
while number > 1:
Expand Down
23 changes: 20 additions & 3 deletions exercises/practice/collatz-conjecture/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# 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.

[540a3d51-e7a6-47a5-92a3-4ad1838f0bfd]
description = "zero steps for one"
Expand All @@ -16,6 +23,16 @@ description = "large number of even and odd steps"

[7d4750e6-def9-4b86-aec7-9f7eb44f95a3]
description = "zero is an error"
include = false

[2187673d-77d6-4543-975e-66df6c50e2da]
description = "zero is an error"
reimplements = "7d4750e6-def9-4b86-aec7-9f7eb44f95a3"

[c6c795bf-a288-45e9-86a1-841359ad426d]
description = "negative value is an error"
include = false

[ec11f479-56bc-47fd-a434-bcd7a31a7a2e]
description = "negative value is an error"
reimplements = "c6c795bf-a288-45e9-86a1-841359ad426d"
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def test_zero_is_an_error(self):
with self.assertRaises(ValueError) as err:
steps(0)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Only positive numbers are allowed")
self.assertEqual(err.exception.args[0], "Only positive integers are allowed")

def test_negative_value_is_an_error(self):

with self.assertRaises(ValueError) as err:
steps(-15)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Only positive numbers are allowed")
self.assertEqual(err.exception.args[0], "Only positive integers are allowed")
2 changes: 1 addition & 1 deletion exercises/practice/connect/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Compute the result for a game of Hex / Polygon",
"blurb": "Compute the result for a game of Hex / Polygon.",
"authors": [
"yunchih"
],
Expand Down
Loading