aoc2021/day2/p1.nim
2021-12-03 20:16:57 -07:00

33 lines
554 B
Nim

import os
import std/strutils
type
Command = enum
Forward = "forward",
Down = "down",
Up = "up"
proc main() =
let fileName = paramStr(1)
var
horizontal = 0
depth = 0
for val in fileName.lines:
let
commandAndUnits = val.split(" ")
command = parseEnum[Command](commandAndUnits[0])
units = commandAndUnits[1].parseInt
case command
of Forward:
horizontal += units
of Up:
depth -= units
of Down:
depth += units
echo "Horizontal x Depth: ", horizontal * depth
main()