diff --git a/kata/7-kyu/index.md b/kata/7-kyu/index.md index 11fdcc5f..d9fc700c 100644 --- a/kata/7-kyu/index.md +++ b/kata/7-kyu/index.md @@ -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") diff --git a/kata/7-kyu/stones-on-the-table/README.md b/kata/7-kyu/stones-on-the-table/README.md new file mode 100644 index 00000000..f9e7523e --- /dev/null +++ b/kata/7-kyu/stones-on-the-table/README.md @@ -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 +``` \ No newline at end of file diff --git a/kata/7-kyu/stones-on-the-table/main/Solution.java b/kata/7-kyu/stones-on-the-table/main/Solution.java new file mode 100644 index 00000000..1dba9888 --- /dev/null +++ b/kata/7-kyu/stones-on-the-table/main/Solution.java @@ -0,0 +1,5 @@ +interface Solution { + static int solve(String stones) { + return stones.length() - stones.replaceAll("(.)\\1+", "$1").length(); + } +} \ No newline at end of file diff --git a/kata/7-kyu/stones-on-the-table/test/SolutionTest.java b/kata/7-kyu/stones-on-the-table/test/SolutionTest.java new file mode 100644 index 00000000..99cd7cbb --- /dev/null +++ b/kata/7-kyu/stones-on-the-table/test/SolutionTest.java @@ -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)); + } +} \ No newline at end of file