mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 07:23:18 -09:00
golf
This commit is contained in:
parent
4446d015d9
commit
7eb6fd4f57
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user