Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@
- [Status Arrays](status-arrays "601c18c1d92283000ec86f2b")
- [Steps](steps-1 "6473603854720900496e1c82")
- [Stone Pickaxe Crafting](stone-pickaxe-crafting "65c0161a2380ae78052e5731")
- [Stones on the Table](stones-on-the-table "5f70e4cce10f9e0001c8995a")
- [Strange mathematics](strange-mathematics "604517d65b464d000d51381f")
- [String ends with?](string-ends-with "51f2d1cafc9c0f745c00037d")
- [String interlacing](string-interlacing "56e120ee2bb224eaa3000ba2")
Expand Down
14 changes: 14 additions & 0 deletions kata/7-kyu/stones-on-the-table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# [Stones on the Table](https://www.codewars.com/kata/stones-on-the-table "https://www.codewars.com/kata/5f70e4cce10f9e0001c8995a")

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`.

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.

Examples:

```
"RGBRGBRGGB" => 1
"RGGRGBBRGRR" => 3
"RRRRGGGGBBBB" => 9
```
5 changes: 5 additions & 0 deletions kata/7-kyu/stones-on-the-table/main/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Solution {
static int solve(String stones) {
return stones.length() - stones.replaceAll("(.)\\1+", "$1").length();
}
}
18 changes: 18 additions & 0 deletions kata/7-kyu/stones-on-the-table/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

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

class SolutionTest {
@ParameterizedTest
@CsvSource(textBlock = """
RGBRGB, 0
RRGGBB, 3
BGRBBGGBRRR, 4
GBBBGGRRGRB, 4
GBRGGRBBBBRRGGGB, 7
""")
void sample(String stones, int duplicates) {
assertEquals(duplicates, Solution.solve(stones));
}
}