Created
May 30, 2014 01:04
-
-
Save joshuacalloway/b472efd10a4882c61053 to your computer and use it in GitHub Desktop.
euler problem 19
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 euler.problem19) | |
(defn isleapyear?[yr] | |
(and (not (zero? (mod yr 100))) (= 0 (mod yr 4)))) | |
(def nonleapmonths [31 28 31 30 31 30 31 31 30 31 30 31]) | |
(def leapmonths [31 29 31 30 31 30 31 31 30 31 30 31]) | |
(defn getfirstmonthdays [yr] | |
(loop [index 0 | |
yr yr | |
firstdaysofmonths [1]] | |
(let [months (if (isleapyear? yr) leapmonths nonleapmonths) ] | |
(if (= 1188 index) | |
firstdaysofmonths | |
(recur (inc index) (+ yr (/ index 12)) (conj firstdaysofmonths (+ (peek firstdaysofmonths )(months (mod index 12))))))))) | |
(defn countsundaysonfirstonmonth [firstsunday firsdaysofmonth] | |
(count (filter #(or (= firstsunday %) (= firstsunday (mod % 7))) firsdaysofmonth)) ) | |
(countsundaysonfirstonmonth 4 (getfirstmonthdays 1901)) |
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 euler.problem19) | |
(defn isleapyear?[yr] | |
(and (not (zero? (mod yr 100))) (= 0 (mod yr 4)))) | |
(def nonleapmonths [31 28 31 30 31 30 31 31 30 31 30 31]) | |
(def leapmonths [31 29 31 30 31 30 31 31 30 31 30 31]) | |
(defn getfirstmonthdays [yr] | |
(loop [index 0 | |
yr yr | |
firstdaysofmonths [1]] | |
(let [months (if (isleapyear? yr) leapmonths nonleapmonths) ] | |
(if (= 1188 index) | |
firstdaysofmonths | |
(recur (inc index) (+ yr (/ index 12)) (conj firstdaysofmonths (+ (peek firstdaysofmonths )(months (mod index 12))))))))) | |
(defn countsundaysonfirstonmonth [firstsunday firsdaysofmonth] | |
(count (filter #(or (= firstsunday %) (= firstsunday (mod % 7))) firsdaysofmonth)) ) | |
(countsundaysonfirstonmonth 4 (getfirstmonthdays 1901)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment