-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kata/clean-up-after-your-dog (#658)
* docs: kata description * docs: sync progress * feat(7-kyu): kata/clean-up-after-your-dog --------- Co-authored-by: ParanoidUser <[email protected]> Co-authored-by: Dmitriy Fedoriv <[email protected]>
- Loading branch information
1 parent
a7fd02f
commit 195de4b
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |