diff --git a/docs/README.md b/docs/README.md index 1aa49625..1eae1103 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,7 +25,7 @@ slug. | [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) | |:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:| -| 0 | 1 | 2 | 26 | 48 | 430 | 581 | 218 | 56 | 79 | +| 0 | 1 | 2 | 26 | 48 | 430 | 582 | 218 | 56 | 79 | **Note:** The source code is written in Java 17 and may use language features that are incompatible with Java 8, 11. diff --git a/kata/7-kyu/clean-up-after-your-dog/README.md b/kata/7-kyu/clean-up-after-your-dog/README.md new file mode 100644 index 00000000..edd998d9 --- /dev/null +++ b/kata/7-kyu/clean-up-after-your-dog/README.md @@ -0,0 +1,27 @@ +# [Clean up after your dog](https://www.codewars.com/kata/clean-up-after-your-dog "https://www.codewars.com/kata/57faa6ff9610ce181b000028") + +You have stumbled across the divine pleasure that is owning a dog and a garden. Now time to pick up all the cr@p! :D + +Given a 2D array to represent your garden, you must find and collect all the dog cr@p - represented by `'@'`. + +You will also be given the number of bags you have access to (`bags`), and the capactity of a bag (`cap`). If there are no `bags` then you +can't pick anything up, so you can ignore `cap`. + +You need to find out if you have enough capacity to collect all the cr@p and make your garden clean again. + +If you do, return `'Clean'`, else return `'Cr@p'`. + +Watch out though - if your dog is out there (`'D'`), he gets very touchy about being watched. If he is there you need to return `'Dog!!'`. + +For example: + +``` +bags = 2 +cap = 2 +x (or garden) = +[[ _ , _ , _ , _ , _ , _ ], + [ _ , _ , _ , _ , @ , _ ], + [ @ , _ , _ , _ , _ , _ ]] +``` + +returns `'Clean'` \ No newline at end of file diff --git a/kata/7-kyu/clean-up-after-your-dog/main/Kata.java b/kata/7-kyu/clean-up-after-your-dog/main/Kata.java new file mode 100644 index 00000000..261a9605 --- /dev/null +++ b/kata/7-kyu/clean-up-after-your-dog/main/Kata.java @@ -0,0 +1,15 @@ +interface Kata { + static String crap(char[][] garden, int bags, int cap) { + int poops = bags * cap; + for (char[] bunch : garden) { + for (char patch : bunch) { + if (patch == 'D') { + return "Dog!!"; + } else if (patch == '@') { + poops--; + } + } + } + return poops < 0 ? "Cr@p" : "Clean"; + } +} \ No newline at end of file diff --git a/kata/7-kyu/clean-up-after-your-dog/test/SampleTests.java b/kata/7-kyu/clean-up-after-your-dog/test/SampleTests.java new file mode 100644 index 00000000..011c4cc5 --- /dev/null +++ b/kata/7-kyu/clean-up-after-your-dog/test/SampleTests.java @@ -0,0 +1,50 @@ +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +class SampleTests { + private static Stream cleanData() { + return Stream.of( + arguments(new char[][]{{'_', '_', '_', '_'}, {'_', '_', '_', '@'}, {'_', '_', '@', '_'}}, 2, 2), + arguments(new char[][]{{'_', '_', '_', '_'}, {'_', '_', '_', '_'}, {'_', '_', '_', '_'}}, 2, 2), + arguments(new char[][]{{'@', '@'}, {'@', '@'}, {'@', '@'}}, 3, 2), + arguments(new char[0][0], 0, 0) + ); + } + + private static Stream dirtyData() { + return Stream.of( + arguments(new char[][]{{'_', '_', '_', '_'}, {'_', '_', '_', '@'}, {'_', '_', '@', '_'}}, 1, 1), + arguments(new char[][]{{'@', '.', '.', '.'}, {'.', '.', '.', '.'}, {'.', '.', '.', '@'}}, 1, 0) + ); + } + + private static Stream dogData() { + return Stream.of( + arguments(new char[][]{{'_', '_'}, {'_', '@'}, {'D', '_'}}, 2, 2), + arguments(new char[][]{{'@', '@'}, {'@', '@'}, {'@', 'D'}}, 0, 0) + ); + } + + @ParameterizedTest + @MethodSource("cleanData") + void cleanCase(char[][] garden, int bags, int capacity) { + assertEquals("Clean", Kata.crap(garden, bags, capacity)); + } + + @ParameterizedTest + @MethodSource("dirtyData") + void dirtyCase(char[][] garden, int bags, int capacity) { + assertEquals("Cr@p", Kata.crap(garden, bags, capacity)); + } + + @ParameterizedTest + @MethodSource("dogData") + void dogCase(char[][] garden, int bags, int capacity) { + assertEquals("Dog!!", Kata.crap(garden, bags, capacity)); + } +} \ No newline at end of file