Skip to content

Commit 21846eb

Browse files
committed
1 parent 772cc47 commit 21846eb

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

kata/7-kyu/stones-on-the-table/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`.
44

5-
Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have different colors.
5+
Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have
6+
different colors.
67

78
Examples:
89

910
```
1011
"RGBRGBRGGB" => 1
1112
"RGGRGBBRGRR" => 3
1213
"RRRRGGGGBBBB" => 9
13-
```
14+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Solution {
2+
static int solve(String stones) {
3+
return stones.length() - stones.replaceAll("(.)\\1+", "$1").length();
4+
}
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
RGBRGB, 0
10+
RRGGBB, 3
11+
BGRBBGGBRRR, 4
12+
GBBBGGRRGRB, 4
13+
GBRGGRBBBBRRGGGB, 7
14+
""")
15+
void sample(String stones, int duplicates) {
16+
assertEquals(duplicates, Solution.solve(stones));
17+
}
18+
}

0 commit comments

Comments
 (0)