-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.ts
More file actions
32 lines (26 loc) · 840 Bytes
/
Copy patha.ts
File metadata and controls
32 lines (26 loc) · 840 Bytes
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
31
32
import { assertEquals } from "https://deno.land/std@0.167.0/testing/asserts.ts";
function solution(input: string) {
const lines = input.split("\n").map((line) => line.split(","));
let sum = 0;
lines.forEach((line) => {
const [a, b] = line.map((range) => range.split("-").map((n) => Number(n)));
if (a[0] <= b[0] && a[1] >= b[1]) {
sum++;
} else if (b[0] <= a[0] && b[1] >= a[1]) {
sum++;
}
});
return sum;
}
Deno.test("example", () => {
const input = Deno.readTextFileSync("./04/example.txt");
const actual = solution(input);
const expected = 2;
assertEquals(actual, expected);
});
Deno.test("puzzle input", { ignore: false }, () => {
const input = Deno.readTextFileSync("./04/input.txt");
const actual = solution(input);
const expected = 644;
assertEquals(actual, expected);
});