mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:33:19 -09:00
organize
This commit is contained in:
parent
b2416724ed
commit
f21409a574
@ -2,12 +2,15 @@
|
||||
(:require
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn compose [& fs]
|
||||
(apply comp (reverse fs)))
|
||||
|
||||
;; string/regex stuff
|
||||
|
||||
(defn split-whitespace [s]
|
||||
(str/split s #"\s+"))
|
||||
|
||||
(defn split-on-double-newlines [s]
|
||||
(str/split s #"\n\n"))
|
||||
|
||||
(defn get-match-groups [regex s]
|
||||
(->> s (re-seq regex) (map rest)))
|
||||
|
||||
@ -18,10 +21,23 @@
|
||||
(recur m (assoc res (.start m) (.group m)))
|
||||
res)))
|
||||
|
||||
;; general utils
|
||||
|
||||
(defn dbg [x]
|
||||
(println x)
|
||||
x)
|
||||
|
||||
(defn log [msg]
|
||||
(spit "logs.txt" msg :append true))
|
||||
|
||||
(defn compose [& fs]
|
||||
(apply comp (reverse fs)))
|
||||
|
||||
(defn bool->binary [condition]
|
||||
(if condition 1 0))
|
||||
|
||||
;; alter collections
|
||||
|
||||
(defn get-coords [list-of-lists]
|
||||
(for [row (range (count list-of-lists))
|
||||
col (range (count (get list-of-lists row)))]
|
||||
@ -38,9 +54,6 @@
|
||||
(list el)
|
||||
(drop idx coll)))
|
||||
|
||||
(defn bool->binary [condition]
|
||||
(if condition 1 0))
|
||||
|
||||
(defn mmap
|
||||
"map map f coll"
|
||||
[f & colls]
|
||||
@ -86,3 +99,19 @@
|
||||
:last (first sorted-nums)}
|
||||
(rest sorted-nums))))
|
||||
|
||||
|
||||
;; Math things
|
||||
|
||||
(defn square [n] (* n n))
|
||||
(defn mean [a] (/ (reduce + a) (count a)))
|
||||
(defn standard-deviation
|
||||
[a]
|
||||
(let [mn (mean a)]
|
||||
(Math/sqrt
|
||||
(/ (reduce #(+ %1 (square (- %2 mn))) 0 a)
|
||||
(dec (count a))))))
|
||||
|
||||
(def arrow-char->dir {\> :right
|
||||
\v :down
|
||||
\< :left
|
||||
\^ :up})
|
||||
|
Loading…
x
Reference in New Issue
Block a user