Skip to content

Instantly share code, notes, and snippets.

@hyone
hyone / hyone-4clojure-solution97.clj
Created July 3, 2011 18:46 — forked from anonymous/hyone-4clojure-solution97.clj
4clojure #97 - Pascal's Triangle
;; hyone's solution to Pascal's Triangle
;; https://4clojure.com/problem/97
(fn [n] (nth (iterate #(vec (map + (conj % 0) (cons 0 %))) '[1]) (dec n)))
@hyone
hyone / hyone-4clojure-solution88.clj
Created July 1, 2011 12:36 — forked from anonymous/hyone-4clojure-solution88.clj
4clojure #88 - Symmetric Difference
;; hyone's solution to Symmetric Difference
;; https://4clojure.com/problem/88
#(cond
(empty? %1) %2
(empty? %2) %1
:else (apply disj (apply conj %1 %2) (filter %1 %2)))
@hyone
hyone / hyone-4clojure-solution69.clj
Created June 30, 2011 14:20 — forked from anonymous/hyone-4clojure-solution69.clj
4clojure #69 - Merge with a Function
;; hyone's solution to Merge with a Function
;; https://4clojure.com/problem/69
(fn my-merge-with [f & maps]
(reduce
(fn [a b]
(reduce
(fn [x [k v]]
(assoc x k (if (b k) (f v (b k)) v)))
b a))
@hyone
hyone / hyone-4clojure-solution65.clj
Created June 29, 2011 05:06 — forked from anonymous/hyone-4clojure-solution65.clj
4clojure #65 - Black Box Testing
;; hyone's solution to Black Box Testing
;; https://4clojure.com/problem/65
(defn seq-type [coll]
(let [base (empty coll)]
(cond
(= base {}) :map
(= base #{}) :set
(= base '()) (if (reversible? coll) :vector :list))))