-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
37 lines (31 loc) · 922 Bytes
/
helpers.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
import fs from 'fs';
export function readFile(filename) {
return fs.readFileSync(filename, 'utf8');
}
export function parseLinesFromFile(filename) {
return parseFile(filename, '\n');
}
export function parseFile(filename, separator) {
const input = readFile(filename);
return input.split(separator);
}
export function writeAnswer(output, part = 1) {
console.log(`Final answer for part ${part}: `, output);
}
export function getAlphabet() {
return 'abcdefghijklmnopqrstuvwxyz';
}
export function drawGrid(grid, [tlX, tlY], [brX, brY], empty='.') {
for (let y=tlY; y<=brY; y++) {
let line = '';
for (let x=tlX; x<=brX; x++) {
const key = generateGridKey(x,y);
if (grid.has(key)) {
line = `${line}${grid.get(key)}`
} else {
line = `${line}${empty}`;
}
}
console.log(line);
}
}