Initial Commit

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2021-12-06 18:42:38 +01:00
commit dc39e86744
28 changed files with 5861 additions and 0 deletions

1000
d2/input.txt Normal file

File diff suppressed because it is too large Load Diff

26
d2/part1.ts Normal file
View File

@@ -0,0 +1,26 @@
import fs from 'fs'
const input = fs.readFileSync(__dirname + '/input.txt').toString()
.split('\n')
var x = 0
var y = 0
for (const line of input) {
const splitted = line.split(' ')
const action = splitted[0]
const value = parseInt(splitted[1])
switch (action) {
case 'forward':
x += value
break
case 'up':
y -= value
break
case 'down':
y += value
break
}
}
console.log(`Result: ${x * y}`)

28
d2/part2.ts Normal file
View File

@@ -0,0 +1,28 @@
import fs from 'fs'
const input = fs.readFileSync(__dirname + '/input.txt').toString()
.split('\n')
var positionX = 0
var depth = 0
var aim = 0
for (const line of input) {
const splitted = line.split(' ')
const action = splitted[0]
const value = parseInt(splitted[1])
switch (action) {
case 'forward':
positionX += value
depth += aim * value
break
case 'up':
aim -= value
break
case 'down':
aim += value
break
}
}
console.log(`Result: ${positionX} * ${depth} = ${positionX * depth}`)