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 leap-year? | |
[year] | |
(and (divides? 4 year) | |
(divides? 100 year) | |
(divides? 400 year))) | |
(defn divides? | |
[divisor n] | |
(if (= (mod n divisor) 0) true false)) |
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 divides? | |
[div n] | |
(= (mod n div) 0)) | |
(defn guy-year2? | |
[year] | |
(if (divides? 400 year) | |
true | |
(if (divides? 100 year) | |
false |
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
(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))) |
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 author->string | |
[author] | |
(if | |
(contains? author :birth-year) | |
(str '"(" (get author :birth-year) '" - "(get author :death-year) '")") | |
(str (:name author))) |
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 author->string | |
[author] | |
(if | |
(contains? author :birth-year) | |
(str (:name author)'" (" (get author :birth-year) '" - "(get author :death-year) '")") | |
(str (:name author)))) |
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 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))) "."))) | |
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
(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) |
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
;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))))) |
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 straight? [hand] | |
(let [sorted-hand | |
(fn[hand] (sort (keys (frequencies (map rank hand))))) | |
range-helper | |
(fn [hand] (= hand (range (apply min hand) (inc (apply max hand))))) | |
low-ace | |
(fn [hand] (range-helper (sort (replace {14 1} (sorted-hand hand)))))] | |
(and |
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 value [hand] | |
(let [checkers #{[high-card? 0] [pair? 1] | |
[two-pairs? 2] [three-of-a-kind? 3] | |
[straight? 4] [flush? 5] | |
[full-house? 6] [four-of-a-kind? 7] | |
[straight-flush? 8]} | |
ita (fn [coll] (if ((first coll) hand) (second coll)))] | |
(apply max (filter (complement nil?) (map ita checkers))))) |
OlderNewer