Skip to content

Instantly share code, notes, and snippets.

@arnaudgeiser
Last active December 3, 2021 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudgeiser/b042c009c6bf33a25b352a3a57a94ae9 to your computer and use it in GitHub Desktop.
Save arnaudgeiser/b042c009c6bf33a25b352a3a57a94ae9 to your computer and use it in GitHub Desktop.
(ns advent-of-code.core
(:require [clojure.string :as str]))
(def content (slurp "/tmp/input"))
(defn compute [[direction nb]]
(let [nb' (Integer/parseInt nb)]
(condp = direction
"forward" [nb' 0]
"down" [0 nb']
"up" [0 (- nb')])))
(->> (str/split content #"\n")
(map #(str/split % #" "))
(map compute)
(reduce (fn [[x1 y1] [x2 y2]] [(+ x1 x2) (+ y1 y2)]) [0 0])
(apply *))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment