Skip to content

Commit 2dbe207

Browse files
ErikSchierboommirkoperillo
authored andcommitted
[v3] Create instruction from prob-specs descriptions
Practice Exercises in Exercism v3 will be structured differently. One such change is that there won't be a (generated) README.md file anymore. This file will be replaced by `.docs/instructions.md` and optionally a `.docs/introduction.md` files. These files are copies of the information defined for their corresponding problem-specifications exercise (if any). The `.docs/instructions.md` file is a copy of the `instructions.md` file of the problem-specifications exercise, or if that does not exists, its `description.md` file. The new [configlet](https://github.com/exercism/configlet) version will add support for doing this syncing automatically. See [the spec](https://github.com/exercism/docs/blob/main/anatomy/tracks/practice-exercises.md) for more information.
1 parent 2bcf25e commit 2dbe207

120 files changed

Lines changed: 4067 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Instructions
2+
3+
Implement the `accumulate` operation, which, given a collection and an
4+
operation to perform on each element of the collection, returns a new
5+
collection containing the result of applying that operation to each element of
6+
the input collection.
7+
8+
Given the collection of numbers:
9+
10+
- 1, 2, 3, 4, 5
11+
12+
And the operation:
13+
14+
- square a number (`x => x * x`)
15+
16+
Your code should be able to produce the collection of squares:
17+
18+
- 1, 4, 9, 16, 25
19+
20+
Check out the test suite to see the expected function signature.
21+
22+
## Restrictions
23+
24+
Keep your hands off that collect/map/fmap/whatchamacallit functionality
25+
provided by your standard library!
26+
Solve this one yourself using other basic tools instead.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Instructions
2+
3+
Convert a phrase to its acronym.
4+
5+
Techies love their TLA (Three Letter Acronyms)!
6+
7+
Help generate some jargon by writing a program that converts a long name
8+
like Portable Network Graphics to its acronym (PNG).
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Instructions
2+
3+
Create an implementation of the affine cipher,
4+
an ancient encryption system created in the Middle East.
5+
6+
The affine cipher is a type of monoalphabetic 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 monoalphabetic ciphers are weak,
10+
the affine cypher is much stronger than the atbash cipher,
11+
because it has many more keys.
12+
13+
The encryption function is:
14+
15+
`E(x) = (ax + b) mod m`
16+
- where `x` is the letter's index from 0 - length of alphabet - 1
17+
- `m` is the length of the alphabet. For the roman alphabet `m == 26`.
18+
- and `a` and `b` make the key
19+
20+
The decryption function is:
21+
22+
`D(y) = a^-1(y - b) mod m`
23+
- where `y` is the numeric value of an encrypted letter, ie. `y = E(x)`
24+
- it is important to note that `a^-1` is the modular multiplicative inverse
25+
of `a mod m`
26+
- the modular multiplicative inverse of `a` only exists if `a` and `m` are
27+
coprime.
28+
29+
To find the MMI of `a`:
30+
31+
`an mod m = 1`
32+
- where `n` is the modular multiplicative inverse of `a mod m`
33+
34+
More information regarding how to find a Modular Multiplicative Inverse
35+
and what it means can be found [here.](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse)
36+
37+
Because automatic decryption fails if `a` is not coprime to `m` your
38+
program should return status 1 and `"Error: a and m must be coprime."`
39+
if they are not. Otherwise it should encode or decode with the
40+
provided key.
41+
42+
The Caesar (shift) cipher is a simple affine cipher where `a` is 1 and
43+
`b` as the magnitude results in a static displacement of the letters.
44+
This is much less secure than a full implementation of the affine cipher.
45+
46+
Ciphertext is written out in groups of fixed length, the traditional group
47+
size being 5 letters, and punctuation is excluded. This is to make it
48+
harder to guess things based on word boundaries.
49+
50+
## General Examples
51+
52+
- Encoding `test` gives `ybty` with the key a=5 b=7
53+
- Decoding `ybty` gives `test` with the key a=5 b=7
54+
- Decoding `ybty` gives `lqul` with the wrong key a=11 b=7
55+
- Decoding `kqlfd jzvgy tpaet icdhm rtwly kqlon ubstx`
56+
- gives `thequickbrownfoxjumpsoverthelazydog` with the key a=19 b=13
57+
- Encoding `test` with the key a=18 b=13
58+
- gives `Error: a and m must be coprime.`
59+
- because a and m are not relatively prime
60+
61+
## Examples of finding a Modular Multiplicative Inverse (MMI)
62+
63+
- simple example:
64+
- `9 mod 26 = 9`
65+
- `9 * 3 mod 26 = 27 mod 26 = 1`
66+
- `3` is the MMI of `9 mod 26`
67+
- a more complicated example:
68+
- `15 mod 26 = 15`
69+
- `15 * 7 mod 26 = 105 mod 26 = 1`
70+
- `7` is the MMI of `15 mod 26`
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Instructions
2+
3+
Convert a number, represented as a sequence of digits in one base, to any other base.
4+
5+
Implement general base conversion. Given a number in base **a**,
6+
represented as a sequence of digits, convert it to base **b**.
7+
8+
## Note
9+
10+
- Try to implement the conversion yourself.
11+
Do not use something else to perform the conversion for you.
12+
13+
## About [Positional Notation](https://en.wikipedia.org/wiki/Positional_notation)
14+
15+
In positional notation, a number in base **b** can be understood as a linear
16+
combination of powers of **b**.
17+
18+
The number 42, *in base 10*, means:
19+
20+
(4 * 10^1) + (2 * 10^0)
21+
22+
The number 101010, *in base 2*, means:
23+
24+
(1 * 2^5) + (0 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (0 * 2^0)
25+
26+
The number 1120, *in base 3*, means:
27+
28+
(1 * 3^3) + (1 * 3^2) + (2 * 3^1) + (0 * 3^0)
29+
30+
I think you got the idea!
31+
32+
*Yes. Those three numbers above are exactly the same. Congratulations!*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Instructions
2+
3+
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
4+
5+
An allergy test produces a single numeric score which contains the
6+
information about all the allergies the person has (that they were
7+
tested for).
8+
9+
The list of items (and their value) that were tested are:
10+
11+
* eggs (1)
12+
* peanuts (2)
13+
* shellfish (4)
14+
* strawberries (8)
15+
* tomatoes (16)
16+
* chocolate (32)
17+
* pollen (64)
18+
* cats (128)
19+
20+
So if Tom is allergic to peanuts and chocolate, he gets a score of 34.
21+
22+
Now, given just that score of 34, your program should be able to say:
23+
24+
- Whether Tom is allergic to any one of those allergens listed above.
25+
- All the allergens Tom is allergic to.
26+
27+
Note: a given score may include allergens **not** listed above (i.e.
28+
allergens that score 256, 512, 1024, etc.). Your program should
29+
ignore those components of the score. For example, if the allergy
30+
score is 257, your program should only report the eggs (1) allergy.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Instructions
2+
3+
Write a function to solve alphametics puzzles.
4+
5+
[Alphametics](https://en.wikipedia.org/wiki/Alphametics) is a puzzle where
6+
letters in words are replaced with numbers.
7+
8+
For example `SEND + MORE = MONEY`:
9+
10+
```text
11+
S E N D
12+
M O R E +
13+
-----------
14+
M O N E Y
15+
```
16+
17+
Replacing these with valid numbers gives:
18+
19+
```text
20+
9 5 6 7
21+
1 0 8 5 +
22+
-----------
23+
1 0 6 5 2
24+
```
25+
26+
This is correct because every letter is replaced by a different number and the
27+
words, translated into numbers, then make a valid sum.
28+
29+
Each letter must represent a different digit, and the leading digit of
30+
a multi-digit number must not be zero.
31+
32+
Write a function to solve alphametics puzzles.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Instructions
2+
3+
An anagram is a rearrangement of letters to form a new word.
4+
Given a word and a list of candidates, select the sublist of anagrams of the given word.
5+
6+
Given `"listen"` and a list of candidates like `"enlists" "google"
7+
"inlets" "banana"` the program should return a list containing
8+
`"inlets"`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Instructions
2+
3+
An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits.
4+
5+
For example:
6+
7+
- 9 is an Armstrong number, because `9 = 9^1 = 9`
8+
- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1`
9+
- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153`
10+
- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`
11+
12+
Write some code to determine whether a number is an Armstrong number.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Instructions
2+
3+
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
4+
5+
The Atbash cipher is a simple substitution cipher that relies on
6+
transposing all the letters in the alphabet such that the resulting
7+
alphabet is backwards. The first letter is replaced with the last
8+
letter, the second with the second-last, and so on.
9+
10+
An Atbash cipher for the Latin alphabet would be as follows:
11+
12+
```text
13+
Plain: abcdefghijklmnopqrstuvwxyz
14+
Cipher: zyxwvutsrqponmlkjihgfedcba
15+
```
16+
17+
It is a very weak cipher because it only has one possible key, and it is
18+
a simple monoalphabetic substitution cipher. However, this may not have
19+
been an issue in the cipher's time.
20+
21+
Ciphertext is written out in groups of fixed length, the traditional group size
22+
being 5 letters, and punctuation is excluded. This is to make it harder to guess
23+
things based on word boundaries.
24+
25+
## Examples
26+
27+
- Encoding `test` gives `gvhg`
28+
- Decoding `gvhg` gives `test`
29+
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Instructions
2+
3+
Simulate a bank account supporting opening/closing, withdrawals, and deposits
4+
of money. Watch out for concurrent transactions!
5+
6+
A bank account can be accessed in multiple ways. Clients can make
7+
deposits and withdrawals using the internet, mobile phones, etc. Shops
8+
can charge against the account.
9+
10+
Create an account that can be accessed from multiple threads/processes
11+
(terminology depends on your programming language).
12+
13+
It should be possible to close an account; operations against a closed
14+
account must fail.
15+
16+
## Instructions
17+
18+
Run the test file, and fix each of the errors in turn. When you get the
19+
first test to pass, go to the first pending or skipped test, and make
20+
that pass as well. When all of the tests are passing, feel free to
21+
submit.
22+
23+
Remember that passing code is just the first step. The goal is to work
24+
towards a solution that is as readable and expressive as you can make
25+
it.
26+
27+
Have fun!

0 commit comments

Comments
 (0)