updates and test w/ day 01 2021
This commit is contained in:
parent
cdb12dbc28
commit
888cd821ac
4
aoc
4
aoc
@ -16,7 +16,7 @@ else
|
||||
fi
|
||||
|
||||
exec_test() {
|
||||
bun test
|
||||
bun test "example.test.ts"
|
||||
}
|
||||
|
||||
exec_part() {
|
||||
@ -100,6 +100,7 @@ aoc() {
|
||||
mkdir -p $curr
|
||||
|
||||
cp -r template/* $curr
|
||||
cd $curr
|
||||
get_problem_input $(get_aoc_cookie) $year $day $AOCINPUT
|
||||
|
||||
echo "Initialized $curr"
|
||||
@ -118,6 +119,7 @@ aoc() {
|
||||
aoc init $year $day
|
||||
fi
|
||||
|
||||
cd $curr
|
||||
exec_test
|
||||
fi
|
||||
|
||||
|
26
aoc_2021/day-01/example.test.ts
Normal file
26
aoc_2021/day-01/example.test.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { main as part1 } from "./part_1";
|
||||
import { main as part2 } from "./part_2";
|
||||
|
||||
const example = `199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263`.split("\n");
|
||||
|
||||
test("part1", async () => {
|
||||
const answer = 7;
|
||||
const res = await part1(example);
|
||||
expect(res).toEqual(answer);
|
||||
});
|
||||
|
||||
test("part2", async () => {
|
||||
const answer = 5;
|
||||
const res = await part2(example);
|
||||
expect(res).toEqual(answer);
|
||||
});
|
0
aoc_2021/day-01/logs/.gitkeep
Normal file
0
aoc_2021/day-01/logs/.gitkeep
Normal file
7
aoc_2021/day-01/logs/out_1.txt
Normal file
7
aoc_2021/day-01/logs/out_1.txt
Normal file
@ -0,0 +1,7 @@
|
||||
=== COMPUTATION ===
|
||||
|
||||
|
||||
=== /COMPUTATION ===
|
||||
|
||||
=== ANSWER TO P1 ===
|
||||
1713
|
7
aoc_2021/day-01/logs/out_2.txt
Normal file
7
aoc_2021/day-01/logs/out_2.txt
Normal file
@ -0,0 +1,7 @@
|
||||
=== COMPUTATION ===
|
||||
|
||||
|
||||
=== /COMPUTATION ===
|
||||
|
||||
=== ANSWER TO P2 ===
|
||||
1734
|
26
aoc_2021/day-01/part_1.ts
Normal file
26
aoc_2021/day-01/part_1.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export const main = async (lines: string[]): Promise<number | string> => {
|
||||
return lines
|
||||
.map((x) => Number(x))
|
||||
.map((num, i, arr) => {
|
||||
if (i > 0 && arr[i - 1] < num) {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.filter((x) => x).length;
|
||||
};
|
||||
|
||||
const isrun = process.argv.length > 1 && process.argv[1] === import.meta.path;
|
||||
if (isrun) {
|
||||
const file = Bun.file("./problem.txt");
|
||||
const text = await file.text();
|
||||
const lines = text.split("\n");
|
||||
|
||||
console.log("=== COMPUTATION ===\n");
|
||||
|
||||
const answer = await main(lines);
|
||||
|
||||
console.log("\n=== /COMPUTATION ===\n");
|
||||
|
||||
console.log("=== ANSWER TO P1 ===");
|
||||
console.log(answer);
|
||||
}
|
30
aoc_2021/day-01/part_2.ts
Normal file
30
aoc_2021/day-01/part_2.ts
Normal file
@ -0,0 +1,30 @@
|
||||
export const main = async (lines: string[]): Promise<number | string> => {
|
||||
return lines
|
||||
.map((x) => Number(x))
|
||||
.map((_num, i, arr) => {
|
||||
if (i > arr.length - 3) return -1;
|
||||
return arr.slice(i, i + 3).reduce((acc, x) => acc + x, 0);
|
||||
})
|
||||
.map((num, i, arr) => {
|
||||
return i > 0 && arr[i - 1] < num;
|
||||
})
|
||||
.filter((x) => x).length;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
const isrun = process.argv.length > 1 && process.argv[1] === import.meta.path;
|
||||
if (isrun) {
|
||||
const file = Bun.file("./problem.txt");
|
||||
const text = await file.text();
|
||||
const lines = text.split("\n");
|
||||
|
||||
console.log("=== COMPUTATION ===\n");
|
||||
|
||||
const answer = await main(lines);
|
||||
|
||||
console.log("\n=== /COMPUTATION ===\n");
|
||||
|
||||
console.log("=== ANSWER TO P2 ===");
|
||||
console.log(answer);
|
||||
}
|
9
package.json
Normal file
9
package.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "aoc",
|
||||
"devDependencies": {
|
||||
"bun-types": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import { expect, test } from "bun:test";
|
||||
import { main as part1 } from "./part_1";
|
||||
import { main as part2 } from "./part_2";
|
||||
|
||||
// const example = ``;
|
||||
// const example = ``.split("\n");;
|
||||
const example = `1 2 3 4 5`.split(" ");
|
||||
|
||||
test("part1", async () => {
|
||||
@ -11,8 +11,8 @@ test("part1", async () => {
|
||||
expect(res).toEqual(answer);
|
||||
});
|
||||
|
||||
test("part2", async () => {
|
||||
const answer = 5 + 5;
|
||||
const res = await part2(example);
|
||||
expect(res).toEqual(answer);
|
||||
});
|
||||
//test("part2", async () => {
|
||||
// const answer = 5 + 5;
|
||||
// const res = await part2(example);
|
||||
// expect(res).toEqual(answer);
|
||||
//});
|
||||
|
@ -1,6 +1,4 @@
|
||||
export const main = async (
|
||||
lines: string[]
|
||||
): Promise<number | string> => {
|
||||
export const main = async (lines: string[]): Promise<number | string> => {
|
||||
const answer = lines.length;
|
||||
|
||||
// delete me!
|
||||
@ -9,6 +7,8 @@ export const main = async (
|
||||
return answer;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
const isrun = process.argv.length > 1 && process.argv[1] === import.meta.path;
|
||||
if (isrun) {
|
||||
const file = Bun.file("./problem.txt");
|
||||
|
@ -1,14 +1,9 @@
|
||||
export const main = async (
|
||||
lines: string[]
|
||||
): Promise<number | string> => {
|
||||
const answer = lines.length;
|
||||
|
||||
// delete me!
|
||||
console.log(lines);
|
||||
|
||||
return answer + 5;
|
||||
export const main = async (_lines: string[]): Promise<number | string> => {
|
||||
return 10;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
const isrun = process.argv.length > 1 && process.argv[1] === import.meta.path;
|
||||
if (isrun) {
|
||||
const file = Bun.file("./problem.txt");
|
||||
@ -24,4 +19,3 @@ if (isrun) {
|
||||
console.log("=== ANSWER TO P2 ===");
|
||||
console.log(answer);
|
||||
}
|
||||
|
||||
|
22
tsconfig.json
Normal file
22
tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"moduleDetection": "force",
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true,
|
||||
"composite": true,
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user