mirror of
https://github.com/Aviortheking/advent-of-code.git
synced 2025-08-04 17:32:00 +00:00
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:
1000
2015/day-2/input.txt
Normal file
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
17
2015/day-2/part-1.ts
Normal 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
18
2015/day-2/part-2.ts
Normal 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)
|
||||
)
|
Reference in New Issue
Block a user