diff --git a/2023/src/day18.clj b/2023/src/day18.clj index 6ec7f9a..0029a0d 100644 --- a/2023/src/day18.clj +++ b/2023/src/day18.clj @@ -1,28 +1,25 @@ (ns day18 (:require [core :refer [get-puzzle-input]] [clojure.string :as str])) -(def dir-map {\U [0 -1] \L [-1 0] \R [1 0] \D [0 1] - \3 [0 -1] \2 [-1 0] \0 [1 0] \1 [0 1]}) +(def dir-map {\U [-1 0], \L [0 -1], \R [0 1], \D [1 0]}) +(def hex-dir {\0 \R, \1 \D, \2 \L, \3 \U}) -(def input - (->> (get-puzzle-input 18) - (map #(let [[dir n hex-str] (str/split % #" ")] - [(dir-map (last dir)) - (parse-long n) - [(dir-map (last (drop-last hex-str))) - (Long/parseLong (subs hex-str 2 (- (count hex-str) 2)) - 16)]])))) +(def input (->> (get-puzzle-input 18) + (map #(let [[dir n hex-str] (str/split % #" ")] + [(dir-map (last dir)) + (parse-long n) + [(-> hex-str drop-last last hex-dir dir-map) + (-> hex-str + (subs 2 (- (count hex-str) 2)) + (Long/parseLong 16))]])))) ;; Shoelace / Pick's Algorithm, wtf?! (defn area [vs] - (reduce (fn [[pos ans] - [[x y] n]] - (let [pos' (+ pos - (* x n)) - ans' (+ ans - (* y n pos') - (/ n 2))] - [pos' ans'])) + (reduce (fn [[pos ans] [[row col] n]] + (let [pos (+ pos (* col n))] + [pos (+ ans + (* row n pos) + (/ n 2))])) [0 1] vs))