-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10_2.js
47 lines (42 loc) · 1.22 KB
/
day10_2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
console.log('\n\n\n\n###################################3');
import { readLines } from 'https://deno.land/[email protected]/io/bufio.ts';
import { range } from 'https://deno.land/x/[email protected]/range.mjs';
import { slidingWindows } from 'https://deno.land/[email protected]/collections/mod.ts';
import count from 'https://deno.land/x/[email protected]/src/collection/count.ts';
import { writeAllSync } from 'https://deno.land/std/streams/conversion.ts';
let input = await Deno.readTextFile('./resources/input10_demo.txt');
input = await Deno.readTextFile('./resources/input10.txt');
// input = `noop
// addx 3
// addx -5`;
const prg = input
.trim()
.split('\n')
.map((s) => s.trim().split(' '));
let ops = [];
for (let [i, v] of prg) {
if (i === 'addx') {
ops.push(['noop']);
ops.push(['addx', parseInt(v, 10)]);
}
if (i === 'noop') ops.push(['noop']);
}
let s = [[], [], [], [], [], []];
const reg = { X: 1 };
let res = 0;
let cycle = 0;
for (let [i, v] of ops) {
const x = cycle % 40,
y = Math.floor(cycle / 40);
cycle++;
if (reg.X === x || reg.X === x - 1 || reg.X === x + 1) {
s[y].push('#');
} else {
s[y].push('.');
}
if (i === 'addx') reg.X += v;
}
console.log(
{ reg },
s.map((l) => l.join('')),
);