From b5526b62ccef3524bd630c9d1c8c95c169493864 Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Wed, 26 Feb 2025 15:05:33 +0100 Subject: [PATCH 01/10] Update introduction.md Removed "studentScores", which seems to be there by mistake. --- .../international-calling-connoisseur/.docs/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/international-calling-connoisseur/.docs/introduction.md b/exercises/concept/international-calling-connoisseur/.docs/introduction.md index a9d963a1a..fa8bed1e4 100644 --- a/exercises/concept/international-calling-connoisseur/.docs/introduction.md +++ b/exercises/concept/international-calling-connoisseur/.docs/introduction.md @@ -56,7 +56,7 @@ The [size][map-size-javadoc] method returns the number of entries. fruitPrices.size(); // Returns 2 ``` -You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively.studentScores +You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java fruitPrices.keys(); // Returns "apple" and "pear" in a set From 11a750b8172a68529c308718c6e636c598a09e86 Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 20:08:36 +0100 Subject: [PATCH 02/10] Update exercises/concept/international-calling-connoisseur/.docs/introduction.md Co-authored-by: Kah Goh --- .../international-calling-connoisseur/.docs/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/international-calling-connoisseur/.docs/introduction.md b/exercises/concept/international-calling-connoisseur/.docs/introduction.md index fa8bed1e4..3670b6e0b 100644 --- a/exercises/concept/international-calling-connoisseur/.docs/introduction.md +++ b/exercises/concept/international-calling-connoisseur/.docs/introduction.md @@ -59,7 +59,7 @@ fruitPrices.size(); // Returns 2 You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java -fruitPrices.keys(); // Returns "apple" and "pear" in a set +fruitPrices.keySet(); // Returns "apple" and "pear" in a set fruitPrices.values(); // Returns 100 and 80, in a Collection ``` From 9ea15318ed8d80df11ead3a14d7ada2476c786e6 Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 20:10:01 +0100 Subject: [PATCH 03/10] Update exercises/concept/international-calling-connoisseur/.docs/introduction.md Co-authored-by: Kah Goh --- .../international-calling-connoisseur/.docs/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/international-calling-connoisseur/.docs/introduction.md b/exercises/concept/international-calling-connoisseur/.docs/introduction.md index 3670b6e0b..ad2856d12 100644 --- a/exercises/concept/international-calling-connoisseur/.docs/introduction.md +++ b/exercises/concept/international-calling-connoisseur/.docs/introduction.md @@ -56,7 +56,7 @@ The [size][map-size-javadoc] method returns the number of entries. fruitPrices.size(); // Returns 2 ``` -You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively. +You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java fruitPrices.keySet(); // Returns "apple" and "pear" in a set From a5a57f715da42bd3b5c58dc443e2c2ca251debb3 Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 20:22:18 +0100 Subject: [PATCH 04/10] Update introduction.md Added links to the bottom of the file --- .../international-calling-connoisseur/.docs/introduction.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises/concept/international-calling-connoisseur/.docs/introduction.md b/exercises/concept/international-calling-connoisseur/.docs/introduction.md index ad2856d12..562c5465a 100644 --- a/exercises/concept/international-calling-connoisseur/.docs/introduction.md +++ b/exercises/concept/international-calling-connoisseur/.docs/introduction.md @@ -70,3 +70,5 @@ fruitPrices.values(); // Returns 100 and 80, in a Collection [map-containskey-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#containsKey(java.lang.Object) [map-remove-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#remove(java.lang.Object) [map-size-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#size() +[map-keyset-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#keySet() +[map-values-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#values() From 68029e21c4b8f1be886092514cb5dbb64e5e8f64 Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 22:26:04 +0100 Subject: [PATCH 05/10] Update java/concepts/maps/introduction.md Fixed typos, added links for Map keySet and values --- concepts/maps/introduction.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/concepts/maps/introduction.md b/concepts/maps/introduction.md index aba6d4f4a..908506b73 100644 --- a/concepts/maps/introduction.md +++ b/concepts/maps/introduction.md @@ -37,15 +37,15 @@ fruitPrices.get("apple"); // => 100 Use [containsKey][map-containskey-javadoc] to see if the map contains a particular key. ```java -fruitPrices.containsKey("apple"); // => true +fruitPrices.containsKey("apple"); // => true fruitPrices.containsKey("orange"); // => false ``` Remove entries with [remove][map-remove-javadoc]. ```java -fruitPrices.put("plum", 90); // Add plum to map -fruitPrices.remove("plum"); // Removes plum from map +fruitPrices.put("plum", 90); // Add plum to map +fruitPrices.remove("plum"); // Removes plum from map ``` The [size][map-size-javadoc] method returns the number of entries. @@ -54,10 +54,10 @@ The [size][map-size-javadoc] method returns the number of entries. fruitPrices.size(); // Returns 2 ``` -You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively.studentScores +You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively.studentScores ```java -fruitPrices.keys(); // Returns "apple" and "pear" in a set +fruitPrices.keySet(); // Returns "apple" and "pear" in a set fruitPrices.values(); // Returns 100 and 80, in a Collection ``` @@ -68,3 +68,5 @@ fruitPrices.values(); // Returns 100 and 80, in a Collection [map-containskey-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#containsKey(java.lang.Object) [map-remove-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#remove(java.lang.Object) [map-size-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#size() +[map-keyset-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#keySet() +[map-values-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#values() From 84e5f4d8b444f164b194e9c0e83f5b8350d3447b Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 22:35:21 +0100 Subject: [PATCH 06/10] Update introduction.md Aligned spaces --- .../.docs/introduction.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/concept/international-calling-connoisseur/.docs/introduction.md b/exercises/concept/international-calling-connoisseur/.docs/introduction.md index 562c5465a..c407eea39 100644 --- a/exercises/concept/international-calling-connoisseur/.docs/introduction.md +++ b/exercises/concept/international-calling-connoisseur/.docs/introduction.md @@ -39,15 +39,15 @@ fruitPrices.get("apple"); // => 100 Use [containsKey][map-containskey-javadoc] to see if the map contains a particular key. ```java -fruitPrices.containsKey("apple"); // => true -fruitPrices.containsKey("orange"); // => false +fruitPrices.containsKey("apple"); // => true +fruitPrices.containsKey("orange"); // => false ``` Remove entries with [remove][map-remove-javadoc]. ```java -fruitPrices.put("plum", 90); // Add plum to map -fruitPrices.remove("plum"); // Removes plum from map +fruitPrices.put("plum", 90); // Add plum to map +fruitPrices.remove("plum"); // Removes plum from map ``` The [size][map-size-javadoc] method returns the number of entries. @@ -59,7 +59,7 @@ fruitPrices.size(); // Returns 2 You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java -fruitPrices.keySet(); // Returns "apple" and "pear" in a set +fruitPrices.keySet(); // Returns "apple" and "pear" in a set fruitPrices.values(); // Returns 100 and 80, in a Collection ``` From 29045425e432075bab8602a1652b36991b7a0fd6 Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 22:37:27 +0100 Subject: [PATCH 07/10] Update about.md Fixes typos, added links, aligned spacing --- concepts/maps/about.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/concepts/maps/about.md b/concepts/maps/about.md index 142db1139..5acec7c87 100644 --- a/concepts/maps/about.md +++ b/concepts/maps/about.md @@ -51,7 +51,7 @@ fruitPrices.get("apple"); // => 100 Use [containsKey][map-containskey-javadoc] to see if the map contains a particular key. ```java -fruitPrices.containsKey("apple"); // => true +fruitPrices.containsKey("apple"); // => true fruitPrices.containsKey("orange"); // => false ``` @@ -68,10 +68,10 @@ The [size][map-size-javadoc] method returns the number of entries. fruitPrices.size(); // Returns 2 ``` -You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively. +You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java -fruitPrices.keys(); // Returns "apple" and "pear" in a set +fruitPrices.keySet(); // Returns "apple" and "pear" in a set fruitPrices.values(); // Returns 100 and 80, in a Collection ``` @@ -169,3 +169,5 @@ Calling methods like `put`, `remove` or `clear` results in an `UnsupportedOperat [map-copyof-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#copyOf(java.util.Map) [object-hashcode-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#hashCode() [object-equals-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object) +[map-keyset-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#keySet() +[map-values-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#values() From 0eab6ba3498e0fbb19059322c1ebe8b82cc6ac3f Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Thu, 27 Feb 2025 22:48:36 +0100 Subject: [PATCH 08/10] Update about.md Fixed typos, added links for maps keySet and values, aligned spacing --- concepts/maps/about.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/concepts/maps/about.md b/concepts/maps/about.md index 142db1139..86a820cf1 100644 --- a/concepts/maps/about.md +++ b/concepts/maps/about.md @@ -51,15 +51,15 @@ fruitPrices.get("apple"); // => 100 Use [containsKey][map-containskey-javadoc] to see if the map contains a particular key. ```java -fruitPrices.containsKey("apple"); // => true +fruitPrices.containsKey("apple"); // => true fruitPrices.containsKey("orange"); // => false ``` Remove entries with [remove][map-remove-javadoc]. ```java -fruitPrices.put("plum", 90); // Add plum to map -fruitPrices.remove("plum"); // Removes plum from map +fruitPrices.put("plum", 90); // Add plum to map +fruitPrices.remove("plum"); // Removes plum from map ``` The [size][map-size-javadoc] method returns the number of entries. @@ -68,10 +68,10 @@ The [size][map-size-javadoc] method returns the number of entries. fruitPrices.size(); // Returns 2 ``` -You can use the [keys] or [values] methods to obtain the keys or the values in a Map as a Set or collection respectively. +You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java -fruitPrices.keys(); // Returns "apple" and "pear" in a set +fruitPrices.keySet(); // Returns "apple" and "pear" in a set fruitPrices.values(); // Returns 100 and 80, in a Collection ``` @@ -169,3 +169,5 @@ Calling methods like `put`, `remove` or `clear` results in an `UnsupportedOperat [map-copyof-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#copyOf(java.util.Map) [object-hashcode-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#hashCode() [object-equals-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object) +[map-keyset-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#keySet() +[map-values-javadoc]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#values() From ab5ee2db427227a0735d28008d54d4314e6c7adc Mon Sep 17 00:00:00 2001 From: Kadri Samuel Date: Fri, 28 Feb 2025 23:52:59 +0100 Subject: [PATCH 09/10] Update concepts/maps/introduction.md removing "studentScores" Co-authored-by: Kah Goh --- concepts/maps/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/concepts/maps/introduction.md b/concepts/maps/introduction.md index 908506b73..60bfbe7e3 100644 --- a/concepts/maps/introduction.md +++ b/concepts/maps/introduction.md @@ -54,7 +54,7 @@ The [size][map-size-javadoc] method returns the number of entries. fruitPrices.size(); // Returns 2 ``` -You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively.studentScores +You can use the [keySet][map-keyset-javadoc] or [values][map-values-javadoc] methods to obtain the keys or the values in a Map as a Set or collection respectively. ```java fruitPrices.keySet(); // Returns "apple" and "pear" in a set From c5101688bb384576ee6e09954462576903e55ce1 Mon Sep 17 00:00:00 2001 From: jagdish-15 Date: Sat, 1 Mar 2025 19:07:41 +0530 Subject: [PATCH 10/10] Sync repo with problem-specifications (#2920) --- .../.meta/config.json | 3 + .../affine-cipher/.docs/instructions.md | 2 +- .../practice/anagram/.docs/instructions.md | 11 ++- .../practice/grains/.docs/instructions.md | 14 ++-- .../practice/grains/.docs/introduction.md | 6 ++ exercises/practice/grains/.meta/config.json | 2 +- exercises/practice/leap/.meta/config.json | 2 +- .../rna-transcription/.meta/config.json | 2 +- exercises/practice/say/.meta/config.json | 2 +- .../practice/sieve/.docs/instructions.md | 75 +++++++++++++++++-- .../simple-cipher/.docs/instructions.md | 10 +-- 11 files changed, 96 insertions(+), 33 deletions(-) create mode 100644 exercises/practice/grains/.docs/introduction.md diff --git a/exercises/concept/international-calling-connoisseur/.meta/config.json b/exercises/concept/international-calling-connoisseur/.meta/config.json index 45d387012..e65e319f0 100644 --- a/exercises/concept/international-calling-connoisseur/.meta/config.json +++ b/exercises/concept/international-calling-connoisseur/.meta/config.json @@ -11,6 +11,9 @@ ], "exemplar": [ ".meta/src/reference/java/DialingCodes.java" + ], + "invalidator": [ + "build.gradle" ] }, "blurb": "Learn about maps while managing international calling codes." diff --git a/exercises/practice/affine-cipher/.docs/instructions.md b/exercises/practice/affine-cipher/.docs/instructions.md index f6329db93..1603dbbce 100644 --- a/exercises/practice/affine-cipher/.docs/instructions.md +++ b/exercises/practice/affine-cipher/.docs/instructions.md @@ -20,7 +20,7 @@ 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`. + For the Latin alphabet `m` is `26`. - `a` and `b` are integers which make up 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]). diff --git a/exercises/practice/anagram/.docs/instructions.md b/exercises/practice/anagram/.docs/instructions.md index a7298485b..dca24f526 100644 --- a/exercises/practice/anagram/.docs/instructions.md +++ b/exercises/practice/anagram/.docs/instructions.md @@ -1,13 +1,12 @@ # Instructions -Your task is to, given a target word and a set of candidate words, to find the subset of the candidates that are anagrams of the target. +Given a target word and one or more candidate words, your task is to find the candidates that are anagrams of the target. 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"`. -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. +The target word and candidate words are made up 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 words you need to find should be taken from the candidate words, using the same letter case. -Given the target `"stone"` and candidates `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, `"Seton"`, the anagram set is `"tones"`, `"notes"`, `"Seton"`. +Given the target `"stone"` and the candidate words `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, and `"Seton"`, the anagram words you need to find are `"tones"`, `"notes"`, and `"Seton"`. diff --git a/exercises/practice/grains/.docs/instructions.md b/exercises/practice/grains/.docs/instructions.md index df479fc0a..f5b752a81 100644 --- a/exercises/practice/grains/.docs/instructions.md +++ b/exercises/practice/grains/.docs/instructions.md @@ -1,15 +1,11 @@ # Instructions -Calculate the number of grains of wheat on a chessboard given that the number on each square doubles. +Calculate the number of grains of wheat on a chessboard. -There once was a wise servant who saved the life of a prince. -The king promised to pay whatever the servant could dream up. -Knowing that the king loved chess, the servant told the king he would like to have grains of wheat. -One grain on the first square of a chess board, with the number of grains doubling on each successive square. +A chessboard has 64 squares. +Square 1 has one grain, square 2 has two grains, square 3 has four grains, and so on, doubling each time. -There are 64 squares on a chessboard (where square 1 has one grain, square 2 has two grains, and so on). +Write code that calculates: -Write code that shows: - -- how many grains were on a given square, and +- the number of grains on a given square - the total number of grains on the chessboard diff --git a/exercises/practice/grains/.docs/introduction.md b/exercises/practice/grains/.docs/introduction.md new file mode 100644 index 000000000..0df4f46f7 --- /dev/null +++ b/exercises/practice/grains/.docs/introduction.md @@ -0,0 +1,6 @@ +# Introduction + +There once was a wise servant who saved the life of a prince. +The king promised to pay whatever the servant could dream up. +Knowing that the king loved chess, the servant told the king he would like to have grains of wheat. +One grain on the first square of a chessboard, with the number of grains doubling on each successive square. diff --git a/exercises/practice/grains/.meta/config.json b/exercises/practice/grains/.meta/config.json index 611ddb233..671ae4999 100644 --- a/exercises/practice/grains/.meta/config.json +++ b/exercises/practice/grains/.meta/config.json @@ -26,5 +26,5 @@ }, "blurb": "Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.", "source": "The CodeRanch Cattle Drive, Assignment 6", - "source_url": "https://coderanch.com/wiki/718824/Grains" + "source_url": "https://web.archive.org/web/20240908084142/https://coderanch.com/wiki/718824/Grains" } diff --git a/exercises/practice/leap/.meta/config.json b/exercises/practice/leap/.meta/config.json index 234e5a6b5..25541b165 100644 --- a/exercises/practice/leap/.meta/config.json +++ b/exercises/practice/leap/.meta/config.json @@ -25,5 +25,5 @@ }, "blurb": "Determine whether a given year is a leap year.", "source": "CodeRanch Cattle Drive, Assignment 3", - "source_url": "https://coderanch.com/t/718816/Leap" + "source_url": "https://web.archive.org/web/20240907033714/https://coderanch.com/t/718816/Leap" } diff --git a/exercises/practice/rna-transcription/.meta/config.json b/exercises/practice/rna-transcription/.meta/config.json index 3b7e9fecf..f750ce6a6 100644 --- a/exercises/practice/rna-transcription/.meta/config.json +++ b/exercises/practice/rna-transcription/.meta/config.json @@ -38,7 +38,7 @@ "build.gradle" ] }, - "blurb": "Given a DNA strand, return its RNA Complement Transcription.", + "blurb": "Given a DNA strand, return its RNA complement.", "source": "Hyperphysics", "source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html" } diff --git a/exercises/practice/say/.meta/config.json b/exercises/practice/say/.meta/config.json index 4ffa776c6..8df32cdda 100644 --- a/exercises/practice/say/.meta/config.json +++ b/exercises/practice/say/.meta/config.json @@ -21,5 +21,5 @@ }, "blurb": "Given a number from 0 to 999,999,999,999, spell out that number in English.", "source": "A variation on the JavaRanch CattleDrive, Assignment 4", - "source_url": "https://coderanch.com/wiki/718804" + "source_url": "https://web.archive.org/web/20240907035912/https://coderanch.com/wiki/718804" } diff --git a/exercises/practice/sieve/.docs/instructions.md b/exercises/practice/sieve/.docs/instructions.md index 085c0a57d..71292e178 100644 --- a/exercises/practice/sieve/.docs/instructions.md +++ b/exercises/practice/sieve/.docs/instructions.md @@ -6,37 +6,96 @@ A prime number is a number larger than 1 that is only divisible by 1 and itself. For example, 2, 3, 5, 7, 11, and 13 are prime numbers. By contrast, 6 is _not_ a prime number as it not only divisible by 1 and itself, but also by 2 and 3. -To use the Sieve of Eratosthenes, you first create a list of all the numbers between 2 and your given number. -Then you repeat the following steps: +To use the Sieve of Eratosthenes, first, write out all the numbers from 2 up to and including your given number. +Then, follow these steps: -1. Find the next unmarked number in your list (skipping over marked numbers). +1. Find the next unmarked number (skipping over marked numbers). This is a prime number. 2. Mark all the multiples of that prime number as **not** prime. -You keep repeating these steps until you've gone through every number in your list. +Repeat the steps until you've gone through every number. At the end, all the unmarked numbers are prime. ~~~~exercism/note -The tests don't check that you've implemented the algorithm, only that you've come up with the correct list of primes. -To check you are implementing the Sieve correctly, a good first test is to check that you do not use division or remainder operations. +The Sieve of Eratosthenes marks off multiples of each prime using addition (repeatedly adding the prime) or multiplication (directly computing its multiples), rather than checking each number for divisibility. + +The tests don't check that you've implemented the algorithm, only that you've come up with the correct primes. ~~~~ ## Example Let's say you're finding the primes less than or equal to 10. -- List out 2, 3, 4, 5, 6, 7, 8, 9, 10, leaving them all unmarked. +- Write out 2, 3, 4, 5, 6, 7, 8, 9, 10, leaving them all unmarked. + + ```text + 2 3 4 5 6 7 8 9 10 + ``` + - 2 is unmarked and is therefore a prime. Mark 4, 6, 8 and 10 as "not prime". + + ```text + 2 3 [4] 5 [6] 7 [8] 9 [10] + ↑ + ``` + - 3 is unmarked and is therefore a prime. Mark 6 and 9 as not prime _(marking 6 is optional - as it's already been marked)_. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 4 is marked as "not prime", so we skip over it. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 5 is unmarked and is therefore a prime. Mark 10 as not prime _(optional - as it's already been marked)_. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 6 is marked as "not prime", so we skip over it. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 7 is unmarked and is therefore a prime. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 8 is marked as "not prime", so we skip over it. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 9 is marked as "not prime", so we skip over it. + + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + - 10 is marked as "not prime", so we stop as there are no more numbers to check. -You've examined all numbers and found 2, 3, 5, and 7 are still unmarked, which means they're the primes less than or equal to 10. + ```text + 2 3 [4] 5 [6] 7 [8] [9] [10] + ↑ + ``` + +You've examined all the numbers and found that 2, 3, 5, and 7 are still unmarked, meaning they're the primes less than or equal to 10. diff --git a/exercises/practice/simple-cipher/.docs/instructions.md b/exercises/practice/simple-cipher/.docs/instructions.md index 475af6182..337857442 100644 --- a/exercises/practice/simple-cipher/.docs/instructions.md +++ b/exercises/practice/simple-cipher/.docs/instructions.md @@ -11,14 +11,14 @@ If anyone wishes to decipher these, and get at their meaning, he must substitute Ciphers are very straight-forward algorithms that allow us to render text less readable while still allowing easy deciphering. They are vulnerable to many forms of cryptanalysis, but Caesar was lucky that his enemies were not cryptanalysts. -The Caesar Cipher was used for some messages from Julius Caesar that were sent afield. +The Caesar cipher was used for some messages from Julius Caesar that were sent afield. Now Caesar knew that the cipher wasn't very good, but he had one ally in that respect: almost nobody could read well. So even being a couple letters off was sufficient so that people couldn't recognize the few words that they did know. -Your task is to create a simple shift cipher like the Caesar Cipher. -This image is a great example of the Caesar Cipher: +Your task is to create a simple shift cipher like the Caesar cipher. +This image is a great example of the Caesar cipher: -![Caesar Cipher][img-caesar-cipher] +![Caesar cipher][img-caesar-cipher] For example: @@ -44,7 +44,7 @@ would return the obscured "ldpdsdqgdehdu" In the example above, we've set a = 0 for the key value. So when the plaintext is added to the key, we end up with the same message coming out. So "aaaa" is not an ideal key. -But if we set the key to "dddd", we would get the same thing as the Caesar Cipher. +But if we set the key to "dddd", we would get the same thing as the Caesar cipher. ## Step 3