Skip to content

Commit a3e75d9

Browse files
🤖 Configlet sync: docs, metadata, and filepaths (#2082)
1 parent 4b19aae commit a3e75d9

File tree

8 files changed

+77
-105
lines changed

8 files changed

+77
-105
lines changed

exercises/practice/dot-dsl/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Write a Domain Specific Language similar to the Graphviz dot language.
2222
Our DSL is similar to the Graphviz dot language in that our DSL will be used to create graph data structures.
2323
However, unlike the DOT Language, our DSL will be an internal DSL for use only in our language.
2424

25-
More information about the difference between internal and external DSLs can be found [here][fowler-dsl].
25+
[Learn more about the difference between internal and external DSLs][fowler-dsl].
2626

2727
[dsl]: https://en.wikipedia.org/wiki/Domain-specific_language
2828
[dot-language]: https://en.wikipedia.org/wiki/DOT_(graph_description_language)

exercises/practice/eliuds-eggs/.docs/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The position information encoding is calculated as follows:
5858

5959
### Decimal number on the display
6060

61-
16
61+
8
6262

6363
### Actual eggs in the coop
6464

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instructions
22

3-
Determine whether a credit card number is valid according to the [Luhn formula][luhn].
3+
Determine whether a number is valid according to the [Luhn formula][luhn].
44

55
The number will be provided as a string.
66

@@ -10,54 +10,59 @@ Strings of length 1 or less are not valid.
1010
Spaces are allowed in the input, but they should be stripped before checking.
1111
All other non-digit characters are disallowed.
1212

13-
### Example 1: valid credit card number
13+
## Examples
1414

15-
```text
16-
4539 3195 0343 6467
17-
```
15+
### Valid credit card number
1816

19-
The first step of the Luhn algorithm is to double every second digit, starting from the right.
20-
We will be doubling
17+
The number to be checked is `4539 3195 0343 6467`.
18+
19+
The first step of the Luhn algorithm is to start at the end of the number and double every second digit, beginning with the second digit from the right and moving left.
2120

2221
```text
2322
4539 3195 0343 6467
2423
↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ (double these)
2524
```
2625

27-
If doubling the number results in a number greater than 9 then subtract 9 from the product.
28-
The results of our doubling:
26+
If the result of doubling a digit is greater than 9, we subtract 9 from that result.
27+
We end up with:
2928

3029
```text
3130
8569 6195 0383 3437
3231
```
3332

34-
Then sum all of the digits:
33+
Finally, we sum all digits.
34+
If the sum is evenly divisible by 10, the original number is valid.
3535

3636
```text
37-
8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80
37+
8 + 5 + 6 + 9 + 6 + 1 + 9 + 5 + 0 + 3 + 8 + 3 + 3 + 4 + 3 + 7 = 80
3838
```
3939

40-
If the sum is evenly divisible by 10, then the number is valid.
41-
This number is valid!
40+
80 is evenly divisible by 10, so number `4539 3195 0343 6467` is valid!
41+
42+
### Invalid Canadian SIN
43+
44+
The number to be checked is `066 123 478`.
4245

43-
### Example 2: invalid credit card number
46+
We start at the end of the number and double every second digit, beginning with the second digit from the right and moving left.
4447

4548
```text
46-
8273 1232 7352 0569
49+
066 123 478
50+
↑ ↑ ↑ ↑ (double these)
4751
```
4852

49-
Double the second digits, starting from the right
53+
If the result of doubling a digit is greater than 9, we subtract 9 from that result.
54+
We end up with:
5055

5156
```text
52-
7253 2262 5312 0539
57+
036 226 458
5358
```
5459

55-
Sum the digits
60+
We sum the digits:
5661

5762
```text
58-
7+2+5+3+2+2+6+2+5+3+1+2+0+5+3+9 = 57
63+
0 + 3 + 6 + 2 + 2 + 6 + 4 + 5 + 8 = 36
5964
```
6065

61-
57 is not evenly divisible by 10, so this number is not valid.
66+
36 is not evenly divisible by 10, so number `066 123 478` is not valid!
6267

6368
[luhn]: https://en.wikipedia.org/wiki/Luhn_algorithm

exercises/practice/luhn/.docs/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
At the Global Verification Authority, you've just been entrusted with a critical assignment.
44
Across the city, from online purchases to secure logins, countless operations rely on the accuracy of numerical identifiers like credit card numbers, bank account numbers, transaction codes, and tracking IDs.
5-
The Luhn algorithm is a simple checksum formula used to ensure these numbers are valid and error-free.
5+
The Luhn algorithm is a simple checksum formula used to help identify mistyped numbers.
66

77
A batch of identifiers has just arrived on your desk.
88
All of them must pass the Luhn test to ensure they're legitimate.
9-
If any fail, they'll be flagged as invalid, preventing errors or fraud, such as incorrect transactions or unauthorized access.
9+
If any fail, they'll be flagged as invalid, preventing mistakes such as incorrect transactions or failed account verifications.
1010

1111
Can you ensure this is done right? The integrity of many services depends on you.

exercises/practice/phone-number/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instructions
22

3-
Clean up user-entered phone numbers so that they can be sent SMS messages.
3+
Clean up phone numbers so that they can be sent SMS messages.
44

55
The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda.
66
All NANP-countries share the same international country code: `1`.
Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
# Instructions
22

3-
Translate RNA sequences into proteins.
3+
Your job is to translate RNA sequences into proteins.
44

5-
RNA can be broken into three-nucleotide sequences called codons, and then translated to a protein like so:
5+
RNA strands are made up of three-nucleotide sequences called **codons**.
6+
Each codon translates to an **amino acid**.
7+
When joined together, those amino acids make a protein.
68

7-
RNA: `"AUGUUUUCU"` => translates to
8-
9-
Codons: `"AUG", "UUU", "UCU"`
10-
=> which become a protein with the following sequence =>
11-
12-
Protein: `"Methionine", "Phenylalanine", "Serine"`
13-
14-
There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise.
15-
If it works for one codon, the program should work for all of them.
16-
However, feel free to expand the list in the test suite to include them all.
17-
18-
There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated.
19-
20-
All subsequent codons after are ignored, like this:
21-
22-
RNA: `"AUGUUUUCUUAAAUG"` =>
23-
24-
Codons: `"AUG", "UUU", "UCU", "UAA", "AUG"` =>
25-
26-
Protein: `"Methionine", "Phenylalanine", "Serine"`
27-
28-
Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence.
29-
30-
Below are the codons and resulting amino acids needed for the exercise.
9+
In the real world, there are 64 codons, which in turn correspond to 20 amino acids.
10+
However, for this exercise, you’ll only use a few of the possible 64.
11+
They are listed below:
3112

3213
| Codon | Amino Acid |
33-
| :----------------- | :------------ |
14+
| ------------------ | ------------- |
3415
| AUG | Methionine |
3516
| UUU, UUC | Phenylalanine |
3617
| UUA, UUG | Leucine |
@@ -40,6 +21,18 @@ Below are the codons and resulting amino acids needed for the exercise.
4021
| UGG | Tryptophan |
4122
| UAA, UAG, UGA | STOP |
4223

24+
For example, the RNA string “AUGUUUUCU” has three codons: “AUG”, “UUU” and “UCU”.
25+
These map to Methionine, Phenylalanine, and Serine.
26+
27+
## “STOP” Codons
28+
29+
You’ll note from the table above that there are three **“STOP” codons**.
30+
If you encounter any of these codons, ignore the rest of the sequence — the protein is complete.
31+
32+
For example, “AUGUUUUCUUAAAUG” contains a STOP codon (“UAA”).
33+
Once we reach that point, we stop processing.
34+
We therefore only consider the part before it (i.e. “AUGUUUUCU”), not any further codons after it (i.e. “AUG”).
35+
4336
Learn more about [protein translation on Wikipedia][protein-translation].
4437

4538
[protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology)
Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,40 @@
11
# Instructions
22

3-
Implement a simple shift cipher like Caesar and a more secure substitution cipher.
3+
Create an implementation of the [Vigenère cipher][wiki].
4+
The Vigenère cipher is a simple substitution cipher.
45

5-
## Step 1
6+
## Cipher terminology
67

7-
"If he had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out.
8-
If anyone wishes to decipher these, and get at their meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the others."
9-
—Suetonius, Life of Julius Caesar
8+
A cipher is an algorithm used to encrypt, or encode, a string.
9+
The unencrypted string is called the _plaintext_ and the encrypted string is called the _ciphertext_.
10+
Converting plaintext to ciphertext is called _encoding_ while the reverse is called _decoding_.
1011

11-
Ciphers are very straight-forward algorithms that allow us to render text less readable while still allowing easy deciphering.
12-
They are vulnerable to many forms of cryptanalysis, but Caesar was lucky that his enemies were not cryptanalysts.
12+
In a _substitution cipher_, each plaintext letter is replaced with a ciphertext letter which is computed with the help of a _key_.
13+
(Note, it is possible for replacement letter to be the same as the original letter.)
1314

14-
The Caesar cipher was used for some messages from Julius Caesar that were sent afield.
15-
Now Caesar knew that the cipher wasn't very good, but he had one ally in that respect: almost nobody could read well.
16-
So even being a couple letters off was sufficient so that people couldn't recognize the few words that they did know.
15+
## Encoding details
1716

18-
Your task is to create a simple shift cipher like the Caesar cipher.
19-
This image is a great example of the Caesar cipher:
17+
In this cipher, the key is a series of lowercase letters, such as `"abcd"`.
18+
Each letter of the plaintext is _shifted_ or _rotated_ by a distance based on a corresponding letter in the key.
19+
An `"a"` in the key means a shift of 0 (that is, no shift).
20+
A `"b"` in the key means a shift of 1.
21+
A `"c"` in the key means a shift of 2, and so on.
2022

21-
![Caesar cipher][img-caesar-cipher]
23+
The first letter of the plaintext uses the first letter of the key, the second letter of the plaintext uses the second letter of the key and so on.
24+
If you run out of letters in the key before you run out of letters in the plaintext, start over from the start of the key again.
2225

23-
For example:
26+
If the key only contains one letter, such as `"dddddd"`, then all letters of the plaintext are shifted by the same amount (three in this example), which would make this the same as a rotational cipher or shift cipher (sometimes called a Caesar cipher).
27+
For example, the plaintext `"iamapandabear"` would become `"ldpdsdqgdehdu"`.
2428

25-
Giving "iamapandabear" as input to the encode function returns the cipher "ldpdsdqgdehdu".
26-
Obscure enough to keep our message secret in transit.
29+
If the key only contains the letter `"a"` (one or more times), the shift distance is zero and the ciphertext is the same as the plaintext.
2730

28-
When "ldpdsdqgdehdu" is put into the decode function it would return the original "iamapandabear" letting your friend read your original message.
31+
Usually the key is more complicated than that, though!
32+
If the key is `"abcd"` then letters of the plaintext would be shifted by a distance of 0, 1, 2, and 3.
33+
If the plaintext is `"hello"`, we need 5 shifts so the key would wrap around, giving shift distances of 0, 1, 2, 3, and 0.
34+
Applying those shifts to the letters of `"hello"` we get `"hfnoo"`.
2935

30-
## Step 2
36+
## Random keys
3137

32-
Shift ciphers quickly cease to be useful when the opposition commander figures them out.
33-
So instead, let's try using a substitution cipher.
34-
Try amending the code to allow us to specify a key and use that for the shift distance.
38+
If no key is provided, generate a key which consists of at least 100 random lowercase letters from the Latin alphabet.
3539

36-
Here's an example:
37-
38-
Given the key "aaaaaaaaaaaaaaaaaa", encoding the string "iamapandabear"
39-
would return the original "iamapandabear".
40-
41-
Given the key "ddddddddddddddddd", encoding our string "iamapandabear"
42-
would return the obscured "ldpdsdqgdehdu"
43-
44-
In the example above, we've set a = 0 for the key value.
45-
So when the plaintext is added to the key, we end up with the same message coming out.
46-
So "aaaa" is not an ideal key.
47-
But if we set the key to "dddd", we would get the same thing as the Caesar cipher.
48-
49-
## Step 3
50-
51-
The weakest link in any cipher is the human being.
52-
Let's make your substitution cipher a little more fault tolerant by providing a source of randomness and ensuring that the key contains only lowercase letters.
53-
54-
If someone doesn't submit a key at all, generate a truly random key of at least 100 lowercase characters in length.
55-
56-
## Extensions
57-
58-
Shift ciphers work by making the text slightly odd, but are vulnerable to frequency analysis.
59-
Substitution ciphers help that, but are still very vulnerable when the key is short or if spaces are preserved.
60-
Later on you'll see one solution to this problem in the exercise "crypto-square".
61-
62-
If you want to go farther in this field, the questions begin to be about how we can exchange keys in a secure way.
63-
Take a look at [Diffie-Hellman on Wikipedia][dh] for one of the first implementations of this scheme.
64-
65-
[img-caesar-cipher]: https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Caesar_cipher_left_shift_of_3.svg/320px-Caesar_cipher_left_shift_of_3.svg.png
66-
[dh]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
40+
[wiki]: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher

exercises/practice/simple-cipher/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
".meta/example.rs"
3030
]
3131
},
32-
"blurb": "Implement a simple shift cipher like Caesar and a more secure substitution cipher.",
32+
"blurb": "Implement the Vigenère cipher, a simple substitution cipher.",
3333
"source": "Substitution Cipher at Wikipedia",
3434
"source_url": "https://en.wikipedia.org/wiki/Substitution_cipher"
3535
}

0 commit comments

Comments
 (0)