Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Advent of Code 2019
# Advent of Code

## Instructions

1. `yarn`
2. `yarn test`
2. `yarn test:{2020|2021}`
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"author": "David Kane <david@osk.ltd>",
"license": "MIT",
"scripts": {
"test": "jest src/**/*.spec.js"
"test:2020": "jest src/2020/**/*.spec.js",
"test:2021": "jest src/2021/**/*.spec.js"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.7.4",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/2021/day1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const calculateIncreases = depths =>
depths.reduce((total, depth, i) => (i === 0 || depths[i - 1] >= depth ? total : total + 1), 0);

export const part1 = calculateIncreases;
export const part2 = depths => {
return calculateIncreases(
depths.reduce((windows, depth, i) => {
if (depths.length - 1 >= i + 2) {
windows.push(depth + depths[i + 1] + depths[i + 2]);
}

return windows;
}, [])
);
};
28 changes: 28 additions & 0 deletions src/2021/day1/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { part1, part2 } from ".";
import { getInput } from "../utils";

describe("Advent of Code - Day One", () => {
describe("Part One", () => {
it("should get 7", () => {
const input = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
expect(part1(input)).toBe(7);
});

it("should get 1832", async () => {
const input = (await getInput("day1")).split("\n").map(Number);
expect(part1(input)).toBe(1832);
});
});

describe("Part Two", () => {
it("should get 5", () => {
const input = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
expect(part2(input)).toBe(5);
});

it("should get 1858", async () => {
const input = (await getInput("day1")).split("\n").map(Number);
expect(part2(input)).toBe(1858);
});
});
});
Loading