mirror of
https://github.com/Aviortheking/advent-of-code.git
synced 2025-06-07 16:29:55 +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:
parent
c0369d340a
commit
1060cb8a09
1
2015/day-1/input.txt
Normal file
1
2015/day-1/input.txt
Normal file
File diff suppressed because one or more lines are too long
8
2015/day-1/part-1.ts
Normal file
8
2015/day-1/part-1.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||||
|
.split('')
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Result:", input.reduce((p, c) => p + (c === '(' ? 1 : -1), 0)
|
||||||
|
)
|
19
2015/day-1/part-2.ts
Normal file
19
2015/day-1/part-2.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||||
|
.split('')
|
||||||
|
|
||||||
|
let v = 0
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
const item = input[i];
|
||||||
|
if (item === '(') {
|
||||||
|
v++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (--v < 0) {
|
||||||
|
console.log(
|
||||||
|
"Result:", i + 1
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
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)
|
||||||
|
)
|
1
2015/day-3/input.txt
Normal file
1
2015/day-3/input.txt
Normal file
File diff suppressed because one or more lines are too long
34
2015/day-3/part-1.ts
Normal file
34
2015/day-3/part-1.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||||
|
.split('') as Array<'<' | '>' | 'v' | '^'>
|
||||||
|
|
||||||
|
const poses: Array<`${number}:${number}`> = ['0:0']
|
||||||
|
|
||||||
|
let x = 0
|
||||||
|
let y = 0
|
||||||
|
|
||||||
|
for (const direction of input) {
|
||||||
|
switch (direction) {
|
||||||
|
case '>':
|
||||||
|
x++
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
x--
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
y--
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
y++
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const v: `${number}:${number}` = `${x}:${y}`
|
||||||
|
if (!poses.includes(v)) {
|
||||||
|
poses.push(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Result:", poses.length
|
||||||
|
)
|
49
2015/day-3/part-2.ts
Normal file
49
2015/day-3/part-2.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||||
|
.split('') as Array<'<' | '>' | 'v' | '^'>
|
||||||
|
|
||||||
|
const poses: Array<`${number}:${number}`> = ['0:0']
|
||||||
|
|
||||||
|
let x = 0
|
||||||
|
let y = 0
|
||||||
|
|
||||||
|
let roboX = 0
|
||||||
|
let roboY = 0
|
||||||
|
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
const direction = input[i]
|
||||||
|
let xChange = 0
|
||||||
|
let yChange = 0
|
||||||
|
switch (direction) {
|
||||||
|
case '>':
|
||||||
|
xChange++
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
xChange--
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
yChange--
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
yChange++
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let v: `${number}:${number}`
|
||||||
|
if (i % 2 === 0) { // santa
|
||||||
|
x += xChange
|
||||||
|
y += yChange
|
||||||
|
v = `${x}:${y}`
|
||||||
|
} else { // roboSanta
|
||||||
|
roboX += xChange
|
||||||
|
roboY += yChange
|
||||||
|
v = `${roboX}:${roboY}`
|
||||||
|
}
|
||||||
|
if (!poses.includes(v)) {
|
||||||
|
poses.push(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Result:", poses.length
|
||||||
|
)
|
16
2015/day-4/part-1.ts
Normal file
16
2015/day-4/part-1.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
|
||||||
|
// const input = "pqrstuv"
|
||||||
|
const input = "yzbqklnj"
|
||||||
|
|
||||||
|
let hash = ""
|
||||||
|
let i = 0
|
||||||
|
do {
|
||||||
|
hash = crypto.createHash('md5').update(input + ++i).digest('hex')
|
||||||
|
} while (!hash.startsWith('00000'))
|
||||||
|
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Result:", i, hash
|
||||||
|
)
|
16
2015/day-4/part-2.ts
Normal file
16
2015/day-4/part-2.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
|
||||||
|
// const input = "pqrstuv"
|
||||||
|
const input = "yzbqklnj"
|
||||||
|
|
||||||
|
let hash = ""
|
||||||
|
let i = 0
|
||||||
|
do {
|
||||||
|
hash = crypto.createHash('md5').update(input + ++i).digest('hex')
|
||||||
|
} while (!hash.startsWith('000000'))
|
||||||
|
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Result:", i, hash
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user