-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
20 changed files
with
164 additions
and
65 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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Introduction | ||
|
||
Your body is made up of cells that contain DNA. | ||
Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells. | ||
In fact, the average human body experiences about 10 quadrillion cell divisions in a lifetime! | ||
|
||
When cells divide, their DNA replicates too. | ||
Sometimes during this process mistakes happen and single pieces of DNA get encoded with the incorrect information. | ||
If we compare two strands of DNA and count the differences between them, we can see how many mistakes occurred. | ||
This is known as the "Hamming distance". | ||
|
||
The Hamming distance is useful in many areas of science, not just biology, so it's a nice phrase to be familiar with :) |
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,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
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,14 +1,35 @@ | ||
# Instructions | ||
|
||
Compute Pascal's triangle up to a given number of rows. | ||
Your task is to output the first N rows of Pascal's triangle. | ||
|
||
In Pascal's Triangle each number is computed by adding the numbers to the right and left of the current position in the previous row. | ||
[Pascal's triangle][wikipedia] is a triangular array of positive integers. | ||
|
||
In Pascal's triangle, the number of values in a row is equal to its row number (which starts at one). | ||
Therefore, the first row has one value, the second row has two values, and so on. | ||
|
||
The first (topmost) row has a single value: `1`. | ||
Subsequent rows' values are computed by adding the numbers directly to the right and left of the current position in the previous row. | ||
|
||
If the previous row does _not_ have a value to the left or right of the current position (which only happens for the leftmost and rightmost positions), treat that position's value as zero (effectively "ignoring" it in the summation). | ||
|
||
## Example | ||
|
||
Let's look at the first 5 rows of Pascal's Triangle: | ||
|
||
```text | ||
1 | ||
1 1 | ||
1 2 1 | ||
1 3 3 1 | ||
1 4 6 4 1 | ||
# ... etc | ||
``` | ||
|
||
The topmost row has one value, which is `1`. | ||
|
||
The leftmost and rightmost values have only one preceding position to consider, which is the position to its right respectively to its left. | ||
With the topmost value being `1`, it follows from this that all the leftmost and rightmost values are also `1`. | ||
|
||
The other values all have two positions to consider. | ||
For example, the fifth row's (`1 4 6 4 1`) middle value is `6`, as the values to its left and right in the preceding row are `3` and `3`: | ||
|
||
[wikipedia]: https://en.wikipedia.org/wiki/Pascal%27s_triangle |
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,22 @@ | ||
# Introduction | ||
|
||
With the weather being great, you're not looking forward to spending an hour in a classroom. | ||
Annoyed, you enter the class room, where you notice a strangely satisfying triangle shape on the blackboard. | ||
Whilst waiting for your math teacher to arrive, you can't help but notice some patterns in the triangle: the outer values are all ones, each subsequent row has one more value than its previous row and the triangle is symmetrical. | ||
Weird! | ||
|
||
Not long after you sit down, your teacher enters the room and explains that this triangle is the famous [Pascal's triangle][wikipedia]. | ||
|
||
Over the next hour, your teacher reveals some amazing things hidden in this triangle: | ||
|
||
- It can be used to compute how many ways you can pick K elements from N values. | ||
- 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! | ||
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. | ||
|
||
[wikipedia]: https://en.wikipedia.org/wiki/Pascal%27s_triangle | ||
[wikipedia-sierpinski-triangle]: https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle |
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,4 +1,4 @@ | ||
# Instructions | ||
# Description | ||
|
||
A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which, | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
exercises/practice/pythagorean-triplet/.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,19 @@ | ||
# Introduction | ||
|
||
You are an accomplished problem-solver, known for your ability to tackle the most challenging mathematical puzzles. | ||
One evening, you receive an urgent letter from an inventor called the Triangle Tinkerer, who is working on a groundbreaking new project. | ||
The letter reads: | ||
|
||
> Dear Mathematician, | ||
> | ||
> I need your help. | ||
> I am designing a device that relies on the unique properties of Pythagorean triplets — sets of three integers that satisfy the equation a² + b² = c². | ||
> This device will revolutionize navigation, but for it to work, I must program it with every possible triplet where the sum of a, b, and c equals a specific number, N. | ||
> Calculating these triplets by hand would take me years, but I hear you are more than up to the task. | ||
> | ||
> Time is of the essence. | ||
> The future of my invention — and perhaps even the future of mathematical innovation — rests on your ability to solve this problem. | ||
Motivated by the importance of the task, you set out to find all Pythagorean triplets that satisfy the condition. | ||
Your work could have far-reaching implications, unlocking new possibilities in science and engineering. | ||
Can you rise to the challenge and make history? |
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,13 +1,18 @@ | ||
# Instructions | ||
|
||
Given a natural radicand, return its square root. | ||
Your task is to calculate the square root of a given number. | ||
|
||
Note that the term "radicand" refers to the number for which the root is to be determined. | ||
That is, it is the number under the root symbol. | ||
- Try to avoid using the pre-existing math libraries of your language. | ||
- As input you'll be given a positive whole number, i.e. 1, 2, 3, 4… | ||
- You are only required to handle cases where the result is a positive whole number. | ||
|
||
Check out the Wikipedia pages on [square root][square-root] and [methods of computing square roots][computing-square-roots]. | ||
Some potential approaches: | ||
|
||
Recall also that natural numbers are positive real whole numbers (i.e. 1, 2, 3 and up). | ||
- Linear or binary search for a number that gives the input number when squared. | ||
- Successive approximation using Newton's or Heron's method. | ||
- Calculating one digit at a time or one bit at a time. | ||
|
||
[square-root]: https://en.wikipedia.org/wiki/Square_root | ||
You can check out the Wikipedia pages on [integer square root][integer-square-root] and [methods of computing square roots][computing-square-roots] to help with choosing a method of calculation. | ||
|
||
[integer-square-root]: https://en.wikipedia.org/wiki/Integer_square_root | ||
[computing-square-roots]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots |
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,10 @@ | ||
# Introduction | ||
|
||
We are launching a deep space exploration rocket and we need a way to make sure the navigation system stays on target. | ||
|
||
As the first step in our calculation, we take a target number and find its square root (that is, the number that when multiplied by itself equals the target number). | ||
|
||
The journey will be very long. | ||
To make the batteries last as long as possible, we had to make our rocket's onboard computer very power efficient. | ||
Unfortunately that means that we can't rely on fancy math libraries and functions, as they use more power. | ||
Instead we want to implement our own square root calculation. |
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