Skip to content

Instantly share code, notes, and snippets.

(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)]
(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 +)))
@Heliosmaster
Heliosmaster / day5.clj
Created December 5, 2020 09:04
AOC 2020 - Day 5
(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 +))))
(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]
@Heliosmaster
Heliosmaster / oh-n0.clj
Last active February 13, 2019 20:12 — forked from skuro/readme.org
Meetup #111 solutions
(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))))
(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]})
@Heliosmaster
Heliosmaster / core.clj
Last active December 12, 2018 19:34 — forked from skuro/forkme.md
Advent of Clojure solutions
(ns adventclj.core)
;; By Samuel McHugh and Davide Taviani
(defn compute-next [prev]
(-> prev
(* 252533)
(rem 33554393)))
(defn index [r c]
(defn sha [data-bytes]
(apply str (map #(.substring (Integer/toString (+ (bit-and % 0xff) 0x100) 16) 1)
(.digest (MessageDigest/getInstance "sha1") (.getBytes data-bytes)))))
@Heliosmaster
Heliosmaster / haversine.clj
Created November 24, 2017 09:25 — forked from shayanjm/haversine.clj
Haversine Formula implementation in Clojure
; 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
find . -name "*.jpg" -exec convert -quality 75 {} /tmp/output/{} \;