-
-
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(6-kyu): kata/cure-cancer (#623)
- Loading branch information
1 parent
49ea401
commit 9192b2d
Showing
4 changed files
with
116 additions
and
2 deletions.
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,40 @@ | ||
# [Cure Cancer](https://www.codewars.com/kata/cure-cancer "https://www.codewars.com/kata/5b4accacbdd07498aa000041") | ||
|
||
Now you are a doctor. | ||
|
||
You are working with a patient's **body** which has many cells. | ||
|
||
The patient's body is a matrix where every row represents a cell. | ||
|
||
Each cell contains just uppercase and lowercase letters, | ||
|
||
and every cell in the body should be the same. | ||
|
||
Oh, no! It seems that one of the cells have mutated! | ||
|
||
It is your job to locate the mutation so that the chemo specialists can fix it! | ||
|
||
return the location [i,j] within the matrix... | ||
|
||
before it's too late! :( | ||
|
||
example: | ||
|
||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecadecells <- here it is! [20, 9] | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
cellscellscellscodecodecells | ||
|
||
no bodies will have less than 3 cells. | ||
|
||
if the diagnosis was a false alarm, return an empty array. |
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,12 @@ | ||
interface JomoPipi { | ||
static int[] mutationLocation(char[][] body) { | ||
for (int i = 1; i < body.length; i++) { | ||
for (int j = 0; j < body[i].length; j++) { | ||
if (body[0][j] != body[i][j]) { | ||
return new int[]{i > 1 || body[0][j] == body[2][j] ? i : 0, j}; | ||
} | ||
} | ||
} | ||
return new int[0]; | ||
} | ||
} |
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,62 @@ | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class SolutionTest { | ||
@Test | ||
void sample() { | ||
assertArrayEquals(new int[0], JomoPipi.mutationLocation(new char[][]{ | ||
"WellAndHealthy".toCharArray(), | ||
"WellAndHealthy".toCharArray(), | ||
"WellAndHealthy".toCharArray(), | ||
"WellAndHealthy".toCharArray() | ||
})); | ||
|
||
assertArrayEquals(new int[]{0, 4}, JomoPipi.mutationLocation(new char[][]{ | ||
"thisssAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray() | ||
})); | ||
|
||
assertArrayEquals(new int[]{1, 4}, JomoPipi.mutationLocation(new char[][]{ | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisssAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray() | ||
})); | ||
|
||
assertArrayEquals(new int[]{2, 4}, JomoPipi.mutationLocation(new char[][]{ | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisssAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray() | ||
})); | ||
|
||
assertArrayEquals(new int[]{3, 4}, JomoPipi.mutationLocation(new char[][]{ | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisIsAsmallerPerson".toCharArray(), | ||
"thisssAsmallerPerson".toCharArray() | ||
})); | ||
|
||
assertArrayEquals(new int[]{9, 14}, JomoPipi.mutationLocation(new char[][]{ | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuff1thinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray(), | ||
"someGreaTstuffIthinkThisIs".toCharArray() | ||
})); | ||
} | ||
} |