Skip to content

Commit 318c1e2

Browse files
* docs: kata description * feat: kata/even-or-odd-which-is-greater --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent d8e0a3b commit 318c1e2

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# [Even or Odd - Which is Greater?](https://www.codewars.com/kata/even-or-odd-which-is-greater "https://www.codewars.com/kata/57f7b8271e3d9283300000b4")
2+
3+
Given a string of digits confirm whether the sum of all the individual even digits are greater than the sum of all the individual odd
4+
digits. Always a string of numbers will be given.
5+
6+
* If the sum of even numbers is greater than the odd numbers return: `"Even is greater than Odd"`
7+
8+
* If the sum of odd numbers is greater than the sum of even numbers return: `"Odd is greater than Even"`
9+
10+
* If the total of both even and odd numbers are identical return: `"Even and Odd are the same"`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface Kata {
2+
static String evenOrOdd(String str) {
3+
int t = str.chars().reduce(0, (s, c) -> s + (c % 2 > 0 ? -(c - 48) : (c - 48)));
4+
return t == 0 ? "Even and Odd are the same" : t > 0 ? "Even is greater than Odd" : "Odd is greater than Even";
5+
}
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
class EvenOrOddTest {
7+
@ParameterizedTest
8+
@CsvSource(textBlock = """
9+
12, Even is greater than Odd
10+
123, Odd is greater than Even
11+
112, Even and Odd are the same
12+
""")
13+
void sample(String str, String expected) {
14+
assertEquals(expected, Kata.evenOrOdd(str));
15+
}
16+
}

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
- [Eliminate the intruders! Bit manipulation](eliminate-the-intruders-bit-manipulation "5a0d38c9697598b67a000041")
160160
- [Email Address Obfuscator](email-address-obfuscator "562d8d4c434582007300004e")
161161
- [E.S.P. Cards](esp-cards "596ef174e4cab6813600004d")
162+
- [Even or Odd - Which is Greater?](even-or-odd-which-is-greater "57f7b8271e3d9283300000b4")
162163
- [Excel sheet column numbers](excel-sheet-column-numbers "55ee3ebff71e82a30000006a")
163164
- [Excessively Abundant Numbers](excessively-abundant-numbers "56a75b91688b49ad94000015")
164165
- [Exclamation marks series #5: Remove all exclamation marks from the end of words](exclamation-marks-series-number-5-remove-all-exclamation-marks-from-the-end-of-words "57faf32df815ebd49e000117")

0 commit comments

Comments
 (0)