-
Notifications
You must be signed in to change notification settings - Fork 0
/
Luke2.java
61 lines (52 loc) · 1.94 KB
/
Luke2.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
/**
* Æsj, bare rot!
*/
import java.util.HashMap;
import java.util.Scanner;
import java.net.URL;
import java.io.IOException;
//grupere linjer etter stigning
public class Luke2{
private static HashMap<Double,Integer> grupper;
public static void main(String[] args) throws IOException{
grupper = new HashMap<>();
URL link = new URL("https://s3-eu-west-1.amazonaws.com/knowit-julekalender-2018/input-rain.txt");
Scanner input = new Scanner(link.openStream());
while (input.hasNextLine()){
double[] punkter = lesInn(input.nextLine());
double stigning = finnStigning(punkter);
if(grupper.containsKey(stigning)){
grupper.put(stigning,grupper.get(stigning)+1);
} else {
grupper.put(stigning,1);
}
System.out.println(stigning + " : " + grupper.get(stigning));
}
Integer greatest = Integer.MIN_VALUE;
for(Integer i: grupper.values()){
if(i>greatest){
greatest = i;
}
}
System.out.println("Greatest: " + greatest);
}
private static double[] lesInn(String fraFil){
//(x,y);(x,y)
String[] punkter = fraFil.split(";");
//() og ()
/*for (String p: punkter){
p = p.substring(1,p.length()-1);
}*/
//x,y og x,y
double[] xyxy = new double[4];
xyxy[0] = Double.parseDouble(punkter[0].substring(1,punkter[0].length()-1).split(",")[0]);
xyxy[1] = Double.parseDouble(punkter[0].substring(1,punkter[0].length()-1).split(",")[1]);
xyxy[2] = Double.parseDouble(punkter[1].substring(1,punkter[1].length()-1).split(",")[0]);
xyxy[3] = Double.parseDouble(punkter[1].substring(1,punkter[1].length()-1).split(",")[1]);
return xyxy;
}
private static double finnStigning(double[] data){
//x,y,x,y
return data[2]-data[0]/data[3]-data[1];
}
}