Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 27, 2024
1 parent 55ed708 commit 87a5c20
Show file tree
Hide file tree
Showing 5 changed files with 50 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 | 430 | 577 | 214 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 430 | 578 | 214 | 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
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
- [Number of People in the Bus](number-of-people-in-the-bus)
- [Number of Rectangles in a Grid](number-of-rectangles-in-a-grid)
- [Number-Star ladder](number-star-ladder)
- [Number to digit tiers](number-to-digit-tiers)
- [Numbers in strings](numbers-in-strings)
- [Numbers Which Sum of Powers of Its Digits Is The Same Number](numbers-which-sum-of-powers-of-its-digits-is-the-same-number)
- [Numbers with d occurrences of digit d](numbers-with-d-occurences-of-digit-d)
Expand Down
13 changes: 13 additions & 0 deletions kata/7-kyu/number-to-digit-tiers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# [Number to digit tiers](https://www.codewars.com/kata/number-to-digit-tiers "https://www.codewars.com/kata/586bca7fa44cfc833e00005c")

Create a function that takes a number and returns an array of strings containing the number cut off at each digit.

### Examples

* `420` should return `["4", "42", "420"]`
* `2017` should return `["2", "20", "201", "2017"]`
* `2010` should return `["2", "20", "201", "2010"]`
* `4020` should return `["4", "40", "402", "4020"]`
* `80200` should return `["8", "80", "802", "8020", "80200"]`

PS: The input is guaranteed to be an integer in the range `[0, 1000000]`
8 changes: 8 additions & 0 deletions kata/7-kyu/number-to-digit-tiers/main/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import static java.util.stream.IntStream.range;

interface Solution {
static String[] createArrayOfTiers(int num) {
var s = num + "";
return range(0, s.length()).mapToObj(i -> s.substring(0, i + 1)).toArray(String[]::new);
}
}
26 changes: 26 additions & 0 deletions kata/7-kyu/number-to-digit-tiers/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

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;

class SolutionTest {
private static Stream<Arguments> testData() {
return Stream.of(
Arguments.of(0, new String[]{"0"}),
Arguments.of(6, new String[]{"6"}),
Arguments.of(420, new String[]{"4", "42", "420"}),
Arguments.of(2017, new String[]{"2", "20", "201", "2017"}),
Arguments.of(2010, new String[]{"2", "20", "201", "2010"}),
Arguments.of(4020, new String[]{"4", "40", "402", "4020"}),
Arguments.of(80200, new String[]{"8", "80", "802", "8020", "80200"})
);
}

@ParameterizedTest
@MethodSource("testData")
void sample(int num, String[] expected) {
assertArrayEquals(expected, Solution.createArrayOfTiers(num));
}
}

0 comments on commit 87a5c20

Please sign in to comment.