Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync: update docs #732

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions exercises/practice/anagram/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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"`.
28 changes: 1 addition & 27 deletions exercises/practice/collatz-conjecture/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
# Instructions

The Collatz Conjecture or 3x+1 problem can be summarized as follows:

Take any positive integer n.
If n is even, divide n by 2 to get n / 2.
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
Repeat the process indefinitely.
The conjecture states that no matter which number you start with, you will always reach 1 eventually.

Given a number n, return the number of steps required to reach 1.

## Examples

Starting with n = 12, the steps would be as follows:

0. 12
1. 6
2. 3
3. 10
4. 5
5. 16
6. 8
7. 4
8. 2
9. 1

Resulting in 9 steps.
So for input n = 12, the return value would be 9.
Given a positive integer, return the number of steps it takes to reach 1 according to the rules of the Collatz Conjecture.
28 changes: 28 additions & 0 deletions exercises/practice/collatz-conjecture/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Introduction

One evening, you stumbled upon an old notebook filled with cryptic scribbles, as though someone had been obsessively chasing an idea.
On one page, a single question stood out: **Can every number find its way to 1?**
It was tied to something called the **Collatz Conjecture**, a puzzle that has baffled thinkers for decades.

The rules were deceptively simple.
Pick any positive integer.

- If it's even, divide it by 2.
- If it's odd, multiply it by 3 and add 1.

Then, repeat these steps with the result, continuing indefinitely.

Curious, you picked number 12 to test and began the journey:

12 ➜ 6 ➜ 3 ➜ 10 ➜ 5 ➜ 16 ➜ 8 ➜ 4 ➜ 2 ➜ 1

Counting from the second number (6), it took 9 steps to reach 1, and each time the rules repeated, the number kept changing.
At first, the sequence seemed unpredictable — jumping up, down, and all over.
Yet, the conjecture claims that no matter the starting number, we'll always end at 1.

It was fascinating, but also puzzling.
Why does this always seem to work?
Could there be a number where the process breaks down, looping forever or escaping into infinity?
The notebook suggested solving this could reveal something profound — and with it, fame, [fortune][collatz-prize], and a place in history awaits whoever could unlock its secrets.

[collatz-prize]: https://mathprize.net/posts/collatz-conjecture/
4 changes: 2 additions & 2 deletions exercises/practice/collatz-conjecture/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
]
},
"blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture.",
"source": "An unsolved problem in mathematics named after mathematician Lothar Collatz",
"source_url": "https://en.wikipedia.org/wiki/3x_%2B_1_problem"
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Collatz_conjecture"
}
14 changes: 5 additions & 9 deletions exercises/practice/grains/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions exercises/practice/grains/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion exercises/practice/grains/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,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"
}
2 changes: 1 addition & 1 deletion exercises/practice/leap/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,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"
}
8 changes: 3 additions & 5 deletions exercises/practice/luhn/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Instructions

Given a number determine whether or not it is valid per the Luhn formula.
Determine whether a credit card number is valid according to the [Luhn formula][luhn].

The [Luhn algorithm][luhn] is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers.
The number will be provided as a string.

The task is to check if a given string is valid.

## Validating a Number
## Validating a number

Strings of length 1 or less are not valid.
Spaces are allowed in the input, but they should be stripped before checking.
Expand Down
11 changes: 11 additions & 0 deletions exercises/practice/luhn/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Introduction

At the Global Verification Authority, you've just been entrusted with a critical assignment.
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.
The Luhn algorithm is a simple checksum formula used to ensure these numbers are valid and error-free.

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

Can you ensure this is done right? The integrity of many services depends on you.
2 changes: 1 addition & 1 deletion exercises/practice/pascals-triangle/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Over the next hour, your teacher reveals some amazing things hidden in this tria
- It contains the Fibonacci sequence.
- If you color odd and even numbers differently, you get a beautiful pattern called the [Sierpiński triangle][wikipedia-sierpinski-triangle].

The teacher implores you and your classmates to lookup other uses, and assures you that there are lots more!
The teacher implores you and your classmates to look up other uses, and assures you that there are lots more!
At that moment, the school bell rings.
You realize that for the past hour, you were completely absorbed in learning about Pascal's triangle.
You quickly grab your laptop from your bag and go outside, ready to enjoy both the sunshine _and_ the wonders of Pascal's triangle.
Expand Down
12 changes: 12 additions & 0 deletions exercises/practice/phone-number/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Introduction

You've joined LinkLine, a leading communications company working to ensure reliable connections for everyone.
The team faces a big challenge: users submit phone numbers in all sorts of formats — dashes, spaces, dots, parentheses, and even prefixes.
Some numbers are valid, while others are impossible to use.

Your mission is to turn this chaos into order.
You'll clean up valid numbers, formatting them appropriately for use in the system.
At the same time, you'll identify and filter out any invalid entries.

The success of LinkLine's operations depends on your ability to separate the useful from the unusable.
Are you ready to take on the challenge and keep the connections running smoothly?
2 changes: 1 addition & 1 deletion exercises/practice/rna-transcription/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
".meta/src/RnaTranscription.example.elm"
]
},
"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"
}
2 changes: 1 addition & 1 deletion exercises/practice/say/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,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"
}
75 changes: 67 additions & 8 deletions exercises/practice/sieve/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 5 additions & 5 deletions exercises/practice/simple-cipher/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand Down