Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* docs: kata description

* docs: sync progress

* feat(7-kyu): kata/clean-up-after-your-dog

---------

Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
  • Loading branch information
2 people authored and Dmitriy Fedoriv committed Sep 23, 2024
1 parent a7fd02f commit 9fcbc13
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions kata/7-kyu/clean-up-after-your-dog/README.md
Original file line number Diff line number Diff line change
@@ -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'`
15 changes: 15 additions & 0 deletions kata/7-kyu/clean-up-after-your-dog/main/Kata.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
50 changes: 50 additions & 0 deletions kata/7-kyu/clean-up-after-your-dog/test/SampleTests.java
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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<Arguments> dirtyData() {
return Stream.of(
arguments(new char[][]{{'_', '_', '_', '_'}, {'_', '_', '_', '@'}, {'_', '_', '@', '_'}}, 1, 1),
arguments(new char[][]{{'@', '.', '.', '.'}, {'.', '.', '.', '.'}, {'.', '.', '.', '@'}}, 1, 0)
);
}

private static Stream<Arguments> 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));
}
}

0 comments on commit 9fcbc13

Please sign in to comment.