-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3-1.js
50 lines (32 loc) · 811 Bytes
/
day3-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
41
42
43
44
45
46
// Advent of Code Day 3 Part 1
// Fred Martin, [email protected]
// Dec 5, 2020
// const readline = require('readline')
const lineByLine = require('n-readlines');
const fs = require('fs')
const fn = "day3-input.txt"
const liner = new lineByLine(fn);
var row=0; col=0;
var trees=0;
var width;
let line;
while (line = liner.next()) {
let mapstr = line.toString();
if (row == 0) {
row++;
continue;
}
width = mapstr.length;
col = col + 3;
console.log(mapstr + " row " + row + " col " + col);
let mapobj = mapstr.charAt(col % width);
if (mapobj == '#') {
trees++;
console.log("Tree!");
} else {
console.log(" no tree");
}
row++;
// console.log(line.toString());
}
console.log("Found " + trees + " trees in " + row + " rows.");