Skip to content

Commit

Permalink
feat(6-kyu): kata/cure-cancer (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Aug 8, 2024
1 parent 49ea401 commit 9192b2d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Codewars Handbook ☕️🚀

[![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=https://github.com/ParanoidUser/codewars-handbook)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.5%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.6%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml)
[![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook)
[![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook)
Expand All @@ -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 | 427 | 577 | 210 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 428 | 577 | 210 | 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
40 changes: 40 additions & 0 deletions kata/6-kyu/cure-cancer/README.md
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.
12 changes: 12 additions & 0 deletions kata/6-kyu/cure-cancer/main/JomoPipi.java
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];
}
}
62 changes: 62 additions & 0 deletions kata/6-kyu/cure-cancer/test/SolutionTest.java
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()
}));
}
}

0 comments on commit 9192b2d

Please sign in to comment.