This commit is contained in:
Adam Jeniski 2024-12-15 19:08:38 -05:00
parent b2416724ed
commit f21409a574

View File

@ -2,12 +2,15 @@
(:require (:require
[clojure.string :as str])) [clojure.string :as str]))
(defn compose [& fs]
(apply comp (reverse fs))) ;; string/regex stuff
(defn split-whitespace [s] (defn split-whitespace [s]
(str/split s #"\s+")) (str/split s #"\s+"))
(defn split-on-double-newlines [s]
(str/split s #"\n\n"))
(defn get-match-groups [regex s] (defn get-match-groups [regex s]
(->> s (re-seq regex) (map rest))) (->> s (re-seq regex) (map rest)))
@ -18,10 +21,23 @@
(recur m (assoc res (.start m) (.group m))) (recur m (assoc res (.start m) (.group m)))
res))) res)))
;; general utils
(defn dbg [x] (defn dbg [x]
(println x) (println x)
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] (defn get-coords [list-of-lists]
(for [row (range (count list-of-lists)) (for [row (range (count list-of-lists))
col (range (count (get list-of-lists row)))] col (range (count (get list-of-lists row)))]
@ -38,9 +54,6 @@
(list el) (list el)
(drop idx coll))) (drop idx coll)))
(defn bool->binary [condition]
(if condition 1 0))
(defn mmap (defn mmap
"map map f coll" "map map f coll"
[f & colls] [f & colls]
@ -86,3 +99,19 @@
:last (first sorted-nums)} :last (first sorted-nums)}
(rest 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})