Skip to content

Commit d198ae3

Browse files
author
Mustafa Hanif
committed
solution 2022-4
1 parent 4c14f97 commit d198ae3

File tree

2 files changed

+1026
-0
lines changed

2 files changed

+1026
-0
lines changed

2022-4.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var fs = require('fs');
2+
3+
const file = fs.readFileSync('input2022-4.txt', 'utf8');
4+
let lines = file.split('\n');
5+
6+
let count = 0;
7+
let dd = 0;
8+
for (let i = 0; i < lines.length; i++) {
9+
const r1l = lines[i].split(',')[0].split('-')[0];
10+
const r1h = lines[i].split(',')[0].split('-')[1];
11+
12+
const r2l = lines[i].split(',')[1].split('-')[0];
13+
const r2h = lines[i].split(',')[1].split('-')[1];
14+
15+
if (r1l >= r2l && r1h <= r2h || r2l >= r1l && r2h <= r1h) {
16+
console.log('overlap', r1l, r1h, r2l, r2h);
17+
count++;
18+
} else {
19+
console.log('no overlap', r1l, r1h, r2l, r2h);
20+
dd++;
21+
}
22+
}
23+
24+
console.log(count, dd);
25+
26+

0 commit comments

Comments
 (0)