diff --git a/docs/README.md b/docs/README.md index 77cad40b9..4d2d5ba2b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 | 44 | 419 | 561 | 206 | 55 | 79 | +| 0 | 1 | 2 | 26 | 44 | 420 | 561 | 206 | 55 | 79 | **Note:** The source code is written in Java 17 and may use language features that are incompatible with Java 8, 11. diff --git a/kata/6-kyu/index.md b/kata/6-kyu/index.md index cbdab0187..4d63d9f2d 100644 --- a/kata/6-kyu/index.md +++ b/kata/6-kyu/index.md @@ -333,6 +333,7 @@ - [Simple nearest prime](simple-nearest-prime) - [Simple prime streaming](simple-prime-streaming) - [Simple reversed parenthesis](simple-reversed-parenthesis) +- [Simple ROT13.5 cypher](simple-rot13-dot-5-cypher) - [Simple square numbers](simple-square-numbers) - [Simple string indices](simple-string-indices) - [Simple time difference](simple-time-difference) diff --git a/kata/6-kyu/simple-rot13-dot-5-cypher/README.md b/kata/6-kyu/simple-rot13-dot-5-cypher/README.md new file mode 100644 index 000000000..fb50449e2 --- /dev/null +++ b/kata/6-kyu/simple-rot13-dot-5-cypher/README.md @@ -0,0 +1,18 @@ +# [Simple ROT13.5 cypher](https://www.codewars.com/kata/simple-rot13-dot-5-cypher "https://www.codewars.com/kata/5894986e2ddc8f6805000036") + +You are asked to write a simple cypher that rotates every character (in range [a-zA-Z], special chars will be ignored by +the cypher) by 13 chars. As an addition to the original ROT13 cypher, this cypher will also cypher numerical +digits ([0-9]) with 5 chars. + +Example: + + "The quick brown fox jumps over the 2 lazy dogs" + +will be cyphered to: + + "Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf" + +Your task is to write a ROT13.5 (ROT135) method that accepts a string and encrypts it. +Decrypting is performed by using the same method, but by passing the encrypted string again. + +Note: when an empty string is passed, the result is also empty. \ No newline at end of file diff --git a/kata/6-kyu/simple-rot13-dot-5-cypher/main/Kata.java b/kata/6-kyu/simple-rot13-dot-5-cypher/main/Kata.java new file mode 100644 index 000000000..fb7041794 --- /dev/null +++ b/kata/6-kyu/simple-rot13-dot-5-cypher/main/Kata.java @@ -0,0 +1,10 @@ +import static java.util.stream.Collectors.joining; + +interface Kata { + static String ROT135(String input) { + return input.chars().mapToObj(c -> "" + (char) c).map(s -> "" + (char) (s.charAt(0) + ( + s.matches("(?i)[A-M]") ? 13 : s.matches("(?i)[N-Z]") ? -13 : + s.matches("[0-4]") ? 5 : s.matches("[5-9]") ? -5 : 0))) + .collect(joining()); + } +} \ No newline at end of file diff --git a/kata/6-kyu/simple-rot13-dot-5-cypher/test/SolutionTest.java b/kata/6-kyu/simple-rot13-dot-5-cypher/test/SolutionTest.java new file mode 100644 index 000000000..12dc9df29 --- /dev/null +++ b/kata/6-kyu/simple-rot13-dot-5-cypher/test/SolutionTest.java @@ -0,0 +1,11 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void sample() { + assertEquals("Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf", Kata.ROT135("The quick brown fox jumps over the 2 lazy dogs")); + assertEquals("The quick brown fox jumps over the 2 lazy dogs", Kata.ROT135("Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf")); + } +} \ No newline at end of file