Skip to content

Instantly share code, notes, and snippets.

View daveyarwood's full-sized avatar

Dave Yarwood daveyarwood

View GitHub Profile
(fn best-hand [card-strings]
(let [card-parser (fn [[s r]]
(let [suit ({\S :spade, \H :heart,
\D :diamond, \C :club} s)
rank (if (> (Character/digit r 10) -1)
(- (Character/digit r 10) 2)
({\T 8, \J 9,
\Q 10, \K 11, \A 12} r))]
{:suit suit, :rank rank}))
cards (map card-parser card-strings)
(fn best-hand [card-strings]
(let [card-parser (fn [[s r]]
(let [suit ({\S :spade, \H :heart,
\D :diamond, \C :club} s)
rank (if (> (Character/digit r 10) -1)
(- (Character/digit r 10) 2)
({\T 8, \J 9,
\Q 10, \K 11, \A 12} r))]
{:suit suit, :rank rank}))
cards (map card-parser card-strings)
; exs. 32-34:
; not applicable to Clojure (Ruby class inheritance)
; although this is somewhat similar to implementing protocols in records
; ex. 35:
(defn mail-them-a-kit [address]
(when-not (instance? address ex.Address)
(throw (IllegalArgumentException. "No Address object found.")))
(print (formatted address)))
; ex. 1:
(defn dr-chams-timeline [year]
(cond
(= year 1894)
"Born."
(<= 1895 year 1913)
"Childhood in Louisville, Winston Co., Mississippi."
(<= 1914 year 1919)
"Worked at a pecan nursery; punched a Quaker."
(<= 1920 year 1928)
@daveyarwood
daveyarwood / wpgtr-ch4.clj
Created February 21, 2014 01:35
why's poignant guide to ruby in clojure - chapter 4
; ex. 1:
(def blue-crystal 1)
(def leaf-tender 5)
; ex. 2:
(catch-a-star pipe)
; ex. 3:
(def captive-star (catch-a-star pipe))
@daveyarwood
daveyarwood / wpgtr-ch3.clj
Created January 27, 2014 00:37
why's (poignant) guide to ruby in clojure - chapter 3
; ex. 1:
(repeat 5 "Odelay!")
; ex. 2:
(when-not (re-find #"aura" "restaurant") (System/exit 0))
; ex. 3:
(map clojure.string/capitalize ["toast" "cheese" "wine"])
; ex. 4: