Florian Bouillon c0369d340a
Moved to 2021 Folder
Signed-off-by: Avior <github@avior.me>
2021-12-07 10:56:13 +01:00

28 lines
521 B
TypeScript

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}`)