-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_1.js
More file actions
31 lines (26 loc) · 772 Bytes
/
Copy pathday_1.js
File metadata and controls
31 lines (26 loc) · 772 Bytes
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
const fs = require('fs');
fs.readFile('./inputs/1.txt', 'utf8', (err, data) => {
if (err) throw err;
const numbers = data.split('\n')
.map(value => parseInt(value, 10))
let countNormal = 0
let countThreeMeasurements = 0
//STEP ONE
for(let i = 0; i < numbers.length - 1; i++) {
if (numbers[i] < numbers[i+1]) {
countNormal++
}
}
// STEP TWO
for(let i = 0; i < numbers.length - 2; i++) {
const windowA = numbers[i]+numbers[i+1]+numbers[i+2]
const windowB = numbers[i+1]+numbers[i+2]+numbers[i+3]
if (windowA < windowB) {
countThreeMeasurements++
}
}
console.log({
stepOne: countNormal,
stepTwo: countThreeMeasurements
});
})