This commit is contained in:
Aelita4 2022-12-10 17:17:45 +01:00
parent 7d835cdadf
commit 2a025f9c1d
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
2 changed files with 168 additions and 0 deletions

28
day10/index.js Normal file
View File

@ -0,0 +1,28 @@
import { readFileSync } from "fs";
const input = readFileSync("instructions.txt", "utf-8");
let xRegister = 1;
let cycle = 0;
let strengthSum = 0;
input.split('\n').forEach(line => {
const instruction = line.split(' ');
switch(instruction[0]) {
case "noop":
cycle++;
if((cycle + 20) % 40 === 0) strengthSum += (cycle * xRegister);
break;
case "addx":
cycle++;
if((cycle + 20) % 40 === 0) strengthSum += (cycle * xRegister);
cycle++;
if((cycle + 20) % 40 === 0) strengthSum += (cycle * xRegister);
xRegister += parseInt(instruction[1]);
break;
}
});
console.log(strengthSum)

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