Skip to content

Commit

Permalink
switch to encrypted inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
merrywhether committed Dec 7, 2024
1 parent 7687509 commit b7e381d
Show file tree
Hide file tree
Showing 27 changed files with 316 additions and 159 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
input.txt
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,61 @@
[![](https://img.shields.io/badge/stars%20⭐-12-yellow)](#2024-results)
[![](https://img.shields.io/badge/days%20completed-6-red)](#2024-results)


[Advent of Code 2024](https://adventofcode.com/2024) using(/learning) Deno and Zed.

## Usage
## Setup

Create an `.env` file with the following content:

```sh
AOC_SESSION=your_session_cookie
INPUT_KEY=encryption_key
```

Per AoC guidelines, the inputs should not be stored in your repo so that people cannot reverse their generation strategies.
In order to preserve replayability, the input data is encrypted using the `INPUT_KEY` and stored that way instead.
After pulling a fresh copy of the repo, you can decrypt the input data by running the following command (assuming you have the correct key):

```sh
deno run decrypt
```

This was quite the rabbit hole to go down for this small payoff but whatever. 🤷‍♀️

Duplicate the `src/00` directory and rename it to the two-digit, one-indexed number of the day's challenge.
Paste the sample and input data into their respective files.
## Daily Workflow

Use the `dev` task to run the tests in watch mode against the sample data:
1. Duplicate the `src/00` directory and name the copy `src/XX` using the two-digit, one-indexed number of the day's challenge.
2. Copy-pasta the sample data into `sample.txt`.
3. Use the `dev` task to run the tests in watch mode against the sample data:

```sh
DAY=XX deno run dev
```

Use the `solve` task to output a solution based on the input data:
4. Use the `solve` task to output a solution based on the input data:

```sh
DAY=XX deno run solve
```

5. Add the solution and timing to the top of that day's `main.ts` for posterity.
6. Duplicate `test.ts` and name the copy `input.test.ts`. Change the target to `input` and update the expected values.
7. Commit with message `day XX` and push, triggering an update of the star/day progress tracking in this README.

## Other Tasks

Use the `test` task to run all tests against the sample data (mostly for CI):

```sh
deno run test
```

Use the `test:input` task to run all tests against the input data (mostly for validating changes to the repo structure):

```sh
deno run test:input
```

<!--- advent_readme_stars table --->
## 2024 Results

Expand Down
11 changes: 9 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"tasks": {
"decrypt": "deno run -ERW src/encrypt.ts --decrypt",
"dev": "deno test --watch -R src/$DAY/test.ts",
"input": "deno run -NEWR src/encrypt.ts --get=$DAY",
"solve": "deno run -R src/$DAY/main.ts",
"test": "deno test -R src"
"test": "deno test -R src/**/test.ts",
"test:input": "deno test -R src/**/input.test.ts"
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.8"
"@std/assert": "jsr:@std/assert@^1.0.8",
"@std/cli": "jsr:@std/cli@^1.0.8",
"@std/crypto": "jsr:@std/crypto@^1.0.3",
"@std/dotenv": "jsr:@std/dotenv@^0.225.3",
"@std/encoding": "jsr:@std/encoding@^1.0.5"
}
}
22 changes: 21 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file removed src/00/input.txt
Empty file.
11 changes: 9 additions & 2 deletions src/00/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

Deno.test("correct placeholder for sample", async () => {
const result = await main("sample");
const target = "sample";

Deno.test(`correct placeholder1 for ${target}`, async () => {
const result = await main(target);
assertEquals(result.text, "");
});

Deno.test(`correct placeholder2 for ${target}`, async () => {
const result = await main(target);
assertEquals(result.text, "");
});
2 changes: 2 additions & 0 deletions src/01/enput.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/01/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

const target = "input";

Deno.test(`correct distance for ${target}`, async () => {
const result = await main(target);
assertEquals(result.distance, 3246517);
});

Deno.test(`correct similarity for ${target}`, async () => {
const result = await main(target);
assertEquals(result.similiarity, 29379307);
});
2 changes: 1 addition & 1 deletion src/01/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

export async function main(target = "input") {
const dirpath = new URL(".", import.meta.url).pathname;
const text = await Deno.readTextFile(`${dirpath}/${target}.txt`);
const text = await Deno.readTextFile(`${dirpath}${target}.txt`);

const data = text.split("\n").reduce((agg, line) => {
const match = line.match(/^(\d+)\s+(\d+)$/);
Expand Down
10 changes: 6 additions & 4 deletions src/01/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

Deno.test("correct distance for sample", async () => {
const result = await main("sample");
const target = "sample";

Deno.test(`correct distance for ${target}`, async () => {
const result = await main(target);
assertEquals(result.distance, 11);
});

Deno.test("correct similarity for sample", async () => {
const result = await main("sample");
Deno.test(`correct similarity for ${target}`, async () => {
const result = await main(target);
assertEquals(result.similiarity, 31);
});
2 changes: 2 additions & 0 deletions src/02/enput.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/02/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

const target = "input";

Deno.test(`correct safe count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.safeLines, 660);
});

Deno.test(`correct dampended safe count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.dampenedSafeLines, 689);
});
10 changes: 6 additions & 4 deletions src/02/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

Deno.test("correct safe count for sample", async () => {
const result = await main("sample");
const target = "sample";

Deno.test(`correct safe count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.safeLines, 2);
});

Deno.test("correct dampended safe count for sample", async () => {
const result = await main("sample");
Deno.test(`correct dampended safe count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.dampenedSafeLines, 4);
});
2 changes: 2 additions & 0 deletions src/03/enput.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/03/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

const target = "input";

Deno.test(`correct quotient sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.quotientSum, 163931492);
});

Deno.test(`correct do quotient sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.doQuotientSum, 76911921);
});
8 changes: 5 additions & 3 deletions src/03/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

Deno.test("correct quotient sum for sample", async () => {
const result = await main("sample");
const target = "sample";

Deno.test(`correct quotient sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.quotientSum, 161);
});

Deno.test("correct quotient sum for sample with do", async () => {
Deno.test(`correct do quotient sum for sample with do`, async () => {
const result = await main("sample-do");
assertEquals(result.doQuotientSum, 48);
});
2 changes: 2 additions & 0 deletions src/04/enput.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/04/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

const target = "input";

Deno.test(`correct xmas count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.wordCount, 2718);
});

Deno.test(`correct x-mas count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.xCount, 2046);
});
10 changes: 6 additions & 4 deletions src/04/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

Deno.test("correct xmas count for sample", async () => {
const result = await main("sample");
const target = "sample";

Deno.test(`correct xmas count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.wordCount, 18);
});

Deno.test("correct x-mas count for sample", async () => {
const result = await main("sample");
Deno.test(`correct x-mas count for ${target}`, async () => {
const result = await main(target);
assertEquals(result.xCount, 9);
});
2 changes: 2 additions & 0 deletions src/05/enput.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/05/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

const target = "input";

Deno.test(`correct legal update middle page sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.legalUpdateMiddlePageSum, 5955);
});

Deno.test(`correct fixed update middle page sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.fixedUpdateMiddlePageSum, 4030);
});
10 changes: 6 additions & 4 deletions src/05/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { assertEquals } from "@std/assert";
import { main } from "./main.ts";

Deno.test("correct legal update middle page sum for sample", async () => {
const result = await main("sample");
const target = "sample";

Deno.test(`correct legal update middle page sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.legalUpdateMiddlePageSum, 143);
});

Deno.test("correct fixed update middle page sum for sample", async () => {
const result = await main("sample");
Deno.test(`correct fixed update middle page sum for ${target}`, async () => {
const result = await main(target);
assertEquals(result.fixedUpdateMiddlePageSum, 123);
});
2 changes: 2 additions & 0 deletions src/06/enput.txt

Large diffs are not rendered by default.

Loading

0 comments on commit b7e381d

Please sign in to comment.