diff --git a/docs/README.md b/docs/README.md index 2d76a2f87..e57b2093d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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-69.4%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed) +[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.3%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) @@ -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 | 445 | 607 | 228 | 59 | 82 | +| 0 | 1 | 2 | 26 | 48 | 445 | 608 | 228 | 59 | 82 | **Note:** The source code is written in Java 17 and may use language features that are incompatible with Java 8, 11. diff --git a/kata/7-kyu/index.md b/kata/7-kyu/index.md index e52a842da..a131c2cda 100644 --- a/kata/7-kyu/index.md +++ b/kata/7-kyu/index.md @@ -530,6 +530,7 @@ - [Sum of Triangular Numbers](sum-of-triangular-numbers "580878d5d27b84b64c000b51") - [Sum of two lowest positive integers](sum-of-two-lowest-positive-integers "558fc85d8fd1938afb000014") - [Summation Triangle #1](summation-triangle-number-1 "6357825a00fba284e0189798") +- [Summing a number's digits](summing-a-numbers-digits "52f3149496de55aded000410") - [Supernatural](supernatural "55c9a8cda33889d69e00008b") - [Survive the attack](survive-the-attack "634d0f7c562caa0016debac5") - [Suzuki needs help lining up his students!](suzuki-needs-help-lining-up-his-students "5701800886306a876a001031") diff --git a/kata/7-kyu/summing-a-numbers-digits/README.md b/kata/7-kyu/summing-a-numbers-digits/README.md new file mode 100644 index 000000000..0ab1592b2 --- /dev/null +++ b/kata/7-kyu/summing-a-numbers-digits/README.md @@ -0,0 +1,13 @@ +# [Summing a number's digits](https://www.codewars.com/kata/summing-a-numbers-digits "https://www.codewars.com/kata/52f3149496de55aded000410") + +Write a function which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. + +For example: (**Input --> Output**) + +``` +10 --> 1 +99 --> 18 +-32 --> 5 +``` + +Let's assume that all numbers in the input will be integer values. diff --git a/kata/7-kyu/summing-a-numbers-digits/main/Kata.java b/kata/7-kyu/summing-a-numbers-digits/main/Kata.java new file mode 100644 index 000000000..2cd100221 --- /dev/null +++ b/kata/7-kyu/summing-a-numbers-digits/main/Kata.java @@ -0,0 +1,5 @@ +interface Kata { + static int sumDigits(int number) { + return (Math.abs(number) + "").chars().reduce(0, (s, i) -> s + i - 48); + } +} \ No newline at end of file diff --git a/kata/7-kyu/summing-a-numbers-digits/test/SolutionTest.java b/kata/7-kyu/summing-a-numbers-digits/test/SolutionTest.java new file mode 100644 index 000000000..cb8913bcb --- /dev/null +++ b/kata/7-kyu/summing-a-numbers-digits/test/SolutionTest.java @@ -0,0 +1,16 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class SolutionTest { + @ParameterizedTest + @CsvSource(textBlock = """ + 10, 1 + 99, 18 + -32, 5 + """) + void sample(int number, int expected) { + assertEquals(expected, Kata.sumDigits(number)); + } +} \ No newline at end of file