Skip to content

Instantly share code, notes, and snippets.

View mlb-'s full-sized avatar

Matthew Batema mlb-

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mlb- on github.
  • I am mlbatema (https://keybase.io/mlbatema) on keybase.
  • I have a public key whose fingerprint is 1188 2C08 1CDC 5C33 8E51 9D3F 1A93 0524 7F3F 9AB3

To claim this, I am signing this object:

@mlb-
mlb- / matching-substring-integer-counts.clj
Created September 11, 2017 17:51 — forked from featheredtoast/matching-substring-integer-counts.clj
Find the largest substring in which the number of integer elements is equal to number of non integer elements.
(defn find-subcoll-of-equal-int-nonint [coll]
(let [candidates (->> (range 2 (count coll) 2)
reverse
(map #(-> (partition % 1 coll)
(doto println)))
(reduce concat)
(filter (fn [candidate]
(let [{ints true
non-ints false} (group-by integer?
candidate)]
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(defn get-that-thing
"Bind the event handler for clicks and have it `put!` into a
channel."
[]
;; The implementation of this is left to the reader. Who will
;; probably skim swannodette's blog.
@mlb-
mlb- / *scratch*.clj
Last active October 21, 2016 01:09
Stupid recursive Clojure destructuring
(let [[[x1 y1] [x2 y2] :as [c1 c2 :as cs]] [[1 2] [3 4]]]
{:x1 x1
:y1 y1
:x2 x2
:y2 y2
:c1 c1
:c2 c2
:cs cs})
(def paper-feet
(comp #(apply + %)
(juxt (partial apply min)
(comp #(* 2 %)
(partial apply +)))
#(map (partial apply *) %)
#(partition 2 1 (take 1 %) %)
#(map (fn [x]
(Integer/parseInt x))
%)
(defn happy-numbers
[n]
(letfn [(next-happy [n]
(->> n
str
(map (comp int
#(Math/pow % 2)
read-string
str))
(reduce +)))]
@mlb-
mlb- / gol.clj
Created October 7, 2015 01:58 — forked from featheredtoast/gol.clj
4clojure GoL problem http://www.4clojure.com/problem/94
(defn gol
"Returns the next generation for a given game of life board"
[b]
(let [cells (for [x (range (count (first b)))
y (range (count b))]
[x y])
is-alive? (fn [[x y]]
(= \# (get-in b [x y])))
find-surrounding-live (fn [[cellx celly]]
(for [x (range (dec cellx) (+ 2 cellx))
(defn win-tic-tac-toe
[side b]
(let [b (->> b
flatten
(map-indexed vector))
check-win (fn
[[a b c d e f g h i]]
(->> [[a b c] [d e f] [g h i]
[a d g] [b e h] [c f i]
[a e i] [c e g]]
@mlb-
mlb- / longestsubstring.clj
Created October 1, 2015 01:07 — forked from featheredtoast/longestsubstring.clj
Just because I apparently can't think in an interview room.
(defn findSubstring
"Finds the longest substring"
[s]
(->> (range (dec (count s)) 0 -1)
(map (fn [i]
(->> s
(partition i 1)
(map clojure.string/join)
getSubstring)))
(drop-while nil?)
(defn fizzbuzz
[n]
(map-indexed (fn [n out]
(or (and (zero? (count out))
(inc n))
out))
(apply map (fn [& args]
(apply str args))
((apply juxt (map (fn [[mult sig]]
(fn [coll]