View wpgtr-ch4.clj
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)) |
View wpgtr-ch5-pt1.clj
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) |
View wpgtr-ch5-pt2.clj
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))) |
View 4clojure-178.clj
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) |
View 4clojure-178-revised.clj
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) |
View fizzbuzz-a.py
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 |
View fizzbuzz-b.clj
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)) |
View fizzbuzz-c.clj
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)) |
View fizzbuzz-d.clj
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)) |
View pixelrain.mml
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
#TITLE Pixel Rain | |
#COMPOSER Quitasol | |
#PROGRAMER 2005 Dave Yarwood | |
#BANK-CHANGE 0,1 | |
#BANK-CHANGE 2,2 | |
@v2 = { 15 12 10 8 6 3 2 1 0 } | |
@v3 = { 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 } | |
@v0 = { 11 8 6 4 2 1 0 } | |
@v1 = { 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 } |
OlderNewer