Compare commits
2 Commits
0f796c32ae
...
7dfbdc1d62
Author | SHA1 | Date | |
---|---|---|---|
|
7dfbdc1d62 | ||
|
e96c5dad2b |
1
10/.gitignore
vendored
Normal file
1
10/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Main.class
|
48
10/Main.java
Normal file
48
10/Main.java
Normal 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
8
10/README.md
Normal 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
139
10/asm.txt
Normal 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
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Today's language: **gnu x86-64** (and alternatively **C**)
|
Today's language: **gnu x86-64** (and alternatively **C**)
|
||||||
|
|
||||||
Today I wanted to use OpenAI to solve the tasks using *gnu* **x86-64 assembly**, which I have never used before
|
Today I wanted to use ChatGPT to solve the tasks using *gnu* **x86-64 assembly**, which I have never used before
|
||||||
(I did some small things in [6502-asssembly](https://github.com/MatthiasQuintern/6502), so it wasn't all new).
|
(I did some small things in [6502-asssembly](https://github.com/MatthiasQuintern/6502), so it wasn't all new).
|
||||||
The prompt can be seen in `prompt.md`, the original file in `day4-by-ai.s`.
|
The prompt can be seen in `prompt.md`, the original file in `day4-by-ai.s`.
|
||||||
It did a lot of things right, however it also did a lot of things wrong:
|
It did a lot of things right, however it also did a lot of things wrong:
|
||||||
|
@ -9,7 +9,7 @@ The directories for each day contain my input file, my code and a README that sh
|
|||||||
|
|
||||||
## Recommended Days
|
## Recommended Days
|
||||||
These are the days with to most interesting code so far:
|
These are the days with to most interesting code so far:
|
||||||
1. **day 4**: *x86-64 assembly* with the help of OpenAI
|
1. **day 4**: *x86-64 assembly* with the help of ChatGPT
|
||||||
2. **day 6**: *html+javascript* [check it out here](https://quintern.xyz/advent22/day6.html)
|
2. **day 6**: *html+javascript* [check it out here](https://quintern.xyz/advent22/day6.html)
|
||||||
3. **day 7**: *awk+bash*
|
3. **day 7**: *awk+bash*
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user