Skip to content

Commit 0e06b14

Browse files
committed
Msc link, punctuation, and formatting fixes.
1 parent e73b418 commit 0e06b14

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

exercises/practice/rotational-cipher/.approaches/alphabet/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The function `rotate()` is then declared, and a variable `result` is defined as
2222
The text argument is then iterated over via a [`for loop`][for-loop].
2323
Each element is checked to make sure it is a letter, and subsequently checked if it is uppercase or lowercase.
2424
Uppercase letters are converted to lowercase.
25-
Then index of each letter is found in the `AlPHABET` constant.
25+
Then the index of each letter is found in the `AlPHABET` constant.
2626
The numeric key value is added to the letter index and [modulo (`%`)][modulo] 26 is used on the result.
2727
Finally, the new number is used as an index into the `AlPHABET` constant, and the resulting letter is converted back to uppercase.
2828

exercises/practice/rotational-cipher/.approaches/ascii-values/content.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ While the uppercase letters are in the range between 65 and 91.
2626
2727
This approach only supports the English alphabet.
2828
Non-English alphabets are not contiguous in their ascii number ranges, and are not consistently defined across platforms.
29-
For example, the Scandinavian letter: **å** has the extended ascii value of 132, but is used in combination with Latin characters that appear in the 65-91 and 97-123 ranges.
29+
For example, the Scandinavian letter **å** has the extended ascii value of **134**, but is used in combination with Latin-1 characters that appear in the 65-91 and 97-123 ranges.
3030
This means that a shift for an extended ascii word containing **å** won't result in an accurate alphabet position for a Scandinavian language.
3131
3232
~~~~
3333

3434
The approach starts with defining the function `rotate()`, with a variable `result` is assigned to an empty string.
3535
The elements of the text argument are then iterated over using a [`for loop`][for-loop].
36-
Each element is checked to see if it is a letter, and then is checked if it is an uppercase letter.
36+
Each element is checked to see if it is a letter, and if it is a lower or uppercase letter.
3737

3838
Python has a builtin function called `ord` that converts a [unicode][unicode] symbol to an integer representation.
3939
Unicode's first 128 code points have the same numbers as their ascii counterparts.
4040

4141
If the element is an uppercase letter, [`ord`][ord] is used to convert the letter to an integer.
4242
The integer is added to the numeric key and then 65 is subtracted from the total.
43-
Finally, the result is [modulo (%)][modulo] 26 (_to put the value within the 0-26 range_) and 65 is added back.
43+
Finally, the result is [modulo (%)][modulo] 26 to put the value within the 0-26 range, and 65 is added back.
4444

4545
This is because we want to know which letter of the alphabet the number will become.
46-
And if the new number is over 26 we want to make sure that it "wraps around" to remain in the range of 0-26.
46+
If the new number is over 26 we want to make sure that it "wraps around" to remain in the range of 0-26.
4747
To properly use modulo for a range we have to make sure that it starts at zero, so we subtract 65.
4848
To get back to a letter in the ascii range we add 65 and use the [`chr`][chr] method to convert the value to a letter.
4949

exercises/practice/rotational-cipher/.approaches/introduction.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Introduction
22

3-
There are various ways to solve `rotational-cipher`.
4-
You can for example use [ascii values][ascii], an alphabet `str` or `list`, recursion, or `str.translate`.
3+
There are various ways to solve `Rotational Cipher`.
4+
For example, you can use [ascii values][ascii], an alphabet `str`/`list`, recursion, or `str.translate`.
55

66
## General guidance
77

88
The goal of this exercise is to shift the letters in a string by a given integer key between 0 and 26.
99
The letter in the encrypted string is shifted for as many values (or "positions") as the value of the key.
1010

11+
1112
## Approach: Using ascii values
1213

1314
This approach is straightforward to understand.
@@ -18,11 +19,12 @@ The numbers 65-91 in the ascii range represent lowercase Latin letters, while 97
1819
1920
This approach only supports the English alphabet.
2021
Non-English alphabets are not contiguous in their ascii number ranges, and are not consistently defined across platforms.
21-
For example, the Scandinavian letter: **å** has the extended ascii value of 132, but is used in combination with Latin characters that appear in the 65-91 and 97-123 ranges.
22+
For example, the Scandinavian letter **å** has the extended ascii value of **134**, but is used in combination with Latin-1 characters that appear in the 65-91 and 97-123 ranges.
2223
This means that a shift for an extended ascii word containing **å** won't result in an accurate alphabet position for a Scandinavian language.
2324
2425
~~~~
2526

27+
2628
```python
2729
def rotate(text, key):
2830
result = ""
@@ -37,17 +39,18 @@ def rotate(text, key):
3739
return result
3840
```
3941

40-
For more information, check the [ascii values approach][approach-ascii-values].
42+
For more information, check out the [ascii values approach][approach-ascii-values].
4143

4244
## Approach: Alphabet
4345

44-
This approach is similar to the ascii one, but it uses the index number of each letter in an alphabet string.
46+
This approach is similar to the ascii one, but it uses the index number of each letter in a defined alphabet string.
4547
It requires making a string for all the letters in an alphabet.
4648
And unless two strings are used, you will have to convert individual letters from lower to upper case (or vice-versa).
4749

48-
The big advantage of this approach is the ability to use any alphabet (_although there are some issues with combining characters in Unicode._).
49-
Here, if we want to use the scandinavian letter: **å**, we can simply insert it into our string where we want it:
50-
`abcdefghijklmnopqrstuvwxyzå` and the rotation will work correctly.
50+
The big advantage of this approach is the ability to use _any_ alphabet (_although there are some issues with combining characters in Unicode._).
51+
Here, if we want to use the Scandinavian letter: **å**, we can simply insert it into our string where we want it:
52+
`abcdefghijklmnopqrstuvwxyzå` and the key rotation will work correctly.
53+
5154

