Skip to content

Instantly share code, notes, and snippets.

@rvlieshout
Created December 11, 2017 11:34
Show Gist options
  • Save rvlieshout/f19cc1b628631723d01affebcaba85fc to your computer and use it in GitHub Desktop.
Save rvlieshout/f19cc1b628631723d01affebcaba85fc to your computer and use it in GitHub Desktop.
AoC 2017, Day 11, Nim
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