Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions kata/7-kyu/even-or-odd-which-is-greater/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [Even or Odd - Which is Greater?](https://www.codewars.com/kata/even-or-odd-which-is-greater "https://www.codewars.com/kata/57f7b8271e3d9283300000b4")

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
digits. Always a string of numbers will be given.

* If the sum of even numbers is greater than the odd numbers return: `"Even is greater than Odd"`

* If the sum of odd numbers is greater than the sum of even numbers return: `"Odd is greater than Even"`

* If the total of both even and odd numbers are identical return: `"Even and Odd are the same"`
6 changes: 6 additions & 0 deletions kata/7-kyu/even-or-odd-which-is-greater/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Kata {
static String evenOrOdd(String str) {
int t = str.chars().reduce(0, (s, c) -> s + (c % 2 > 0 ? -(c - 48) : (c - 48)));
return t == 0 ? "Even and Odd are the same" : t > 0 ? "Even is greater than Odd" : "Odd is greater than Even";
}
}
16 changes: 16 additions & 0 deletions kata/7-kyu/even-or-odd-which-is-greater/test/EvenOrOddTest.java
Original file line number Diff line number Diff line change
@@ -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 EvenOrOddTest {
@ParameterizedTest
@CsvSource(textBlock = """
12, Even is greater than Odd
123, Odd is greater than Even
112, Even and Odd are the same
""")
void sample(String str, String expected) {
assertEquals(expected, Kata.evenOrOdd(str));
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
- [Eliminate the intruders! Bit manipulation](eliminate-the-intruders-bit-manipulation "5a0d38c9697598b67a000041")
- [Email Address Obfuscator](email-address-obfuscator "562d8d4c434582007300004e")
- [E.S.P. Cards](esp-cards "596ef174e4cab6813600004d")
- [Even or Odd - Which is Greater?](even-or-odd-which-is-greater "57f7b8271e3d9283300000b4")
- [Excel sheet column numbers](excel-sheet-column-numbers "55ee3ebff71e82a30000006a")
- [Excessively Abundant Numbers](excessively-abundant-numbers "56a75b91688b49ad94000015")
- [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")
Expand Down