Skip to content

Commit 09b9277

Browse files
* docs: kata description * feat: kata/rot13-1 --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent abd06b9 commit 09b9277

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

kata/5-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [Primes in numbers](primes-in-numbers "54d512e62a5e54c96200019e")
4040
- [Product of consecutive Fib numbers](product-of-consecutive-fib-numbers "5541f58a944b85ce6d00006a")
4141
- [RGB To Hex Conversion](rgb-to-hex-conversion "513e08acc600c94f01000001")
42+
- [Rot13](rot13-1 "530e15517bc88ac656000716")
4243
- [ROT13](rot13 "52223df9e8f98c7aa7000062")
4344
- [Scramblies](scramblies "55c04b4cc56a697bb0000048")
4445
- [Simple Pig Latin](simple-pig-latin "520b9d2ad5c005041100000f")

kata/5-kyu/rot13-1/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# [Rot13](https://www.codewars.com/kata/rot13-1 "https://www.codewars.com/kata/530e15517bc88ac656000716")
2+
3+
ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example
4+
of the Caesar cipher.
5+
6+
Create a function that takes a string and returns the string ciphered with Rot13.
7+
If there are numbers or special characters included in the string, they should be returned as they are. Only letters from the latin/english
8+
alphabet should be shifted, like in the original Rot13 "implementation".

kata/5-kyu/rot13-1/main/Kata.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import static java.util.stream.Collectors.joining;
2+
3+
interface Kata {
4+
static String rot13(String str) {
5+
return str.chars().mapToObj(c -> "" + (char) c)
6+
.map(c -> "" + (char) (c.charAt(0) + (c.matches("(?i)[A-M]") ? 13 : c.matches("(?i)[N-Z]") ? -13 : 0)))
7+
.collect(joining());
8+
}
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
class SolutionTest {
7+
@ParameterizedTest
8+
@CsvSource(textBlock = """
9+
test, grfg
10+
Test, Grfg
11+
!@#$, !@#$
12+
""")
13+
void sample(String message, String expected) {
14+
assertEquals(expected, Kata.rot13(message));
15+
}
16+
}

0 commit comments

Comments
 (0)