Skip to content

Commit 707048b

Browse files
authored
Merge branch 'main' into update-tests-sgf-parsing
2 parents 877560a + 3f5c931 commit 707048b

File tree

38 files changed

+490
-279
lines changed

38 files changed

+490
-279
lines changed

concepts/switch-statement/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"Azumix"
55
],
66
"contributors": [
7+
"josealonso"
78
]
89
}

concepts/switch-statement/about.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,23 @@ Starting with Java 14 (available as a preview before in Java 12 and 13) it is po
147147

148148
You can find more information on enhanced switch [here][switch1], [here][switch2] and on the [oracle documentation][oracle-doc].
149149

150+
In addition, a feature called `Guarded Patterns` was added in Java 21, which allows you to do checks in the case label itself.
151+
152+
```java
153+
String dayOfMonth = getDayOfMonth();
154+
String day = "";
155+
return switch (day) {
156+
case "Tuesday" when dayOfMonth == 13 -> "Forbidden day!!";
157+
case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" -> "Week day";
158+
case "Saturday", "Sunday" -> "Weekend";
159+
default -> "Unknown";
160+
};
161+
```
162+
163+
You can find more information on the switch expression on Java 21 [here][switch-on-Java-21]
164+
150165
[yield-keyword]: https://www.codejava.net/java-core/the-java-language/yield-keyword-in-java
151166
[switch1]: https://www.vojtechruzicka.com/java-enhanced-switch/
152167
[switch2]: https://howtodoinjava.com/java14/switch-expressions/
153168
[oracle-doc]: https://docs.oracle.com/en/java/javase/13/language/switch-expressions.html
169+
[switch-on-Java-21]: https://blog.adamgamboa.dev/switch-expression-on-java-21/#3-guarded-pattern

concepts/switch-statement/links.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
{
1515
"url": "https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html",
1616
"description": "oracle-doc"
17+
},
18+
{
19+
"url": "https://blog.adamgamboa.dev/switch-expression-on-java-21/#3-guarded-pattern",
20+
"description": "switch-on-Java-21"
1721
}
1822
]

exercises/practice/affine-cipher/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Create an implementation of the affine cipher, an ancient encryption system crea
44

55
The affine cipher is a type of monoalphabetic substitution cipher.
66
Each character is mapped to its numeric equivalent, encrypted with a mathematical function and then converted to the letter relating to its new numeric value.
7-
Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the atbash cipher, because it has many more keys.
7+
Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the Atbash cipher, because it has many more keys.
88

99
[//]: # " monoalphabetic as spelled by Merriam-Webster, compare to polyalphabetic "
1010

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Instructions Append
2+
3+
The anagrams can be returned in any order.

exercises/practice/atbash-cipher/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instructions
22

3-
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
3+
Create an implementation of the Atbash cipher, an ancient encryption system created in the Middle East.
44

55
The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards.
66
The first letter is replaced with the last letter, the second with the second-last, and so on.

exercises/practice/atbash-cipher/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"build.gradle"
4040
]
4141
},
42-
"blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.",
42+
"blurb": "Create an implementation of the Atbash cipher, an ancient encryption system created in the Middle East.",
4343
"source": "Wikipedia",
4444
"source_url": "https://en.wikipedia.org/wiki/Atbash"
4545
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# Instructions
22

3-
Correctly determine the fewest number of coins to be given to a customer such that the sum of the coins' value would equal the correct amount of change.
3+
Determine the fewest number of coins to give a customer so that the sum of their values equals the correct amount of change.
44

5-
## For example
5+
## Examples
66

7-
- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) or [5, 10]
8-
- An input of 40 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) and one quarter (25) or [5, 10, 25]
9-
10-
## Edge cases
11-
12-
- Does your algorithm work for any given set of coins?
13-
- Can you ask for negative change?
14-
- Can you ask for a change value smaller than the smallest coin value?
7+
- An amount of 15 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5 and one coin of value 10, or [5, 10].
8+
- An amount of 40 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5, one coin of value 10, and one coin of value 25, or [5, 10, 25].
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Introduction
2+
3+
In the mystical village of Coinholt, you stand behind the counter of your bakery, arranging a fresh batch of pastries.
4+
The door creaks open, and in walks Denara, a skilled merchant with a keen eye for quality goods.
5+
After a quick meal, she slides a shimmering coin across the counter, representing a value of 100 units.
6+
7+
You smile, taking the coin, and glance at the total cost of the meal: 88 units.
8+
That means you need to return 12 units in change.
9+
10+
Denara holds out her hand expectantly.
11+
"Just give me the fewest coins," she says with a smile.
12+
"My pouch is already full, and I don't want to risk losing them on the road."
13+
14+
You know you have a few options.
15+
"We have Lumis (worth 10 units), Viras (worth 5 units), and Zenth (worth 2 units) available for change."
16+
17+
You quickly calculate the possibilities in your head:
18+
19+
- one Lumis (1 × 10 units) + one Zenth (1 × 2 units) = 2 coins total
20+
- two Viras (2 × 5 units) + one Zenth (1 × 2 units) = 3 coins total
21+
- six Zenth (6 × 2 units) = 6 coins total
22+
23+
"The best choice is two coins: one Lumis and one Zenth," you say, handing her the change.
24+
25+
Denara smiles, clearly impressed.
26+
"As always, you've got it right."
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
11
# Instructions
22

3-
The Collatz Conjecture or 3x+1 problem can be summarized as follows:
4-
5-
Take any positive integer n.
6-
If n is even, divide n by 2 to get n / 2.
7-
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
8-
Repeat the process indefinitely.
9-
The conjecture states that no matter which number you start with, you will always reach 1 eventually.
10-
11-
Given a number n, return the number of steps required to reach 1.
12-
13-
## Examples
14-
15-
Starting with n = 12, the steps would be as follows:
16-
17-
0. 12
18-
1. 6
19-
2. 3
20-
3. 10
21-
4. 5
22-
5. 16
23-
6. 8
24-
7. 4
25-
8. 2
26-
9. 1
27-
28-
Resulting in 9 steps.
29-
So for input n = 12, the return value would be 9.
3+
Given a positive integer, return the number of steps it takes to reach 1 according to the rules of the Collatz Conjecture.

0 commit comments

Comments
 (0)