10_1
This commit is contained in:
		
							parent
							
								
									7d835cdadf
								
							
						
					
					
						commit
						2a025f9c1d
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
		Loading…
	
		Reference in New Issue