2015/2
This commit is contained in:
21
src/2015/2/1/index.ts
Normal file
21
src/2015/2/1/index.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export default async function runner(inputPath: string) {
|
||||||
|
const input = await Bun.file(inputPath).text();
|
||||||
|
|
||||||
|
let totalArea = 0;
|
||||||
|
|
||||||
|
input.split("\n").forEach(line => {
|
||||||
|
if (line.trim() === '') return;
|
||||||
|
|
||||||
|
const [l, w, h]: number[] = line.split("x") as unknown as number[];
|
||||||
|
|
||||||
|
if(!l || !w || !h) return;
|
||||||
|
const s1 = l*w;
|
||||||
|
const s2 = w*h;
|
||||||
|
const s3 = l*h;
|
||||||
|
|
||||||
|
const a = 2*s1 + 2*s2 + 2*s3 + Math.min(s1, s2, s3);
|
||||||
|
totalArea += a;
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(totalArea)
|
||||||
|
}
|
||||||
24
src/2015/2/2/index.ts
Normal file
24
src/2015/2/2/index.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
export default async function runner(inputPath: string) {
|
||||||
|
const input = await Bun.file(inputPath).text();
|
||||||
|
|
||||||
|
let totalArea = 0;
|
||||||
|
|
||||||
|
input.split("\n").forEach(line => {
|
||||||
|
if (line.trim() === '') return;
|
||||||
|
|
||||||
|
const [l, w, h]: number[] = line.split("x") as unknown as number[];
|
||||||
|
|
||||||
|
if(!l || !w || !h) return;
|
||||||
|
const c1 = 2*l+2*w;
|
||||||
|
const c2 = 2*w+2*h;
|
||||||
|
const c3 = 2*l+2*h;
|
||||||
|
|
||||||
|
|
||||||
|
const v = l*w*h;
|
||||||
|
|
||||||
|
const a = Math.min(c1, c2, c3) + v;
|
||||||
|
totalArea += a;
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(totalArea)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user