You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/practice/rotational-cipher/.approaches/ascii-values/content.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,14 +22,14 @@ It uses numbers to represent 128 different entities including carriage returns,
22
22
In ascii, all the lowercase English letters appear between 97 and 123.
23
23
While the uppercase letters are in the range between 65 and 91.
24
24
25
-
```exercism/caution
25
+
~~~~exercism/caution
26
26
27
27
This approach only supports the English alphabet.
28
28
Non-English alphabets are not contiguous in their ascii number ranges, and are not consistently defined across platforms.
29
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.
30
30
This means that a shift for an extended ascii word containing **å** won't result in an accurate alphabet position for a Scandinavian language.
31
31
32
-
```
32
+
~~~~
33
33
34
34
The approach starts with defining the function `rotate()`, with a variable `result` is assigned to an empty string.
35
35
The elements of the text argument are then iterated over using a [`for loop`][for-loop].
@@ -40,7 +40,7 @@ Unicode's first 128 code points have the same numbers as their ascii counterpart
40
40
41
41
If the element is an uppercase letter, [`ord`][ord] is used to convert the letter to an integer.
42
42
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 2_) 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.
44
44
45
45
This is because we want to know which letter of the alphabet the number will become.
46
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.
Copy file name to clipboardExpand all lines: exercises/practice/rotational-cipher/.approaches/introduction.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,14 @@ This approach is straightforward to understand.
14
14
It uses the ascii value of the letters to rotate them within the message.
15
15
The numbers 65-91 in the ascii range represent lowercase Latin letters, while 97-123 represent uppercase Latin letters.
16
16
17
-
```exercism/caution
17
+
~~~~exercism/caution
18
18
19
19
This approach only supports the English alphabet.
20
20
Non-English alphabets are not contiguous in their ascii number ranges, and are not consistently defined across platforms.
21
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
22
This means that a shift for an extended ascii word containing **å** won't result in an accurate alphabet position for a Scandinavian language.
23
23
24
-
```
24
+
~~~~
25
25
26
26
```python
27
27
defrotate(text, key):
@@ -73,9 +73,9 @@ For more information, check the [Alphabet approach][approach-alphabet].
73
73
This approach uses the [`str.translate`][str-translate] method to create a mapping from input to shifted string instead of using the index of an alphabet string to calculate the shift.
74
74
The benefit of this approach is that it has no visible loop, making the code more concise.
75
75
76
-
```exercism/note
76
+
~~~~exercism/note
77
77
`str.translate` **still loops over the `string`** even if it is not visibly doing so.
78
-
```
78
+
~~~~
79
79
80
80
```python
81
81
AlPHABET ="abcdefghijklmnopqrstuvwxyz
@@ -93,10 +93,10 @@ This approach uses a recursive function.
93
93
A recursive function is a function that calls itself.
94
94
This approach can be more concise than other approaches, and may also be more readable for some audiences.
95
95
96
-
```exercism/caution
96
+
~~~~exercism/caution
97
97
Python does not have any tail-call optimization and has a default [recursion limit][recursion-limit] of 1000 calls on the stack.
98
98
Calculate your base case carefully to avoid errors.
0 commit comments