5255
```python
5356
# This only uses English characters
@@ -66,7 +69,7 @@ def rotate(text, key):
6669
return result
6770
```
6871

69-
For more information, check the [Alphabet approach][approach-alphabet].
72+
For more information, see the [Alphabet approach][approach-alphabet].
7073

7174
## Approach: Str translate
7275

@@ -77,6 +80,7 @@ The benefit of this approach is that it has no visible loop, making the code mor
7780
`str.translate` **still loops over the `string`** even if it is not visibly doing so.
7881
~~~~
7982

83+
8084
```python
8185
AlPHABET = "abcdefghijklmnopqrstuvwxyz"
8286

@@ -85,7 +89,8 @@ def rotate(text, key):
8589
return text.translate(str.maketrans(AlPHABET + AlPHABET.upper(), translator + translator.upper()))
8690
```
8791

88-
For more information, check the [Str translate approach][approach-str-translate].
92+
For more information, check out the [Str translate approach][approach-str-translate].
93+
8994

9095
## Approach: Recursion
9196

@@ -96,8 +101,11 @@ This approach can be more concise than other approaches, and may also be more re
96101
~~~~exercism/caution
97102
Python does not have any tail-call optimization and has a default [recursion limit][recursion-limit] of 1000 calls on the stack.
98103
Calculate your base case carefully to avoid errors.
104+
105+
[recursion-limit]: https://docs.python.org/3/library/sys.html#sys.setrecursionlimit
99106
~~~~
100107

108+
101109
```python
102110
AlPHABET = "abcdefghijklmnopqrstuvwxyz"
103111

@@ -114,17 +122,17 @@ def rotate(text, key):
114122
return first_letter + rotate(rest, key)
115123
```
116124

117-
For more information, check the [Recursion approach][approach-recursion].
125+
For more information, read the [Recursion approach][approach-recursion].
118126

119127
## Benchmark
120128

121-
For more information, check the [Performance article][article-performance].
129+
For more information on the speed of these various approaches, check out the Rotational Cipher [Performance article][article-performance].
130+
122131

123132
[ascii]: https://en.wikipedia.org/wiki/ASCII
124133
[approach-recursion]: https://exercism.org/tracks/python/exercises/rotational-cipher/approaches/recursion
125134
[approach-str-translate]: https://exercism.org/tracks/python/exercises/rotational-cipher/approaches/str-translate
126135
[approach-ascii-values]: https://exercism.org/tracks/python/exercises/rotational-cipher/approaches/ascii-values
127136
[approach-alphabet]: https://exercism.org/tracks/python/exercises/rotational-cipher/approaches/alphabet
128137
[article-performance]: https://exercism.org/tracks/python/exercises/rotational-cipher/articles/performance
129-
[recursion-limit]: https://docs.python.org/3/library/sys.html#sys.setrecursionlimit
130138
[str-translate]: https://docs.python.org/3/library/stdtypes.html?highlight=str%20translate#str.translate

exercises/practice/rotational-cipher/.approaches/recursion/content.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def rotate(text, key):
1818

1919
This approach uses the same logic as that of the `alphabet` approach, but instead of a `loop`, [concept:python/recursion]() is used to parse the text and solve the problem.
2020

21-
Recursion is a programming technique where a function calls itself.
21+
[Recursion][recursion] is a programming technique where a function calls itself.
2222
It is powerful, but can be more tricky to implement than a `while loop` or `for loop`.
2323
Recursive techniques are more common in functional programming languages like [Elixir][elixir], [Haskell][haskell], and [Clojure][clojure] than they are in Python.
2424

@@ -28,16 +28,18 @@ Then the `rotate` function can execute the same code again with new values.
2828
We can build a long chain or "stack" of `<letter> + rotate(rest)` calls until the `rest` variable is exhausted and the code adds `""`.
2929
That translates to something like this: `<letter> + <letter> + <letter> + <letter> + ""`.
3030

31+
3132
~~~~exercism/note
3233
By default, we can't have a function call itself more than 1000 times.
33-
Code that exceeds this recursion limit will throw a RecursionError.
34-
While it is possible to adjust the recursion limit, doing so risks crashing Python and may also crash your system.
34+
Code that exceeds this recursion limit will throw a [`RecursionError`][recursion-error].
35+
While it is possible to [adjust the recursion limit][recursion-limit], doing so risks crashing Python and may also crash your system.
3536
Casually raising the recursion limit is not recommended.
37+
38+
[recursion-error]: https://docs.python.org/3/library/exceptions.html#RecursionError
39+
[recursion-limit]: https://docs.python.org/3/library/sys.html#sys.setrecursionlimit
3640
~~~~
3741

3842
[clojure]: https://exercism.org/tracks/clojure
3943
[elixir]: https://exercism.org/tracks/elixir
4044
[haskell]: https://exercism.org/tracks/haskell
4145
[recursion]: https://realpython.com/python-thinking-recursively/
42-
[recursion-error]: https://docs.python.org/3/library/exceptions.html#RecursionError
43-
[recursion-limit]: https://docs.python.org/3/library/sys.html#sys.setrecursionlimit

exercises/practice/rotational-cipher/.approaches/str-translate/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def rotate(text, key):
1010

1111
This approach uses the [`<str>.translate`][translate] method.
1212
`translate` takes a translation table as an argument.
13-
To create a translation table we use [str.`makestrans`][maketrans].
13+
To create a translation table we use [`str.makestrans`][maketrans].
1414

1515
This approach starts with defining a constant of all the lowercase letters in the alphabet.
1616
Then the function `rotate()` is declared.

0 commit comments

Comments
 (0)