d4
This commit is contained in:
@@ -4,20 +4,15 @@ import { readFile, sum } from "../../utils";
|
|||||||
let input = readFile(path.resolve(__dirname, 'input.txt'));
|
let input = readFile(path.resolve(__dirname, 'input.txt'));
|
||||||
|
|
||||||
const day1 = input.split('\n').filter(row => {
|
const day1 = input.split('\n').filter(row => {
|
||||||
let first = ""
|
const [firstElf, secondElf] = row.split(',').map(elf => elf.split('-').map(Number));
|
||||||
let second = ""
|
return (firstElf[0] - secondElf[0] >= 0 && secondElf[1] - firstElf[1] >= 0) || (secondElf[0] - firstElf[0] >= 0 && firstElf[1] - secondElf[1] >= 0);
|
||||||
|
|
||||||
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;
|
}).length;
|
||||||
|
|
||||||
console.log("Day1:", day1)
|
console.log("Day1:", day1)
|
||||||
|
|
||||||
|
const day2 = input.split('\n').filter(row => {
|
||||||
|
const [firstElf, secondElf] = row.split(',').map(elf => elf.split('-').map(Number));
|
||||||
|
return (firstElf[1] >= secondElf[0] && secondElf[1] >= firstElf[0]);
|
||||||
|
}).length;
|
||||||
|
|
||||||
// const day2 = input;
|
console.log("Day2:", day2);
|
||||||
|
|
||||||
// console.log("Day2:", day2);
|
|
||||||
Reference in New Issue
Block a user