This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for x in range(1,101): | |
if x % 15 == 0: | |
print "FizzBuzz" | |
elif x % 3 == 0: | |
print "Fizz" | |
elif x % 5 == 0: | |
print "Buzz" | |
else: | |
print x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fizz-buzz [n] | |
(cond | |
(zero? (rem n 15)) "FizzBuzz" | |
(zero? (rem n 3)) "Fizz" | |
(zero? (rem n 5)) "Buzz" | |
:else n)) | |
(doseq [x (map fizz-buzz (range 1 101))] | |
(println x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def fizz-buzz | |
(->> (map vector (range 1 101) (repeat 100 "")) | |
(map (fn [[i s]] [i (if (zero? (rem i 3)) (str s "Fizz") s)])) | |
(map (fn [[i s]] [i (if (zero? (rem i 5)) (str s "Buzz") s)])) | |
(map (fn [[i s]] (if (= "" s) i s))))) | |
(doseq [x fizz-buzz] (println x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fizz-buzz [n] | |
(let [s (str (when (zero? (rem n 3)) "Fizz") | |
(when (zero? (rem n 5)) "Buzz"))] | |
(if (empty? s) n s))) | |
(doseq [x (map fizz-buzz (range 1 101))] | |
(println x)) |
OlderNewer