-
Notifications
You must be signed in to change notification settings - Fork 0
/
day8.js
64 lines (47 loc) · 1.3 KB
/
day8.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var fs = require("fs");
let input = fs.readFileSync(__dirname +"/input.txt").toString().trim();
let width = 25, height = 6;
/*let data = [];
for (let i = 0; i < input.length; i++) {
let layer = Math.floor(i / (width * height));
let x = i % width;
let y = Math.floor(i / width);
if (data[layer] == undefined) {
data[layer] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
data[layer][Number(input.charAt(i))]++;
}
let min = Number.MAX_SAFE_INTEGER;
let index = -1;
for (let i = 0; i < data.length; i++) {
//console.log(data[i]);
if (data[i][0] < min) {
min = data[i][0];
index = i;
}
}
console.log((data[index][1] * data[index][2])+" "+index);*/
let data = [];
for (let i = 0; i < input.length; i++) {
let layer = Math.floor(i / (width * height));
let x = i % width;
let y = Math.floor((i - layer * width * height) / width);
if (data[x] == undefined) {
data[x] = [];
for (let j = 0; j < height; j++) {
data[x][j] = 2;
}
}
if (data[x][y] == 2)
data[x][y] = Number(input.charAt(i));
}
for (let y = 0; y < height; y++) {
let line = "";
for (let x = 0; x < width; x++) {
if (data[x][y] == 1)
line += "O";
else
line += " ";
}
console.log(line);
}