d4p1
This commit is contained in:
@@ -12,6 +12,6 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon src/2022/day3/index.ts"
|
"start": "nodemon src/2022/day4/index.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
src/2022/day4/example.txt
Normal file
6
src/2022/day4/example.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8
|
||||||
23
src/2022/day4/index.ts
Normal file
23
src/2022/day4/index.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import { readFile, sum } from "../../utils";
|
||||||
|
|
||||||
|
let input = readFile(path.resolve(__dirname, 'input.txt'));
|
||||||
|
|
||||||
|
const day1 = input.split('\n').filter(row => {
|
||||||
|
let first = ""
|
||||||
|
let second = ""
|
||||||
|
|
||||||
|
const [firstElf, secondElf] = row.split(',');
|
||||||
|
const [firstElfStart, firstElfEnd] = firstElf.split('-').map(Number);
|
||||||
|
const [secondElfStart, secondElfEnd] = secondElf.split('-').map(Number);
|
||||||
|
|
||||||
|
if (firstElfStart - secondElfStart >= 0 && secondElfEnd - firstElfEnd >= 0) return true;
|
||||||
|
if (secondElfStart - firstElfStart >= 0 && firstElfEnd - secondElfEnd >= 0) return true;
|
||||||
|
}).length;
|
||||||
|
|
||||||
|
console.log("Day1:", day1)
|
||||||
|
|
||||||
|
|
||||||
|
// const day2 = input;
|
||||||
|
|
||||||
|
// console.log("Day2:", day2);
|
||||||
1000
src/2022/day4/input.txt
Normal file
1000
src/2022/day4/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user