Skip to content

Commit 39f0e69

Browse files
authored
Merge branch 'main' into add-approach-change
2 parents 505a92d + bf8a4c3 commit 39f0e69

File tree

22 files changed

+237
-57
lines changed

22 files changed

+237
-57
lines changed

exercises/practice/bob/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"austinlyons",
88
"c-thornton",
99
"FridaTveit",
10+
"jagdish-15",
1011
"jmrunkle",
1112
"jtigger",
1213
"kytrinyx",

exercises/practice/bob/.meta/tests.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[e162fead-606f-437a-a166-d051915cea8e]
613
description = "stating something"
@@ -64,6 +71,7 @@ description = "alternate silence"
6471

6572
[66953780-165b-4e7e-8ce3-4bcb80b6385a]
6673
description = "multiple line question"
74+
include = false
6775

6876
[5371ef75-d9ea-4103-bcfa-2da973ddec1b]
6977
description = "starting with whitespace"
@@ -76,3 +84,7 @@ description = "other whitespace"
7684

7785
[12983553-8601-46a8-92fa-fcaa3bc4a2a0]
7886
description = "non-question ending with whitespace"
87+
88+
[2c7278ac-f955-4eb4-bf8f-e33eb4116a15]
89+
description = "multiple line question"
90+
reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a"

exercises/practice/bob/src/test/java/BobTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ public void alternateSilence() {
152152
.isEqualTo("Fine. Be that way!");
153153
}
154154

155-
@Disabled("Remove to run test")
156-
@Test
157-
public void multipleLineQuestion() {
158-
assertThat(bob.hey("\nDoes this cryogenic chamber make me look fat?\nNo."))
159-
.isEqualTo("Whatever.");
160-
}
161-
162155
@Disabled("Remove to run test")
163156
@Test
164157
public void startingWithWhitespace() {
@@ -187,4 +180,11 @@ public void nonQuestionEndingWithWhiteSpace() {
187180
.isEqualTo("Whatever.");
188181
}
189182

183+
@Disabled("Remove to run test")
184+
@Test
185+
public void multipleLineQuestion() {
186+
assertThat(bob.hey("\nDoes this cryogenic chamber make\n me look fat?"))
187+
.isEqualTo("Sure.");
188+
}
189+
190190
}
Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,100 @@
11
# Instructions
22

3-
A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`.
3+
A **complex number** is expressed in the form `z = a + b * i`, where:
44

5-
`a` is called the real part and `b` is called the imaginary part of `z`.
6-
The conjugate of the number `a + b * i` is the number `a - b * i`.
7-
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.
5+
- `a` is the **real part** (a real number),
86

9-
The sum/difference of two complex numbers involves adding/subtracting their real and imaginary parts separately:
10-
`(a + i * b) + (c + i * d) = (a + c) + (b + d) * i`,
11-
`(a + i * b) - (c + i * d) = (a - c) + (b - d) * i`.
7+
- `b` is the **imaginary part** (also a real number), and
128

13-
Multiplication result is by definition
14-
`(a + i * b) * (c + i * d) = (a * c - b * d) + (b * c + a * d) * i`.
9+
- `i` is the **imaginary unit** satisfying `i^2 = -1`.
1510

16-
The reciprocal of a non-zero complex number is
17-
`1 / (a + i * b) = a/(a^2 + b^2) - b/(a^2 + b^2) * i`.
11+
## Operations on Complex Numbers
1812

19-
Dividing a complex number `a + i * b` by another `c + i * d` gives:
20-
`(a + i * b) / (c + i * d) = (a * c + b * d)/(c^2 + d^2) + (b * c - a * d)/(c^2 + d^2) * i`.
13+
### Conjugate
2114

22-
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)`.
15+
The conjugate of the complex number `z = a + b * i` is given by:
2316

24-
Implement the following operations:
17+
```text
18+
zc = a - b * i
19+
```
2520

26-
- addition, subtraction, multiplication and division of two complex numbers,
27-
- conjugate, absolute value, exponent of a given complex number.
21+
### Absolute Value
2822

