2022-01-01 13:56:01 +01:00
|
|
|
import
|
|
|
|
../../adventofcode,
|
|
|
|
strutils,
|
|
|
|
strformat
|
|
|
|
|
|
|
|
let input = adventofcode.getInput(2021, 2)
|
2022-01-02 10:50:00 +01:00
|
|
|
let lines = input.splitLines()
|
2022-01-01 13:56:01 +01:00
|
|
|
|
|
|
|
var horizontalPosition = 0
|
|
|
|
var depth = 0
|
|
|
|
when defined(second):
|
|
|
|
var aim = 0
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
var command = line.split(" ")
|
|
|
|
case command[0]:
|
|
|
|
of "forward":
|
|
|
|
horizontalPosition += command[1].parseInt()
|
|
|
|
when defined(second):
|
|
|
|
depth += aim * command[1].parseInt()
|
|
|
|
of "up":
|
|
|
|
when defined(second):
|
|
|
|
aim -= command[1].parseInt()
|
|
|
|
else:
|
|
|
|
depth -= command[1].parseInt()
|
|
|
|
of "down":
|
|
|
|
when defined(second):
|
|
|
|
aim += command[1].parseInt()
|
|
|
|
else:
|
|
|
|
depth += command[1].parseInt()
|
|
|
|
|
|
|
|
echo fmt"Answer: {horizontalPosition * depth}"
|