-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSumProblem.java
91 lines (58 loc) · 2.21 KB
/
SumProblem.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import com.github.sh0nk.matplotlib4j.Plot;
import com.github.sh0nk.matplotlib4j.PythonExecutionException;
import com.github.sh0nk.matplotlib4j.builder.ScaleBuilder;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
public class SumProblem {
BigInteger startPoint = BigInteger.ONE;
private int countEven = 0;
private int countOdd = 0;
public static void main(String[] args) throws PythonExecutionException, IOException {
SumProblem sum = new SumProblem();
System.out.println("Hello, you math freak!");
System.out.println("Enter a huge number to let 3x+1 do its job!");
Scanner sc=new Scanner(System.in);
BigInteger a= sc.nextBigInteger();
sum.processing();
sum.StartSequenz(a);
}
private void processing(){
System.out.print("Processing");
String out = "";
int i = 2;
while (i>0){
try {
i--;
out= "";
Thread.sleep(1000L); // 1000L = 1000ms = 1 second
out = ".";
}
catch (InterruptedException e) {
//I don't think you need to do anything for your particular problem
}
System.out.print(out);
}
}
private void StartSequenz(BigInteger startPoint) throws PythonExecutionException, IOException {
Plot plt = Plot.create();
plt.xlabel("xlabel");
plt.ylabel("ylabel");
//plt.text(100, 100, "text");
//plt.xscale(ScaleBuilder.Scale.valueOf("100"));
plt.title("Title!");
System.out.println(startPoint);
this.startPoint = startPoint;
while(startPoint.compareTo(BigInteger.ONE) > 0){
if(startPoint.mod(BigInteger.TWO).compareTo(BigInteger.ZERO) != 0){
startPoint = (startPoint.multiply(BigInteger.valueOf(3))).add(BigInteger.ONE);
countOdd++;
} else {
startPoint = (startPoint.divide(BigInteger.TWO));
countEven++;
}
System.out.println(startPoint);
}
System.out.println("overall even: " + countEven + " " + "overall odd: " + countOdd);
}
}