29-
Assume the programming language you are using does not have an implementation of complex numbers.
23+
The absolute value (or modulus) of `z` is defined as:
24+
25+
```text
26+
|z| = sqrt(a^2 + b^2)
27+
```
28+
29+
The square of the absolute value is computed as the product of `z` and its conjugate `zc`:
30+
31+
```text
32+
|z|^2 = z * zc = a^2 + b^2
33+
```
34+
35+
### Addition
36+
37+
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:
38+
39+
```text
40+
z1 + z2 = (a + b * i) + (c + d * i)
41+
= (a + c) + (b + d) * i
42+
```
43+
44+
### Subtraction
45+
46+
The difference of two complex numbers is obtained by subtracting their respective parts:
47+
48+
```text
49+
z1 - z2 = (a + b * i) - (c + d * i)
50+
= (a - c) + (b - d) * i
51+
```
52+
53+
### Multiplication
54+
55+
The product of two complex numbers is defined as:
56+
57+
```text
58+
z1 * z2 = (a + b * i) * (c + d * i)
59+
= (a * c - b * d) + (b * c + a * d) * i
60+
```
61+
62+
### Reciprocal
63+
64+
The reciprocal of a non-zero complex number is given by:
65+
66+
```text
67+
1 / z = 1 / (a + b * i)
68+
= a / (a^2 + b^2) - b / (a^2 + b^2) * i
69+
```
70+
71+
### Division
72+
73+
The division of one complex number by another is given by:
74+
75+
```text
76+
z1 / z2 = z1 * (1 / z2)
77+
= (a + b * i) / (c + d * i)
78+
= (a * c + b * d) / (c^2 + d^2) + (b * c - a * d) / (c^2 + d^2) * i
79+
```
80+
81+
### Exponentiation
82+
83+
Raising _e_ (the base of the natural logarithm) to a complex exponent can be expressed using Euler's formula:
84+
85+
```text
86+
e^(a + b * i) = e^a * e^(b * i)
87+
= e^a * (cos(b) + i * sin(b))
88+
```
89+
90+
## Implementation Requirements
91+
92+
Given that you should not use built-in support for complex numbers, implement the following operations:
93+
94+
- **addition** of two complex numbers
95+
- **subtraction** of two complex numbers
96+
- **multiplication** of two complex numbers
97+
- **division** of two complex numbers
98+
- **conjugate** of a complex number
99+
- **absolute value** of a complex number
100+
- **exponentiation** of _e_ (the base of the natural logarithm) to a complex number

exercises/practice/dot-dsl/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"editor": [
1717
"src/main/java/Node.java",
1818
"src/main/java/Edge.java"
19+
],
20+
"invalidator": [
21+
"build.gradle"
1922
]
2023
},
2124
"blurb": "Write a Domain Specific Language similar to the Graphviz dot language.",

exercises/practice/forth/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"aadityakulkarni",
77
"FridaTveit",
88
"hgvanpariya",
9+
"jagdish-15",
910
"jmrunkle",
1011
"kytrinyx",
1112
"lemoncurry",

exercises/practice/forth/.meta/tests.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ description = "addition -> errors if there is nothing on the stack"
2424
[06efb9a4-817a-435e-b509-06166993c1b8]
2525
description = "addition -> errors if there is only one value on the stack"
2626

27+
[1e07a098-c5fa-4c66-97b2-3c81205dbc2f]
28+
description = "addition -> more than two values on the stack"
29+
2730
[09687c99-7bbc-44af-8526-e402f997ccbf]
2831
description = "subtraction -> can subtract two numbers"
2932

@@ -33,6 +36,9 @@ description = "subtraction -> errors if there is nothing on the stack"
3336
[b3cee1b2-9159-418a-b00d-a1bb3765c23b]
3437
description = "subtraction -> errors if there is only one value on the stack"
3538

39+
[2c8cc5ed-da97-4cb1-8b98-fa7b526644f4]
40+
description = "subtraction -> more than two values on the stack"
41+
3642
[5df0ceb5-922e-401f-974d-8287427dbf21]
3743
description = "multiplication -> can multiply two numbers"
3844

@@ -42,6 +48,9 @@ description = "multiplication -> errors if there is nothing on the stack"
4248
[8ba4b432-9f94-41e0-8fae-3b3712bd51b3]
4349
description = "multiplication -> errors if there is only one value on the stack"
4450

51+
[5cd085b5-deb1-43cc-9c17-6b1c38bc9970]
52+
description = "multiplication -> more than two values on the stack"
53+
4554
[e74c2204-b057-4cff-9aa9-31c7c97a93f5]
4655
description = "division -> can divide two numbers"
4756

@@ -57,12 +66,21 @@ description = "division -> errors if there is nothing on the stack"
5766
[d5547f43-c2ff-4d5c-9cb0-2a4f6684c20d]
5867
description = "division -> errors if there is only one value on the stack"
5968

69+
[f224f3e0-b6b6-4864-81de-9769ecefa03f]
70+
description = "division -> more than two values on the stack"
71+
6072
[ee28d729-6692-4a30-b9be-0d830c52a68c]
6173
description = "combined arithmetic -> addition and subtraction"
6274

6375
[40b197da-fa4b-4aca-a50b-f000d19422c1]
6476
description = "combined arithmetic -> multiplication and division"
6577

78+
[f749b540-53aa-458e-87ec-a70797eddbcb]
79+
description = "combined arithmetic -> multiplication and addition"
80+
81+
[c8e5a4c2-f9bf-4805-9a35-3c3314e4989a]
82+
description = "combined arithmetic -> addition and multiplication"
83+
6684
[c5758235-6eef-4bf6-ab62-c878e50b9957]
6785
description = "dup -> copies a value on the stack"
6886

