- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootOperator.java
More file actions
Latest commit
50 lines (38 loc) · 943 Bytes
/
Copy pathRootOperator.java
File metadata and controls
50 lines (38 loc) · 943 Bytes
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
importjava.util.Random;
publicclassRootOperatorextendsOperator {
intwhich;
publicRootOperator(Difficultydiff, Randomrand) {
super(diff, rand);
shuffle();
}
publicOperatorcloneThis() {
RootOperatorop = newRootOperator(this.diff, this.rand);
op.which = which;
returnop;
}
publicvoidshuffle() {
if (diff.level == Difficulty.Level.HARD) {
which = rand.nextInt(2) + 2;
}
}
publicbooleanworksForInput(intin) {
booleansecond = false;
booleanthird = false;
// test if Square Root is an Integer
intsqrt = (int) Math.sqrt(in);
second = sqrt * sqrt == in;
if (second)
which = 2;
intcurt = (int) Math.pow(in, 1d/3d);
third = curt * curt * curt == in;
if (third)
which = 3;
returnsecond || third;
}
publicintgetOutput() {
return (int) Math.pow(prev.getOutput(), 1d/which);
}
publicStringtoString() {
return (which == 3 ? "3. " : "") + "Wurzel ziehen";
}
}