Solutions for day one
This commit is contained in:
parent
568be798e2
commit
a2292d251b
40
01/code.js
Normal file
40
01/code.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
const fs = require('fs');
|
||||
|
||||
const inputArray = fs.readFileSync('input.txt').toString().split("\n");
|
||||
|
||||
// Part One
|
||||
let increases = 0;
|
||||
let previous;
|
||||
|
||||
for(i in inputArray) {
|
||||
const value = parseInt(inputArray[i]);
|
||||
if (previous && value > previous) {
|
||||
increases++;
|
||||
}
|
||||
previous = value;
|
||||
}
|
||||
|
||||
console.log(increases);
|
||||
|
||||
|
||||
// Part Two
|
||||
increases = 0;
|
||||
previous = null;
|
||||
let a;
|
||||
let b;
|
||||
let c;
|
||||
|
||||
for(i in inputArray) {
|
||||
c = parseInt(inputArray[i]);
|
||||
total = a + b + c;
|
||||
if (a && b && c && total > previous) {
|
||||
increases++;
|
||||
}
|
||||
|
||||
a = b;
|
||||
b = c;
|
||||
previous = total;
|
||||
}
|
||||
|
||||
console.log(increases);
|
2000
01/input.txt
Normal file
2000
01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user