-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarMileage.java
26 lines (21 loc) · 986 Bytes
/
carMileage.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
import java.util.Arrays;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static java.lang.Integer.parseInt;
public class CarMileage {
public static boolean isReallyInteresting(int number, final int[] awesomePhrases) {
return Stream.<Predicate<String>>of(
s -> s.matches("\\d0+"),
s -> new StringBuilder(s).reverse().toString().equals(s),
s -> "1234567890".contains(s),
s -> "9876543210".contains(s),
s -> Arrays.stream(awesomePhrases).anyMatch(n -> parseInt(s) == n)
).anyMatch( p -> number > 99 && p.test(Integer.toString(number)));
}
public static int isInteresting(int number, int[] awesomePhrases) {
return isReallyInteresting(number, awesomePhrases) ? 2 :
isReallyInteresting(number + 1, awesomePhrases) ? 1 :
isReallyInteresting(number + 2, awesomePhrases) ? 1 : 0;
}
}
//https://www.codewars.com/kata/52c4dd683bfd3b434c000292/train/python