Created
December 11, 2017 11:34
-
-
Save rvlieshout/f19cc1b628631723d01affebcaba85fc to your computer and use it in GitHub Desktop.
AoC 2017, Day 11, Nim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sequtils | |
let | |
child_steps = toSeq(readLine(stdin).items) | |
var | |
cx, cy, furthest = 0 | |
proc dist(): int = max(abs(cx), abs(cy)) | |
for ch in child_steps: | |
if ch == 'n': cy += 1 | |
if ch == 's': cy -= 1 | |
if ch == 'e': cx += 1 | |
if ch == 'w': cx -= 1 | |
if ch == ',': furthest = max(furthest, dist()) | |
# handle last step | |
furthest = max(furthest, dist()) | |
echo "child is ", dist(), " steps away. Furthest was ", furthest, " steps." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment