Added the four first days of 2015

Yes i'm gonna do them all !

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2021-12-07 17:03:46 +01:00
parent c0369d340a
commit 1060cb8a09
11 changed files with 1179 additions and 0 deletions

1000
2015/day-2/input.txt Normal file

File diff suppressed because it is too large Load Diff

17
2015/day-2/part-1.ts Normal file
View File

@@ -0,0 +1,17 @@
import fs from 'fs'
const input: Array<[number, number, number]> = fs.readFileSync(__dirname + '/input.txt').toString()
.split('\n')
.map((it) => it.split('x').map((v) => parseInt(v)) as [number, number, number])
function calc(item: [number, number, number]) {
const l = item[0]
const w = item[1]
const h = item[2]
const smallestSide = Math.min(l*w, w*h, h*l)
return 2*l*w + 2*w*h + 2*h*l + smallestSide
}
console.log(
"Result:", input.reduce((p, c) => p + calc(c), 0)
)

18
2015/day-2/part-2.ts Normal file
View File

@@ -0,0 +1,18 @@
import fs from 'fs'
const input: Array<[number, number, number]> = fs.readFileSync(__dirname + '/input.txt').toString()
.split('\n')
.map((it) => it.split('x').map((v) => parseInt(v)) as [number, number, number])
function calc(item: [number, number, number]) {
const l = item[0]
const w = item[1]
const h = item[2]
const largest = Math.max(l, w, h)
const tmp = l === largest ? w+h : w === largest ? l+h : l+w
return tmp + tmp + l*w*h
}
console.log(
"Result:", input.reduce((p, c) => p + calc(c), 0)
)