Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# Gary Deer gdeer81

• San Antonio, TX
Created Nov 29, 2017
My over-engineered solution to a deceptively simple problem
View mind-games.clj
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; string s = "123456789" ;; int target = 100 ;; how many combinations of +/- give you the target int? ;; + and - can be inserted at any index ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;helper functions;;;;;; (defn str->vec "converts a string of consecutive numbers to a vector of individual numbers
Created Nov 29, 2017
lets print a triangle of stars for fun and profit
View make-stars.clj
 ;;;;;;;;;Given this yucky implementation: (defn print-row [num] (loop [iter 0]) (if (< iter num) (do (print "*") (recur (inc iter))) (println ""))) (defn print-a-triangle [num] (loop [iter 0]
Created Nov 17, 2017
Example of using :when qualifier in a for comprehension
View for-when.clj
 (set! *unchecked-math* false) (defn find-the-pairs [^long n] "takes an upper bound and returns all the pairs of numbers where (* x y) equals the sum of the entire collection without x and y (find-the-pairs 26) => [[15 21] [21 15]] " (let [^long coll-sum (/ (* n (inc n)) 2)] (for [^long i (range 1 (inc n)) ^long j (range 1 (inc n)) :when (= (- coll-sum i j) (* i j))]
Last active Aug 4, 2017
beginner performance bug
View findpairs.clj
 ;;this works until you pass in ridiculously large numbers ;; the for loop lets me try all of the numbers in the collection with each other (defn find-the-pairs [n] "takes an upper bound and returns all the pairs of numbers where (* x y) equals the sum of the entire collection without x and y (find-the-pairs 26) => [[15 21] [21 15]] " (let [coll (take n (iterate inc 1)) coll-sum (apply + coll)]
Last active Jul 22, 2017
View random-examples.clj
 (def inc-coll (partial map inc)) ;;#'user/inc-coll (inc-coll [4 5 6]) ;;(5 6 7) (def inc-coll-coll (partial map inc-coll)) ;;#'user/inc-coll-coll (inc-coll-coll [[1] [2]]) ;;((2) (3)) (inc-coll-coll [[1] 3]) ;;IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:542)
Created Jul 5, 2017
This set of rules causes all products to be hidden...but why?
View rules.cljs
 ;; Filtering ; product visible when no filter (define [:app :visible-product/id ?e] :- [:not [_ :product-filter/range]] [:not [_ :product-filter/category]] [[?e :product/name]]) ; product visible when filter active and price in range (define [:app :visible-product/id ?e] :- [[_ :product-filter/range ?range]]
Last active Jan 23, 2017 — forked from Deraen/spec-coercion.clj
Clojure.spec coercion test
View spec-coercion.clj
 (ns spec-test.core (:require [clojure.spec :as s])) (defn x-integer? [x] (if (integer? x) x (if (string? x) (try (Integer/parseInt x) (catch Exception e
Created Dec 12, 2016
every form in clojure.core that has four characters
View 4char_forms.txt
 *in* *ns* aget amap as-> aset atom bean byte case
Last active Dec 10, 2016
bouncey ball problem with 2 different solutions
View bounceyball.clj
 ;;compare the two approaches to solving the same problem ;;A child plays with a ball on the nth floor of a big building the height of which is known ;;(float parameter "h" in meters, h > 0) . ;;He lets out the ball. The ball rebounds for example to two-thirds ;;(float parameter "bounce", 0 < bounce < 1) ;;of its height. ;;His mother looks out of a window that is 1.5 meters from the ground ;;(float parameters window < h). ;;How many times will the mother see the ball either falling or bouncing in front of the window
Last active Aug 29, 2015
View gist:1a87b20b628b9becd7c8
 {% for product-partition in partitioned-products %} {% for product in product-partition %}

{{product.name}}

Price \${{product.price}}