Skip to content

Commit b6c4798

Browse files
committed
chore: migrate lots of my repos into the scratchpad
1 parent f514e6d commit b6c4798

File tree

327 files changed

+78824
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

327 files changed

+78824
-0
lines changed

adventofcode/.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"deno.enable": true,
3+
"deno.lint": true,
4+
"deno.unstable": true
5+
}

adventofcode/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
### Prerequisities
2+
3+
- `deno` is installed to the command line
4+
5+
### Running
6+
7+
- `cd` to the required day (number) and part (A|B)
8+
- `cd day3/partA`
9+
- Note some days are not split by part so just `cd day1`
10+
- Run `deno test --allow-read`
11+
- See command line for test output
12+
13+
### Results
14+
______
15+
16+
Day | A | B
17+
--- | --- | ---
18+
1 | ✓ | ✓
19+
2 | ✓ | ✓
20+
3 | ✓ | ✗
21+
4 | ✓ | ✗
22+
5 | ?| ?
23+
6 | ?| ?
24+
7 | ?| ?
25+
8 | ?| ?
26+
9 | ?| ?
27+
10 | ?| ?
28+
11 | ?| ?
29+
12 | ?| ?
30+
13 | ?| ?
31+
14 | ?| ?
32+
15 | ?| ?
33+
16 | ?| ?
34+
17 | ?| ?
35+
18 | ?| ?
36+
19 | ?| ?
37+
20 | ?| ?
38+
21 | ?| ?
39+
22 | ?| ?
40+
23 | ?| ?
41+
24 | ?| ?

adventofcode/day1/day1.test.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {
2+
beforeAll,
3+
describe,
4+
expect,
5+
it,
6+
run,
7+
} from "https://deno.land/x/tincan/mod.ts";
8+
import { depthMeasurer, slidingWindowMeasurer } from "./day1.ts";
9+
10+
const inputExample = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
11+
12+
describe("advent of code day 1 - part 1", () => {
13+
let depths: number[];
14+
beforeAll(async () => {
15+
const input = await Deno.readTextFile("depths.txt");
16+
const splitInput = input.split("\n");
17+
depths = splitInput.map(Number);
18+
});
19+
describe("example", () => {
20+
it("should count the number of times a depth measurement increases", () => {
21+
expect(depthMeasurer(inputExample)).toBe(7);
22+
});
23+
});
24+
25+
describe("exercise", () => {
26+
it("should count the number of times a depth measurement increases", () => {
27+
expect(depthMeasurer(depths)).toBe(1832);
28+
});
29+
});
30+
});
31+
32+
describe("advent of code day 1 - part 2", () => {
33+
let depths: number[];
34+
beforeAll(async () => {
35+
const input = await Deno.readTextFile("depths.txt");
36+
const splitInput = input.split("\n");
37+
depths = splitInput.map(Number);
38+
});
39+
describe("example", () => {
40+
it("should count the number of times a depth measurement increases", () => {
41+
expect(slidingWindowMeasurer(inputExample)).toBe(5);
42+
});
43+
});
44+
45+
describe("exercise", () => {
46+
it("should count the number of times a window measurement increases", () => {
47+
expect(slidingWindowMeasurer(depths)).toBe(1858);
48+
});
49+
});
50+
});
51+
52+
run();

adventofcode/day1/day1.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const depthMeasurer = (a: number[]): number => {
2+
let count = 0;
3+
for (let i = 0; i < a.length; i++) {
4+
if (a[i] > a[i - 1]) {
5+
count++;
6+
}
7+
}
8+
return count;
9+
};
10+
11+
export const slidingWindowMeasurer = (a: number[]): number => {
12+
let count = 0;
13+
for (let i = 0; i < a.length; i++) {
14+
if (a[i] + a[i + 1] + a[i + 2] < a[i + 1] + a[i + 2] + a[i + 3]) {
15+
count++;
16+
}
17+
}
18+
return count;
19+
};

0 commit comments

Comments
 (0)