-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubtractTheSum.java
50 lines (43 loc) · 1.81 KB
/
SubtractTheSum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.smlnskgmail.jaman.codewarsjava.kyu8;
import java.util.Arrays;
// https://www.codewars.com/kata/56c5847f27be2c3db20009c3
public class SubtractTheSum {
private String[] words = new String[]{
"kiwi", "pear", "kiwi", "banana", "melon",
"banana", "melon", "pineapple", "apple",
"pineapple", "cucumber", "pineapple",
"cucumber", "orange", "grape", "orange",
"grape", "apple", "grape", "cherry", "pear",
"cherry", "pear", "kiwi", "banana", "kiwi",
"apple", "melon", "banana", "melon",
"pineapple", "melon", "pineapple",
"cucumber", "orange", "apple", "orange",
"grape", "orange", "grape", "cherry",
"pear", "cherry", "pear", "apple", "pear",
"kiwi", "banana", "kiwi", "banana",
"melon", "pineapple", "melon",
"apple", "cucumber", "pineapple", "cucumber",
"orange", "cucumber", "orange", "grape",
"cherry", "apple", "cherry", "pear", "cherry",
"pear", "kiwi", "pear", "kiwi", "banana",
"apple", "banana", "melon", "pineapple",
"melon", "pineapple", "cucumber", "pineapple",
"cucumber", "apple", "grape", "orange", "grape",
"cherry", "grape", "cherry", "pear", "cherry",
"apple", "kiwi", "banana", "kiwi", "banana", "melon",
"banana", "melon", "pineapple", "apple", "pineapple"
};
private int input;
public SubtractTheSum(int input) {
this.input = input;
}
public String solution() {
do {
input -= Arrays
.stream(String.valueOf(input).split(""))
.mapToInt(Integer::parseInt)
.sum();
} while (input > 100);
return words[input - 1];
}
}