-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_1.js
30 lines (25 loc) · 849 Bytes
/
4_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
const fileName = process.argv.slice(2)[0] || 'input.txt';
async function solve() {
const lineReader = require('readline').createInterface({
input: require('fs').createReadStream(fileName)
});
let containedCount = 0;
for await (const line of lineReader) {
const pair = line.split(',').map(rangeString => {
const rangeSplit = rangeString.split('-');
return {
start: Number(rangeSplit[0]),
end: Number(rangeSplit[1])
};
});
const former = pair[0];
const latter = pair[1];
// if first range is larger or equal to second or second range is larger or equal to first
if ((former.start <= latter.start && former.end >= latter.end)
|| (former.start >= latter.start && former.end <= latter.end)) {
containedCount++;
}
}
console.log(containedCount);
}
solve();