This commit is contained in:
2022-12-04 16:33:24 +00:00
parent d68ac87ca9
commit 57f3bd59e1
4 changed files with 1030 additions and 1 deletions

View File

@@ -12,6 +12,6 @@
},
"scripts": {
"start": "nodemon src/2022/day3/index.ts"
"start": "nodemon src/2022/day4/index.ts"
}
}

View 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
View 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

File diff suppressed because it is too large Load Diff