This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn print-help [prefix cmds] | |
(println "Usage:" prefix "[COMMAND] [FLAGS]") | |
(println) | |
(println "Flags:") | |
(println (format " %s%-40s%s%s" log/blue "-v" log/nc "Verbose")) | |
(println (format " %s%-40s%s%s" log/blue "-h" log/nc "Help")) | |
(println) | |
(when (seq cmds) | |
(println "Commands:") | |
(doseq [[cmd {:keys [description]}] (sort-by first cmds)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(def example "abc\n\na\nb\nc\n\nab\nac\n\na\na\na\na\n\nb") | |
(defn part-1 [a] | |
(->> (str/split a #"\n\n") | |
(map #(str/replace % #"\n" "")) | |
(map set) | |
(map count) | |
(reduce +))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(defn binary-partition [b-string] | |
(let [bits (dec (count b-string))] | |
(->> b-string | |
(map-indexed (fn [i x] | |
(if (#{\B \R} x) | |
(Math/pow 2 (- bits i)) | |
0))) | |
(reduce +)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[java-time :as t]) | |
(defn at [t {:keys [hours minutes seconds]}] | |
(let [m (t/as-map t)] | |
(cond-> t | |
hours (t/plus (t/hours (- hours (:hour-of-day m)))) | |
minutes (t/plus (t/minutes (- minutes (:minute-of-hour m)))) | |
seconds (t/plus (t/seconds (- seconds (:second-of-minute m))))))) | |
(defn next-working-day [t] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns oh-n0.core) | |
(defn transpose [board] | |
(apply mapv vector board)) | |
(defn right-elems [board [i j]] | |
(drop (inc j) (get board i))) | |
(defn left-elems [board [i j]] | |
(reverse (take j (get board i)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns adventofcode.2018.day14) | |
(def day-input 846601) | |
(def day-input-vec [8 4 6 6 0 1]) | |
(set! *unchecked-math* true) | |
(def initial-state {:workers #{0 1} | |
:table [3 7]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns adventclj.core) | |
;; By Samuel McHugh and Davide Taviani | |
(defn compute-next [prev] | |
(-> prev | |
(* 252533) | |
(rem 33554393))) | |
(defn index [r c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sha [data-bytes] | |
(apply str (map #(.substring (Integer/toString (+ (bit-and % 0xff) 0x100) 16) 1) | |
(.digest (MessageDigest/getInstance "sha1") (.getBytes data-bytes))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Haversine formula | |
; a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) | |
; c = 2 ⋅ atan2( √a, √(1−a) ) | |
; d = R ⋅ c | |
; where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); | |
(defn haversine | |
"Implementation of Haversine formula. Takes two sets of latitude/longitude pairs and returns the shortest great circle distance between them (in km)" | |
[{lon1 :lng lat1 :lat} {lon2 :lng lat2 :lat}] | |
(let [R 6378.137 ; Radius of Earth in km |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -name "*.jpg" -exec convert -quality 75 {} /tmp/output/{} \; |
NewerOlder