Compare commits

...

2 Commits

Author SHA1 Message Date
Aelita4 9ac24ee0fa
10_2 2022-12-10 17:38:55 +01:00
Aelita4 2a025f9c1d
10_1 2022-12-10 17:17:45 +01:00
2 changed files with 177 additions and 0 deletions

37
day10/index.js Normal file
View File

@ -0,0 +1,37 @@
import { readFileSync } from "fs";
const input = readFileSync("instructions.txt", "utf-8");
let display = "";
function drawCRT(cycle, pointer) {
if((cycle - 1) % 40 === 0) display += "\n"
if(Math.abs(((cycle - 1) % 40) - pointer) <= 1) display += "#";
else display += ".";
}
let xRegister = 1;
let cycle = 0;
input.split('\n').forEach(line => {
const instruction = line.split(' ');
switch(instruction[0]) {
case "noop":
cycle++;
drawCRT(cycle, xRegister);
break;
case "addx":
cycle++;
drawCRT(cycle, xRegister);
cycle++;
drawCRT(cycle, xRegister);
xRegister += parseInt(instruction[1]);
break;
}
});
console.log(display)

140
day10/instructions.txt Normal file
View File

@ -0,0 +1,140 @@
addx 1
addx 4
addx -2
addx 3
addx 3
addx 1
noop
addx 5
noop
noop
noop
addx 5
addx 2
addx 3
noop
addx 2
addx 4
noop
addx -1
noop
addx 3
addx -10
addx -17
noop
addx -3
addx 2
addx 25
addx -24
addx 2
addx 5
addx 2
addx 3
noop
addx 2
addx 14
addx -9
noop
addx 5
noop
noop
addx -2
addx 5
addx 2
addx -5
noop
noop
addx -19
addx -11
addx 5
addx 3
noop
addx 2
addx 3
addx -2
addx 2
noop
addx 3
addx 4
noop
noop
addx 5
noop
noop
noop
addx 5
addx -3
addx 8
noop
addx -15
noop
addx -12
addx -9
noop
addx 6
addx 7
addx -6
addx 4
noop
noop
noop
addx 4
addx 1
addx 5
addx -11
addx 29
addx -15
noop
addx -12
addx 17
addx 7
noop
noop
addx -32
addx 3
addx -8
addx 7
noop
addx -2
addx 5
addx 2
addx 6
addx -8
addx 5
addx 2
addx 5
addx 17
addx -12
addx -2
noop
noop
addx 7
addx 9
addx -8
addx 2
addx -33
addx -1
addx 2
noop
addx 26
addx -22
addx 19
addx -16
addx 8
addx -1
addx 3
addx -2
addx 2
addx -17
addx 24
addx 1
noop
addx 5
addx -1
noop
addx 5
noop
noop
addx 1
noop
noop