Skip to content

Instantly share code, notes, and snippets.

@oliverholworthy
Created December 12, 2017 11:37
Show Gist options
  • Save oliverholworthy/bed9178f7dee1e632eaecb13305fd6c6 to your computer and use it in GitHub Desktop.
Save oliverholworthy/bed9178f7dee1e632eaecb13305fd6c6 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<script>
window.klipse_settings = {
selector: '.language-klipse'
};
</script>
</head>
<body>
<pre>
<code class="language-klipse">
;; http://adventofcode.com/2017/day/11
;; Hex Ed
;; -----------------------------------------------------------------------------
(def move-dir {:nw [-1 1 0] :n [0 1 -1] :ne [1 0 -1]
:sw [-1 0 1] :s [0 -1 1] :se [1 -1 0]})
(defn manhattan [pos] (/ (reduce + (mapv #(Math/abs %) pos)) 2))
(defn positions [dirs] (reductions #(mapv + %1 %2) [0 0 0] dirs))
(def input-sample (map move-dir [:se :sw :se :sw :sw]))
;; -----------------------------------------------------------------------------
[
"Part One (fewest number of steps from origin after moves):"
(manhattan (apply mapv + input-sample))
"Part Two (furthest distance from origin during moves):"
(apply max (map manhattan (positions input-sample)))
"Positions (sequence of positions starting at origin after each move):"
(positions input-sample)
]
</code>
</pre>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment