-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7-kyu): kata/a-letters-best-friend (#597)
- Loading branch information
1 parent
a502534
commit 6c714e0
Showing
5 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + ").*"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters