Created
August 30, 2019 02:18
-
-
Save craftybones/f0eba869e3bcfdc47d4f6bfe2ebc6b2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 divisible-by? [x y] | |
(zero? (rem y x))) | |
(defn leap? [year] | |
(condp divisible-by? year | |
400 true | |
100 false | |
4 true | |
false)) | |
(def days [31 28 31 30 31 30 31 31 30 31 30 31]) | |
(def max-days {false days true (assoc-in days [1] 29)}) | |
(defn max-days-for [year month] | |
(get-in max-days [(leap? year) (dec month)] -1)) | |
(defn valid-date? [year month day] | |
(when-let [max-days-for-month (max-days-for year month)] | |
(<= 1 day max-days-for-month))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment