Skip to content

Commit 99ae279

Browse files
* docs: kata description * feat: kata/stones-on-the-table --------- Co-authored-by: ParanoidUser <[email protected]>
1 parent fcbeddb commit 99ae279

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@
531531
- [Status Arrays](status-arrays "601c18c1d92283000ec86f2b")
532532
- [Steps](steps-1 "6473603854720900496e1c82")
533533
- [Stone Pickaxe Crafting](stone-pickaxe-crafting "65c0161a2380ae78052e5731")
534+
- [Stones on the Table](stones-on-the-table "5f70e4cce10f9e0001c8995a")
534535
- [Strange mathematics](strange-mathematics "604517d65b464d000d51381f")
535536
- [String ends with?](string-ends-with "51f2d1cafc9c0f745c00037d")
536537
- [String interlacing](string-interlacing "56e120ee2bb224eaa3000ba2")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# [Stones on the Table](https://www.codewars.com/kata/stones-on-the-table "https://www.codewars.com/kata/5f70e4cce10f9e0001c8995a")
2+
3+
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`.
4+
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.
7+
8+
Examples:
9+
10+
```
11+
"RGBRGBRGGB" => 1
12+
"RGGRGBBRGRR" => 3
13+
"RRRRGGGGBBBB" => 9
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)