43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
const fs = require('fs');
|
|
|
|
const inputArray = fs.readFileSync('input.txt').toString().split("\n");
|
|
|
|
// Part One
|
|
let totalCount = 0;
|
|
|
|
for (i in inputArray) {
|
|
const contents = inputArray[i].split(",");
|
|
const range1 = contents[0].split("-");
|
|
const range2 = contents[1].split("-");
|
|
if (
|
|
(parseInt(range1[0]) >= parseInt(range2[0]) && parseInt(range1[1]) <= parseInt(range2[1]) && parseInt(range1[1]) <= parseInt(range2[1]))
|
|
||
|
|
(parseInt(range2[0]) >= parseInt(range1[0]) && parseInt(range2[1]) <= parseInt(range1[1]) && parseInt(range2[1]) <= parseInt(range1[1]))
|
|
) {
|
|
totalCount++
|
|
}
|
|
}
|
|
|
|
console.log(totalCount);
|
|
|
|
|
|
// Part Two
|
|
|
|
totalCount = 0;
|
|
|
|
for (i in inputArray) {
|
|
const contents = inputArray[i].split(",");
|
|
const range1 = contents[0].split("-");
|
|
const range2 = contents[1].split("-");
|
|
if (
|
|
(parseInt(range1[1]) >= parseInt(range2[0]) && parseInt(range1[1]) <= parseInt(range2[1]) && parseInt(range1[1]) <= parseInt(range2[1]))
|
|
||
|
|
(parseInt(range2[1]) >= parseInt(range1[0]) && parseInt(range2[1]) <= parseInt(range1[1]) && parseInt(range2[1]) <= parseInt(range1[1]))
|
|
) {
|
|
totalCount++
|
|
}
|
|
}
|
|
|
|
console.log(totalCount);
|
|
|