Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Jan 28, 2024
1 parent b66f2dd commit e003268
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
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 | 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.
Expand Down
1 change: 1 addition & 0 deletions kata/6-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions kata/6-kyu/simple-rot13-dot-5-cypher/README.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions kata/6-kyu/simple-rot13-dot-5-cypher/main/Kata.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
11 changes: 11 additions & 0 deletions kata/6-kyu/simple-rot13-dot-5-cypher/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit e003268

Please sign in to comment.