Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ slug.

| [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) |
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:|
| 0 | 1 | 2 | 26 | 48 | 445 | 606 | 228 | 58 | 82 |
| 0 | 1 | 2 | 26 | 48 | 445 | 606 | 228 | 59 | 82 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
2 changes: 2 additions & 0 deletions kata/beta/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@
- [Who's Next in Line?](whos-next-in-line)
# Y
- [Your Basic FizzBuzz kata](your-basic-fizzbuzz-kata)
# Z
- [Zeta Swap](zeta-swap)
21 changes: 21 additions & 0 deletions kata/beta/zeta-swap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [Zeta Swap](https://www.codewars.com/kata/zeta-swap "https://www.codewars.com/kata/6780126afa635e648148397e")

Hello Detective! The Ministry of Magic has suddenly fallen while we were in the middle of our annual Tetrawizard Tournament. A murder has
been spotted within the chambers of Slytherin. Our only witness is Ron. But, as you know, Ron was preoccupied with Lavendar while it
happened. He is unsure what letter he saw on the back of the coats of the suspects since he reads right to left.

Your task is to implement a function that takes a string and swaps each letter with its "opposite" in the alphabet (e.g., 'a' ↔ 'z', 'b' ↔ 'y', etc.),
but only if the letter occurs more than once in the string.

- Non-alphabet characters (e.g., numbers, punctuation, whitespace) should remain unchanged.
- The function should preserve the case of the letters (e.g., 'A' ↔ 'Z', 'b' ↔ 'y').
- Single-occurrence letters are not swapped.

Input

- A string containing alphabetic and non-alphabetic characters.
- Length of the string: 0 ≤ length ≤ 10^5.

Output

- A string with swapped letters where applicable, and all other characters unchanged.
10 changes: 10 additions & 0 deletions kata/beta/zeta-swap/main/ZetaSwap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.joining;

interface ZetaSwap {
static String swapMurder(String suspects) {
var count = suspects.chars().boxed().collect(groupingBy(c -> c | 32, counting()));
return suspects.chars().mapToObj(c -> "" + (char) (Character.isLetter(c) && count.get(c | 32) > 1 ? (c > 96 ? 219 : 155) - c : c)).collect(joining());
}
}
18 changes: 18 additions & 0 deletions kata/beta/zeta-swap/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class SolutionTest {
@ParameterizedTest
@CsvSource(textBlock = """
abcabc, zyxzyx
aabc, zzbc
abc, abc
HeLLo, HeOOo
123 !@# aabc, 123 !@# zzbc
""")
void sample(String suspects, String swapped) {
assertEquals(swapped, ZetaSwap.swapMurder(suspects));
}
}