This commit is contained in:
matthias@arch 2022-12-11 02:11:01 +01:00
parent e96c5dad2b
commit 7dfbdc1d62
4 changed files with 196 additions and 0 deletions

1
10/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Main.class

48
10/Main.java Normal file
View File

@ -0,0 +1,48 @@
import java.io.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.lang.Math;
public class Main {
static int instructionCounter = 1;
static int registerX = 1;
static int signalStrenghts = 0;
public static String getCurrentPixel() {
String s = "";
int crtPos = (instructionCounter - 1) % 40;
// System.out.printf("crtpos: %d\n", crtPos);
if (Math.abs(registerX - 1 - crtPos) <= 1) { s = ""; }
else { s = " "; }
if (instructionCounter % 40 == 0) { s += "\r\n"; }
return s;
}
public static void instructionFinished() {
System.out.print(getCurrentPixel());
instructionCounter++;
if (instructionCounter >= 20 && (instructionCounter - 20) % 40 == 0) {
signalStrenghts += registerX * instructionCounter;
}
}
public static void main(String[] args) throws IOException {
String input = Files.readString(Path.of(args[0]));
String separator = System.getProperty("line.separator");
int index = 0;
while (true) {
int nextIndex = input.indexOf(separator, index + separator.length());
if (nextIndex < 0) { break; };
String line = input.substring(index, nextIndex);
instructionFinished();
if (!line.equals("noop")) {
int val = Integer.parseInt(line.split(" ")[1]);
registerX += val;
instructionFinished();
}
index = nextIndex + 1;
}
System.out.printf("The sum of the signal strengths is: %d\n", signalStrenghts);
}
}

8
10/README.md Normal file
View File

@ -0,0 +1,8 @@
# [Day 10](https://adventofcode.com/2022/day/10)
:gift::gift::gift::gift::gift::gift::gift::gift::gift::gift:
Today's language: **Java**
```shell
```

139
10/asm.txt Normal file
View File

@ -0,0 +1,139 @@
noop
noop
noop
addx 6
addx -1
noop
addx 5
noop
noop
addx -12
addx 19
addx -1
noop
addx 4
addx -11
addx 16
noop
noop
addx 5
addx 3
addx -2
addx 4
noop
noop
noop
addx -37
noop
addx 3
addx 2
addx 5
addx 2
addx 10
addx -9
noop
addx 1
addx 4
addx 2
noop
addx 3
addx 2
addx 5
addx 2
addx 3
addx -2
addx 2
addx 5
addx -40
addx 25
addx -22
addx 2
addx 5
addx 2
addx 3
addx -2
noop
addx 23
addx -18
addx 2
noop
noop
addx 7
noop
noop
addx 5
noop
noop
noop
addx 1
addx 2
addx 5
addx -40
addx 3
addx 8
addx -4
addx 1
addx 4
noop
noop
noop
addx -8
noop
addx 16
addx 2
addx 4
addx 1
noop
addx -17
addx 18
addx 2
addx 5
addx 2
addx 1
addx -11
addx -27
addx 17
addx -10
addx 3
addx -2
addx 2
addx 7
noop
addx -2
noop
addx 3
addx 2
noop
addx 3
addx 2
noop
addx 3
addx 2
addx 5
addx 2
addx -5
addx -2
addx -30
addx 14
addx -7
addx 22
addx -21
addx 2
addx 6
addx 2
addx -1
noop
addx 8
addx -3
noop
addx 5
addx 1
addx 4
noop
addx 3
addx -2
addx 2
addx -11
noop
noop
noop