diff --git a/kata/7-kyu/even-or-odd-which-is-greater/README.md b/kata/7-kyu/even-or-odd-which-is-greater/README.md new file mode 100644 index 00000000..add8b980 --- /dev/null +++ b/kata/7-kyu/even-or-odd-which-is-greater/README.md @@ -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"` \ No newline at end of file diff --git a/kata/7-kyu/even-or-odd-which-is-greater/main/Kata.java b/kata/7-kyu/even-or-odd-which-is-greater/main/Kata.java new file mode 100644 index 00000000..eab4aad9 --- /dev/null +++ b/kata/7-kyu/even-or-odd-which-is-greater/main/Kata.java @@ -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"; + } +} \ No newline at end of file diff --git a/kata/7-kyu/even-or-odd-which-is-greater/test/EvenOrOddTest.java b/kata/7-kyu/even-or-odd-which-is-greater/test/EvenOrOddTest.java new file mode 100644 index 00000000..c5eb9184 --- /dev/null +++ b/kata/7-kyu/even-or-odd-which-is-greater/test/EvenOrOddTest.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 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)); + } +} \ No newline at end of file diff --git a/kata/7-kyu/index.md b/kata/7-kyu/index.md index 620db10a..36886f2e 100644 --- a/kata/7-kyu/index.md +++ b/kata/7-kyu/index.md @@ -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")