Add day2 problem + solution

This commit is contained in:
Joey Yakimowich-Payne 2021-12-03 20:16:57 -07:00
commit 1dd6a46bb6
4 changed files with 1125 additions and 0 deletions

33
day2/p1.nim Normal file
View file

@ -0,0 +1,33 @@
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()