Skip to content

Instantly share code, notes, and snippets.

View rockBreaker's full-sized avatar
coffee

Guy Barlow rockBreaker

coffee
View GitHub Profile
@rockBreaker
rockBreaker / gist:8f58effcae101d252d85
Created July 10, 2014 14:34
horrible clojure code to sort a poker hand and check for a straight
;sorted hand vals
(defn sorted-hand-vals [hand]
(sort (keys (frequencies (map rank hand)))))
(defn low-ace-helper [hand]
(= hand (range (apply min hand) (inc (apply max hand)))))
;low ace straight?
(defn low-ace-straight? [hand]
(low-ace-helper (sort (replace {14 1} (sorted-hand-vals hand)))))
@rockBreaker
rockBreaker / gist:813085b1439e6b007408
Created July 7, 2014 14:26
scratchpad of shizzle
(comp first reverse) ; sick function get last
(comp second reverse) ;secondary sick function get second last
(defn my-fun [col] (nth col (- (count col) 2)))
(= (my-fun (list 1 2 3 4 5)) 4)
@rockBreaker
rockBreaker / gist:a8ee92b0aed48ce2c092
Created July 7, 2014 08:30
final books-string using interpose cos its better than my brain
(defn books->string
[books]
(cond (= (count books) 0) "No books."
(= (count books) 1) (str "1 book. " (apply book->string books) ".")
:else (str (count books) " books. " (apply str (interpose ". " (map book->string books))) ".")))
(defn author->string
[author]
(if
(contains? author :birth-year)
(str (:name author)'" (" (get author :birth-year) '" - "(get author :death-year) '")")
(str (:name author))))
@rockBreaker
rockBreaker / gist:28fd5863e7a007147a6a
Created July 6, 2014 14:44
pretty horrible author->string example
(defn author->string
[author]
(if
(contains? author :birth-year)
(str '"(" (get author :birth-year) '" - "(get author :death-year) '")")
(str (:name author)))
(ns structured-data)
(defn do-a-thing
[x]
(let [xplus (+ x x)]
(Math/pow xplus xplus)))
(defn spiff
[v]
(+ (get v 0 0) (get v 2 0)))
@rockBreaker
rockBreaker / gist:8311c67b8045357e3229
Last active August 29, 2015 14:03
crappy leap year thing
(defn divides?
[div n]
(= (mod n div) 0))
(defn guy-year2?
[year]
(if (divides? 400 year)
true
(if (divides? 100 year)
false
(defn leap-year?
[year]
(and (divides? 4 year)
(divides? 100 year)
(divides? 400 year)))
(defn divides?
[divisor n]
(if (= (mod n divisor) 0) true false))