-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
38 lines (29 loc) · 1.15 KB
/
solution.java
File metadata and controls
38 lines (29 loc) · 1.15 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
import java.util.Scanner;
public class AoC_10 {
void magic() {
StringBuilder output = new StringBuilder(sc.nextLine());
for (int iteration = 1; iteration <= 50; iteration++) {
char input[] = output.toString().toCharArray(), previous = input[0];
output = new StringBuilder((int)(input.length * 1.4));
int count = 1;
for (int i = 1; i < input.length; i++, count++) {
if (input[i] != previous) {
output.append(count).append(previous);
previous = input[i];
count = 0;
}
}
output.append(count).append(previous);
if (iteration == 40) {
System.out.println("Part One: " + output.length());
}
}
System.out.println("Part Two: " + output.length());
}
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
new AoC_10().magic();
System.out.println("Running time: " + (System.currentTimeMillis() - startTime) + "ms");
}
}