-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
100 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 1 addition & 27 deletions
28
exercises/practice/collatz-conjecture/.docs/instructions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
exercises/practice/collatz-conjecture/.docs/introduction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
# Instructions | ||
|
||
Given students' names along with the grade that they are in, create a roster for the school. | ||
Given students' names along with the grade they are in, create a roster for the school. | ||
|
||
In the end, you should be able to: | ||
|
||
- Add a student's name to the roster for a grade | ||
- Add a student's name to the roster for a grade: | ||
- "Add Jim to grade 2." | ||
- "OK." | ||
- Get a list of all students enrolled in a grade | ||
- Get a list of all students enrolled in a grade: | ||
- "Which students are in grade 2?" | ||
- "We've only got Jim just now." | ||
- "We've only got Jim right now." | ||
- Get a sorted list of all students in all grades. | ||
Grades should sort as 1, 2, 3, etc., and students within a grade should be sorted alphabetically by name. | ||
- "Who all is enrolled in school right now?" | ||
Grades should be sorted as 1, 2, 3, etc., and students within a grade should be sorted alphabetically by name. | ||
- "Who is enrolled in school right now?" | ||
- "Let me think. | ||
We have Anna, Barb, and Charlie in grade 1, Alex, Peter, and Zoe in grade 2 and Jim in grade 5. | ||
So the answer is: Anna, Barb, Charlie, Alex, Peter, Zoe and Jim" | ||
We have Anna, Barb, and Charlie in grade 1, Alex, Peter, and Zoe in grade 2, and Jim in grade 5. | ||
So the answer is: Anna, Barb, Charlie, Alex, Peter, Zoe, and Jim." | ||
|
||
Note that all our students only have one name (It's a small town, what do you want?) and each student cannot be added more than once to a grade or the roster. | ||
In fact, when a test attempts to add the same student more than once, your implementation should indicate that this is incorrect. | ||
Note that all our students only have one name (it's a small town, what do you want?), and each student cannot be added more than once to a grade or the roster. | ||
If a test attempts to add the same student more than once, your implementation should indicate that this is incorrect. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Introduction | ||
|
||
Bob is a thief. | ||
After months of careful planning, he finally manages to crack the security systems of a fancy store. | ||
Lhakpa is a [Sherpa][sherpa] mountain guide and porter. | ||
After months of careful planning, the expedition Lhakpa works for is about to leave. | ||
She will be paid the value she carried to the base camp. | ||
|
||
In front of him are many items, each with a value and weight. | ||
Bob would gladly take all of the items, but his knapsack can only hold so much weight. | ||
Bob has to carefully consider which items to take so that the total value of his selection is maximized. | ||
In front of her are many items, each with a value and weight. | ||
Lhakpa would gladly take all of the items, but her knapsack can only hold so much weight. | ||
|
||
[sherpa]: https://en.wikipedia.org/wiki/Sherpa_people#Mountaineering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |