Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
reuse parsed data
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Dec 5, 2024
1 parent aba0bb9 commit acadd26
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions day1/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function solve2(data: number[][]): number {

if (import.meta.main) {
const data_path = new URL("input.txt", import.meta.url).pathname;
const data = await Deno.readTextFile(data_path);
console.log(solve1(parse(data)));
console.log(solve2(parse(data)));
const data = parse(await Deno.readTextFile(data_path));
console.log(solve1(data));
console.log(solve2(data));
}
6 changes: 3 additions & 3 deletions day1/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse, solve1, solve2 } from "./mod.ts";

Deno.test(async function testExample() {
const example_data_path = new URL("example.txt", import.meta.url).pathname;
const example_data = await Deno.readTextFile(example_data_path);
assertEquals(solve1(parse(example_data)), 11);
assertEquals(solve2(parse(example_data)), 31);
const example_data = parse(await Deno.readTextFile(example_data_path));
assertEquals(solve1(example_data), 11);
assertEquals(solve2(example_data), 31);
});
6 changes: 3 additions & 3 deletions day2/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function solve2(data: number[][]): number {

if (import.meta.main) {
const data_path = new URL("input.txt", import.meta.url).pathname;
const data = await Deno.readTextFile(data_path);
console.log(solve1(parse(data)));
console.log(solve2(parse(data)));
const data = parse(await Deno.readTextFile(data_path));
console.log(solve1(data));
console.log(solve2(data));
}
6 changes: 3 additions & 3 deletions day2/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse, solve1, solve2 } from "./mod.ts";

Deno.test(async function testExample() {
const example_data_path = new URL("example.txt", import.meta.url).pathname;
const example_data = await Deno.readTextFile(example_data_path);
assertEquals(solve1(parse(example_data)), 2);
assertEquals(solve2(parse(example_data)), 4);
const example_data = parse(await Deno.readTextFile(example_data_path));
assertEquals(solve1(example_data), 2);
assertEquals(solve2(example_data), 4);
});
6 changes: 3 additions & 3 deletions day4/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function solve2(data: string[]): number {

if (import.meta.main) {
const data_path = new URL("input.txt", import.meta.url).pathname;
const data = await Deno.readTextFile(data_path);
console.log(solve1(parse(data)));
console.log(solve2(parse(data)));
const data = parse(await Deno.readTextFile(data_path));
console.log(solve1(data));
console.log(solve2(data));
}
6 changes: 3 additions & 3 deletions day4/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse, solve1, solve2 } from "./mod.ts";

Deno.test(async function testExample() {
const example_data_path = new URL("example.txt", import.meta.url).pathname;
const example_data = await Deno.readTextFile(example_data_path);
assertEquals(solve1(parse(example_data)), 18);
assertEquals(solve2(parse(example_data)), 9);
const example_data = parse(await Deno.readTextFile(example_data_path));
assertEquals(solve1(example_data), 18);
assertEquals(solve2(example_data), 9);
});
6 changes: 3 additions & 3 deletions day5/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse, solve1, solve2 } from "./mod.ts";

Deno.test(async function testExample() {
const example_data_path = new URL("example.txt", import.meta.url).pathname;
const example_data = await Deno.readTextFile(example_data_path);
assertEquals(solve1(parse(example_data)), 143);
assertEquals(solve2(parse(example_data)), 123);
const example_data = parse(await Deno.readTextFile(example_data_path));
assertEquals(solve1(example_data), 143);
assertEquals(solve2(example_data), 123);
});

0 comments on commit acadd26

Please sign in to comment.