-
Notifications
You must be signed in to change notification settings - Fork 0
/
day14_1.js
40 lines (35 loc) · 903 Bytes
/
day14_1.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
const { parse } = require('path');
const lineReader = require('readline').createInterface({
input: require('fs').createReadStream('input.txt'),
});
let data = [];
function tiltNorth(startingRow) {
for (let i = startingRow; i > 0; i--) {
for (let j = 0; j < data[0].length; j++) {
if (data[i][j] === 'O' && data[i - 1][j] === '.') {
data[i - 1][j] = 'O';
data[i][j] = '.';
}
}
}
}
lineReader.on('line', function (line) {
const lineArr = line.split('');
data.push(lineArr);
});
lineReader.on('close', function () {
for (let row = 1; row < data.length; row++) {
tiltNorth(row);
}
let count = 0;
let offset = data.length;
for (let row = 0; row < data.length; row++) {
for (let col = 0; col < data[0].length; col++) {
if (data[row][col] === 'Oå') {
count += offset;
}
}
offset--;
}
console.log(count);
});