-
Notifications
You must be signed in to change notification settings - Fork 0
/
JurassicWord.java
49 lines (42 loc) · 1.61 KB
/
JurassicWord.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
package com.smlnskgmail.jaman.codewarsjava.kyu6;
import java.util.Arrays;
import java.util.Objects;
// https://www.codewars.com/kata/55709dc15ebd283cc9000007
public class JurassicWord {
private final String input;
public JurassicWord(String input) {
this.input = input;
}
public String solution() {
String dino = whichDino(new StringBuilder(input).reverse().substring(3, 8));
String something = "Something";
if (input.matches("_C.*C}>")) {
return (Arrays.asList("velociraptor", "T-Rex").contains(dino) ? "A " + dino : something)
+ " is eating a dead dino.";
} else if (input.matches("iii.*iii")) {
return (Arrays.asList("brachiosaurus", "triceratops").contains(dino) ? "A " + dino : something)
+ " is eating flowers.";
} else if (input.matches("\\|\\|\\|.*\\|\\|\\|")) {
return (Objects.equals("brachiosaurus", dino) ? "A " + dino : something)
+ " is eating leaves.";
}
return (Arrays.asList("brachiosaurus", "triceratops", "velociraptor", "T-Rex").contains(dino)
? "A " + dino
: something)
+ " is eating something.";
}
private String whichDino(String dino) {
switch (dino) {
case "uuuuu":
return "brachiosaurus";
case "uuVuu":
return "triceratops";
case "VvvvV":
return "T-Rex";
case "vvvvv":
return "velociraptor";
default:
return null;
}
}
}