This commit is contained in:
Adam Jeniski 2023-12-18 21:23:31 -05:00
parent 4446d015d9
commit 7eb6fd4f57

View File

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