Skip to content

Commit

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

* docs: sync progress

* feat: kata/c-is-for-codewars

---------

Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and ParanoidUser authored Jan 8, 2025
1 parent 163b5ce commit 73f155a
Show file tree
Hide file tree
Showing 5 changed files with 116 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 | 440 | 604 | 227 | 56 | 82 |
| 0 | 1 | 2 | 26 | 48 | 440 | 605 | 227 | 56 | 82 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
37 changes: 37 additions & 0 deletions kata/7-kyu/c-is-for-codewars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# [C is for Codewars](https://www.codewars.com/kata/c-is-for-codewars "https://www.codewars.com/kata/675dc1d3830826975c58a09d")

#### Task:

Build a string representing a capital letter C of a given size out of 'C' characters.

#### Examples:

`generate_C(1)` should return this string:

```
CCCCC
C
C
C
CCCCC
```

`generate_C(2)` should be

```
CCCCCCCCCC
CCCCCCCCCC
CC
CC
CC
CC
CC
CC
CCCCCCCCCC
CCCCCCCCCC
```

and so on. The string returned by `generate_C(size)` should have `5*size` lines, following the format above. <code>size</code> is a positive
integer <code>&le; 2000.</code>

Note that extra spaces after the C's in any line are incorrect. And the last line should not terminate with "\n".
8 changes: 8 additions & 0 deletions kata/7-kyu/c-is-for-codewars/main/GenerateC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import static java.util.stream.Collectors.joining;
import static java.util.stream.IntStream.range;

interface GenerateC {
static String generateC(int size) {
return range(0, 5 * size).mapToObj(r -> "C".repeat(size * (r < size || r > 4 * size - 1 ? 5 : 1))).collect(joining("\n"));
}
}
69 changes: 69 additions & 0 deletions kata/7-kyu/c-is-for-codewars/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class SolutionTest {
@Test
void sample() {
assertEquals("""
CCCCC
C
C
C
CCCCC""", GenerateC.generateC(1));

assertEquals("""
CCCCCCCCCC
CCCCCCCCCC
CC
CC
CC
CC
CC
CC
CCCCCCCCCC
CCCCCCCCCC""", GenerateC.generateC(2)
);

assertEquals("""
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC
CCC
CCC
CCC
CCC
CCC
CCC
CCC
CCC
CCC
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC""", GenerateC.generateC(3)
);

assertEquals("""
CCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCC
CCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCC""", GenerateC.generateC(4)
);
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- [Bumps in the Road](bumps-in-the-road)
- [Bus mastering - Who is the most prioritary?](bus-mastering-who-is-the-most-prioritary)
# C
- [C is for Codewars](c-is-for-codewars)
- [C.Wars](cwars)
- [Caffeine Script](caffeine-script)
- [Calculate mean and concatenate string](calculate-mean-and-concatenate-string)
Expand Down

0 comments on commit 73f155a

Please sign in to comment.