Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Jul 5, 2024
1 parent a502534 commit 6c714e0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Codewars Handbook ☕️🚀

[![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=https://github.com/ParanoidUser/codewars-handbook)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.4%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.5%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml)
[![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook)
[![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook)
Expand All @@ -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 | 426 | 572 | 210 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 426 | 573 | 210 | 56 | 79 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
32 changes: 32 additions & 0 deletions kata/7-kyu/a-letters-best-friend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# [A Letter's Best Friend](https://www.codewars.com/kata/a-letters-best-friend "https://www.codewars.com/kata/64fc03a318692c1333ebc04c")

### Task

Given a string, return if all occurrences of a given letter are always immediately followed by the other given letter.

### Worked Example

```
("he headed to the store", "h", "e") ➞ True
# All occurences of "h": ["he", "headed", "the"]
# All occurences of "h" have an "e" after it.
# Return True
('abcdee', 'e', 'e') ➞ False
# For first "e" we can get "ee"
# For second "e" we cannot have "ee"
# Return False
```

### Examples

```
("i found an ounce with my hound", "o", "u") ➞ True
("we found your dynamite", "d", "y") ➞ False
```

### Notes

- All sentences will be given in lowercase.
5 changes: 5 additions & 0 deletions kata/7-kyu/a-letters-best-friend/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Kata {
static boolean bestFriend(String txt, char a, char b) {
return !txt.matches(".*" + a + "(?!" + b + ").*");
}
}
31 changes: 31 additions & 0 deletions kata/7-kyu/a-letters-best-friend/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

class SolutionTest {
@ParameterizedTest
@CsvSource(textBlock = """
'', x, y
xaeaex, a, e
he headed to the store, h, e
i found an ounce with my hound, o, u
those were their thorns they said, t, h
""")
void friends(String txt, char a, char b) {
assertTrue(Kata.bestFriend(txt, a, b));
}

@ParameterizedTest
@CsvSource(textBlock = """
a test, t, e
abcdee, e, e
abcde, e, e
we found your dynamite, d, y
look they took the cookies, o, o
""")
void strangers(String txt, char a, char b) {
assertFalse(Kata.bestFriend(txt, a, b));
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [80's Kids #3: Punky Brewster's Socks](80-s-kids-number-3-punky-brewsters-socks)
- [80's Kids #5: You Can't Do That on Television](80-s-kids-number-5-you-cant-do-that-on-television)
# A
- [A Letter's Best Friend](a-letters-best-friend)
- [A Man and his Earthly Measurement](a-man-and-his-earthly-measurement)
- [A Rule of Divisibility by 7](a-rule-of-divisibility-by-7)
- [Acronym Generator](acronym-generator)
Expand Down

0 comments on commit 6c714e0

Please sign in to comment.