Skip to content

Commit dbb0ec7

Browse files
committed
Days 15 and 16
1 parent 7ffd42f commit dbb0ec7

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

16.txt

+1
Large diffs are not rendered by default.

Day15.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Day15 {
2+
3+
public static void main(String[] args) throws java.io.IOException {
4+
long count1 = 0, gen1 = 703L, gen2 = 516L;
5+
for (int i = 0; i < 40000000; i++) {
6+
gen1 = next(true, true, gen1);
7+
gen2 = next(true, false, gen2);
8+
if ((gen1 & 0xffff) == (gen2 & 0xffff)) count1++;
9+
}
10+
System.out.print(count1);
11+
count1 = 0; gen1 = 703L; gen2 = 516L;
12+
for (int i = 0; i < 5000000; i++) {
13+
gen1 = next(false, true, gen1);
14+
gen2 = next(false, false, gen2);
15+
if ((gen1 & 0xffff) == (gen2 & 0xffff)) count1++;
16+
}
17+
System.out.println(" - " + count1);
18+
}
19+
20+
private static long next(boolean part1, boolean a, long curr) {
21+
do curr = (curr * (a ? 16807 : 48271)) % 2147483647;
22+
while (part1 ? false : curr % (a ? 4 : 8) != 0);
23+
return curr;
24+
}
25+
26+
}

Day16.java

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public class Day16 {
2+
3+
public static void main(String[] args) throws java.io.IOException {
4+
java.util.List<String> start = java.util.Arrays.asList("abcdefghijklmnop".split(""));
5+
java.util.List<String> progs = new java.util.ArrayList<>(java.util.Arrays.asList("abcdefghijklmnop".split("")));
6+
String[] rows = java.nio.file.Files.readAllLines(java.nio.file.Paths.get("16.txt")).get(0).split(",");
7+
for (int k = 0; k < 1000000000; k++) {
8+
if (k == 1) {
9+
System.out.print(progs.toString().replaceAll(", ", ""));
10+
}
11+
if (k > 0 && progs.equals(start)) {
12+
k = 1000000000 - (1000000000 % k);
13+
}
14+
for (String row : rows) {
15+
if (row.charAt(0) == 'x') {
16+
Integer pos1 = Integer.valueOf(row.substring(1).split("/")[0]);
17+
Integer pos2 = Integer.valueOf(row.substring(1).split("/")[1]);
18+
String tmp = progs.get(pos1);
19+
progs.set(pos1, progs.get(pos2));
20+
progs.set(pos2, tmp);
21+
}
22+
if (row.charAt(0) == 'p') {
23+
int pos1 = progs.indexOf(String.valueOf(row.substring(1).split("/")[0].charAt(0)));
24+
int pos2 = progs.indexOf(String.valueOf(row.substring(1).split("/")[1].charAt(0)));
25+
String tmp = progs.get(pos1);
26+
progs.set(pos1, progs.get(pos2));
27+
progs.set(pos2, tmp);
28+
}
29+
if (row.charAt(0) == 's') {
30+
for (int i = 0; i < Integer.valueOf(row.substring(1)); i++) {
31+
progs.add(0, progs.get(progs.size() - 1));
32+
progs.remove(progs.size() - 1);
33+
}
34+
}
35+
}
36+
}
37+
System.out.println(" - " + progs.toString().replaceAll(", ", ""));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)