-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.js
41 lines (35 loc) · 817 Bytes
/
help.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
import R from 'ramda';
import { promises as fs, stat } from 'fs';
import readline from 'readline';
const parseFile = R.compose(
R.map(R.split('')),
R.split('\n'),
String
);
const run = async () => {
const input = await fs.readFile('help.txt');
const parsed = parseFile(input);
console.log(parsed);
print(parsed);
let tot = 0;
for (let y = 1;y< parsed.length-1;y++) {
for (let x = 1;x< parsed[0].length-1;x++) {
if (parsed[y][x]=='#' &&
parsed[y][x-1] == '#' &&
parsed[y][x+1] == '#' &&
parsed[y-1][x] == '#' &&
parsed[y+1][x] == '#') {
parsed[y][x] = '0';
tot += (x*y);
}
}
}
print(parsed);
console.log(tot);
}
const print = (screen) => {
for (const row of screen) {
console.log(row.join(''))
}
}
run();