mirror of
https://github.com/Aviortheking/advent-of-code.git
synced 2025-07-29 15:19:50 +00:00
28
2021/day-2/part-2.ts
Normal file
28
2021/day-2/part-2.ts
Normal 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}`)
|
Reference in New Issue
Block a user