-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay06.java
More file actions
87 lines (79 loc) · 2.75 KB
/
Day06.java
File metadata and controls
87 lines (79 loc) · 2.75 KB
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
//part 1
package org.thehuglio;
import java.io.File;
import java.util.*;
public class Main {
private static final List<String> data = new Reader(new File("data.txt")).data;
public static void main(String[] args) {
int tot = 1;
List<Integer> time = new LinkedList<>();
List<Integer> distance = new LinkedList<>();
String[] split = data.get(0).split(":")[1].split(" ");
for (String s : split) {
if (!Objects.equals(s, "") && !Objects.equals(s," ")) {
time.add(Integer.parseInt(s));
}
}
split = data.get(1).split(":")[1].split(" ");
for (String s : split) {
if (!Objects.equals(s, "") && !Objects.equals(s," ")) {
distance.add(Integer.parseInt(s));
}
}
for (int i = 0; i < time.size(); i++) {
int speed = 0;
int maxspeed = 0;
int minspeed = 0;
while (speed < time.get(i)) {
if (distance.get(i) < speed * (time.get(i) - speed) && minspeed == 0) {
minspeed = speed;
}
else if (distance.get(i) < speed * (time.get(i) - speed)) {
maxspeed = speed;
}
speed++;
}
tot *= (maxspeed - minspeed) + 1;
}
System.out.println(tot);
}
}
//part 2 (remove spacing from the input data)
package org.thehuglio;
import java.io.File;
import java.util.*;
public class Main {
private static final List<String> data = new Reader(new File("data.txt")).data;
public static void main(String[] args) {
long tot = 1;
List<Long> time = new LinkedList<>();
List<Long> distance = new LinkedList<>();
String[] split = data.get(0).split(":")[1].split(" ");
for (String s : split) {
if (!Objects.equals(s, "") && !Objects.equals(s," ")) {
time.add(Long.parseLong(s));
}
}
split = data.get(1).split(":")[1].split(" ");
for (String s : split) {
if (!Objects.equals(s, "") && !Objects.equals(s," ")) {
distance.add(Long.parseLong(s));
}
}
for (int i = 0; i < time.size(); i++) {
long speed = 0;
long maxspeed = 0;
long minspeed = 0;
while (speed < time.get(i)) {
if (distance.get(i) < speed * (time.get(i) - speed) && minspeed == 0) {
minspeed = speed;
}
else if (distance.get(i) < speed * (time.get(i) - speed)) {
maxspeed = speed;
}
speed++;
}
System.out.println((maxspeed - minspeed) + 1);
}
}
}