-
-
Notifications
You must be signed in to change notification settings - Fork 682
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 file paths, metadata, and documentation with the problem-specifications repository #2869
Merged
kahgoh
merged 4 commits into
exercism:main
from
jagdish-15:sync-documents-with-problem-specification
Nov 20, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3a0a219
Syncing with problem-specification
jagdish-15 25ad17e
Merge branch 'main' of https://github.com/jagdish-15/java
jagdish-15 1a47ebc
Syncing docs, metadata and filepaths with problem-specifications
jagdish-15 65e05b8
Syncing unsynced docs and metadata
jagdish-15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 89 additions & 18 deletions
107
exercises/practice/complex-numbers/.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,100 @@ | ||
# Instructions | ||
|
||
A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`. | ||
A **complex number** is expressed in the form `z = a + b * i`, where: | ||
|
||
`a` is called the real part and `b` is called the imaginary part of `z`. | ||
The conjugate of the number `a + b * i` is the number `a - b * i`. | ||
The absolute value of a complex number `z = a + b * i` is a real number `|z| = sqrt(a^2 + b^2)`. The square of the absolute value `|z|^2` is the result of multiplication of `z` by its complex conjugate. | ||
- `a` is the **real part** (a real number), | ||
|
||
The sum/difference of two complex numbers involves adding/subtracting their real and imaginary parts separately: | ||
`(a + i * b) + (c + i * d) = (a + c) + (b + d) * i`, | ||
`(a + i * b) - (c + i * d) = (a - c) + (b - d) * i`. | ||
- `b` is the **imaginary part** (also a real number), and | ||
|
||
Multiplication result is by definition | ||
`(a + i * b) * (c + i * d) = (a * c - b * d) + (b * c + a * d) * i`. | ||
- `i` is the **imaginary unit** satisfying `i^2 = -1`. | ||
|
||
The reciprocal of a non-zero complex number is | ||
`1 / (a + i * b) = a/(a^2 + b^2) - b/(a^2 + b^2) * i`. | ||
## Operations on Complex Numbers | ||
|
||
Dividing a complex number `a + i * b` by another `c + i * d` gives: | ||
`(a + i * b) / (c + i * d) = (a * c + b * d)/(c^2 + d^2) + (b * c - a * d)/(c^2 + d^2) * i`. | ||
### Conjugate | ||
|
||
Raising e to a complex exponent can be expressed as `e^(a + i * b) = e^a * e^(i * b)`, the last term of which is given by Euler's formula `e^(i * b) = cos(b) + i * sin(b)`. | ||
The conjugate of the complex number `z = a + b * i` is given by: | ||
|
||
Implement the following operations: | ||
```text | ||
zc = a - b * i | ||
``` | ||
|
||
- addition, subtraction, multiplication and division of two complex numbers, | ||
- conjugate, absolute value, exponent of a given complex number. | ||
### Absolute Value | ||
|
||
Assume the programming language you are using does not have an implementation of complex numbers. | ||
The absolute value (or modulus) of `z` is defined as: | ||
|
||
```text | ||
|z| = sqrt(a^2 + b^2) | ||
``` | ||
|
||
The square of the absolute value is computed as the product of `z` and its conjugate `zc`: | ||
|
||
```text | ||
|z|^2 = z * zc = a^2 + b^2 | ||
``` | ||
|
||
### Addition | ||
|
||
The sum of two complex numbers `z1 = a + b * i` and `z2 = c + d * i` is computed by adding their real and imaginary parts separately: | ||
|
||
```text | ||
z1 + z2 = (a + b * i) + (c + d * i) | ||
= (a + c) + (b + d) * i | ||
``` | ||
|
||
### Subtraction | ||
|
||
The difference of two complex numbers is obtained by subtracting their respective parts: | ||
|
||
```text | ||
z1 - z2 = (a + b * i) - (c + d * i) | ||
= (a - c) + (b - d) * i | ||
``` | ||
|
||
### Multiplication | ||
|
||
The product of two complex numbers is defined as: | ||
|
||
```text | ||
z1 * z2 = (a + b * i) * (c + d * i) | ||
= (a * c - b * d) + (b * c + a * d) * i | ||
``` | ||
|
||
### Reciprocal | ||
|
||
The reciprocal of a non-zero complex number is given by: | ||
|
||
```text | ||
1 / z = 1 / (a + b * i) | ||
= a / (a^2 + b^2) - b / (a^2 + b^2) * i | ||
``` | ||
|
||
### Division | ||
|
||
The division of one complex number by another is given by: | ||
|
||
```text | ||
z1 / z2 = z1 * (1 / z2) | ||
= (a + b * i) / (c + d * i) | ||
= (a * c + b * d) / (c^2 + d^2) + (b * c - a * d) / (c^2 + d^2) * i | ||
``` | ||
|
||
### Exponentiation | ||
|
||
Raising _e_ (the base of the natural logarithm) to a complex exponent can be expressed using Euler's formula: | ||
|
||
```text | ||
e^(a + b * i) = e^a * e^(b * i) | ||
= e^a * (cos(b) + i * sin(b)) | ||
``` | ||
|
||
## Implementation Requirements | ||
|
||
Given that you should not use built-in support for complex numbers, implement the following operations: | ||
|
||
- **addition** of two complex numbers | ||
- **subtraction** of two complex numbers | ||
- **multiplication** of two complex numbers | ||
- **division** of two complex numbers | ||
- **conjugate** of a complex number | ||
- **absolute value** of a complex number | ||
- **exponentiation** of _e_ (the base of the natural logarithm) to a complex number |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to commit this change? It isn't clear to me why we would want to add this to the invalidator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was part of the
metadata
sync performed byconfiglet
with the Problem Specifications repository.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense! Thanks for letting me know.