exercises/practice/forth/src/test/java/ForthEvaluatorTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public void testErrorIfAdditionAttemptedWithOneNumberOnTheStack() {
4848
.withMessage("Addition requires that the stack contain at least 2 values");
4949
}
5050

51+
@Disabled("Remove to run test")
52+
@Test
53+
public void testAdditionForMoreThanTwoValuesOnTheStack() {
54+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 2 3 +")))
55+
.containsExactly(1, 5);
56+
}
57+
5158
@Disabled("Remove to run test")
5259
@Test
5360
public void testTwoNumbersCanBeSubtracted() {
@@ -72,6 +79,13 @@ public void testErrorIfSubtractionAttemptedWithOneNumberOnTheStack() {
7279
.withMessage("Subtraction requires that the stack contain at least 2 values");
7380
}
7481

82+
@Disabled("Remove to run test")
83+
@Test
84+
public void testSubtractionForMoreThanTwoValuesOnTheStack() {
85+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 12 3 -")))
86+
.containsExactly(1, 9);
87+
}
88+
7589
@Disabled("Remove to run test")
7690
@Test
7791
public void testTwoNumbersCanBeMultiplied() {
@@ -94,6 +108,13 @@ public void testErrorIfMultiplicationAttemptedWithOneNumberOnTheStack() {
94108
.withMessage("Multiplication requires that the stack contain at least 2 values");
95109
}
96110

111+
@Disabled("Remove to run test")
112+
@Test
113+
public void testMultiplicationForMoreThanTwoValuesOnTheStack() {
114+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 2 3 *")))
115+
.containsExactly(1, 6);
116+
}
117+
97118
@Disabled("Remove to run test")
98119
@Test
99120
public void testTwoNumbersCanBeDivided() {
@@ -130,6 +151,13 @@ public void testErrorIfDivisionAttemptedWithOneNumberOnTheStack() {
130151
.withMessage("Division requires that the stack contain at least 2 values");
131152
}
132153

154+
@Disabled("Remove to run test")
155+
@Test
156+
public void testDivisionForMoreThanTwoValuesOnTheStack() {
157+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 12 3 /")))
158+
.containsExactly(1, 4);
159+
}
160+
133161
@Disabled("Remove to run test")
134162
@Test
135163
public void testCombinedAdditionAndSubtraction() {
@@ -142,6 +170,18 @@ public void testCombinedMultiplicationAndDivision() {
142170
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("2 4 * 3 /"))).containsExactly(2);
143171
}
144172

173+
@Disabled("Remove to run test")
174+
@Test
175+
public void testCombinedMultiplicationAndAddition() {
176+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 3 4 * +"))).containsExactly(13);
177+
}
178+
179+
@Disabled("Remove to run test")
180+
@Test
181+
public void testCombinedAdditionAndMultiplication() {
182+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 3 4 + *"))).containsExactly(7);
183+
}
184+
145185
@Disabled("Remove to run test")
146186
@Test
147187
public void testDupCopiesAValueOnTheStack() {

exercises/practice/hamming/.docs/instructions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instructions
22

3-
Calculate the Hamming Distance between two DNA strands.
3+
Calculate the Hamming distance between two DNA strands.
44

55
Your body is made up of cells that contain DNA.
66
Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells.
@@ -9,18 +9,18 @@ In fact, the average human body experiences about 10 quadrillion cell divisions
99
When cells divide, their DNA replicates too.
1010
Sometimes during this process mistakes happen and single pieces of DNA get encoded with the incorrect information.
1111
If we compare two strands of DNA and count the differences between them we can see how many mistakes occurred.
12-
This is known as the "Hamming Distance".
12+
This is known as the "Hamming distance".
1313

14-
We read DNA using the letters C,A,G and T.
14+
We read DNA using the letters C, A, G and T.
1515
Two strands might look like this:
1616

1717
GAGCCTACTAACGGGAT
1818
CATCGTAATGACGGCCT
1919
^ ^ ^ ^ ^ ^^
2020

21-
They have 7 differences, and therefore the Hamming Distance is 7.
21+
They have 7 differences, and therefore the Hamming distance is 7.
2222

23-
The Hamming Distance is useful for lots of things in science, not just biology, so it's a nice phrase to be familiar with :)
23+
The Hamming distance is useful for lots of things in science, not just biology, so it's a nice phrase to be familiar with :)
2424

2525
## Implementation notes
2626

exercises/practice/hamming/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"build.gradle"
4444
]
4545
},
46-
"blurb": "Calculate the Hamming difference between two DNA strands.",
46+
"blurb": "Calculate the Hamming distance between two DNA strands.",
4747
"source": "The Calculating Point Mutations problem at Rosalind",
4848
"source_url": "https://rosalind.info/problems/hamm/"
4949
}

0 commit comments

Comments
 (0)