Add day2 problem + solution
This commit is contained in:
parent
bde3a8968d
commit
1dd6a46bb6
4 changed files with 1125 additions and 0 deletions
33
day2/p1.nim
Normal file
33
day2/p1.nim
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue