Last active
May 24, 2024 10:10
-
-
Save alpox/fd2177a0f6c4ecaf7ffe0adc698b7aec to your computer and use it in GitHub Desktop.
FCC Challenge
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
(ns c26 | |
(:require [cljc.java-time.local-date :as ld] | |
[clojure.math :as math] | |
[clojure.test :refer [are testing]])) | |
(def years-bc 1166) | |
(def seasons ["Chaos" "Discord" "Confusion" "Bureaucracy" "The Aftermath"]) | |
(def weekdays ["Sweetmorn" "Boomtime" "Pungenday" "Prickle-Prickle" "Setting Orange"]) | |
(def apostles ["Mungday" "Mojoday" "Syaday" "Zaraday" "Maladay"]) | |
(def holidays ["Chaoflux" "Discoflux" "Confuflux" "Bureflux" "Afflux"]) | |
(defn ordinal [num] | |
(cond | |
(<= 11 num 13) "th" | |
(= (mod num 10) 1) "st" | |
(= (mod num 10) 2) "nd" | |
(= (mod num 10) 3) "rd" | |
:else "th")) | |
(defn discordian-date [date] | |
(let [day-idx (dec (ld/get-day-of-year date)) | |
leap? (ld/is-leap-year date) | |
corrected-day-idx (cond-> day-idx (and leap? (>= day-idx 60)) dec) | |
season-idx (math/floor-div corrected-day-idx 73) | |
year-idx (+ (ld/get-year date) years-bc) | |
weekday (get weekdays (mod corrected-day-idx 5)) | |
season (get seasons (mod season-idx 5)) | |
day-of-season (inc (mod corrected-day-idx 73))] | |
(str (format "%s, the %d%s day of %s in the YOLD %d" | |
weekday | |
day-of-season | |
(ordinal day-of-season) | |
season | |
year-idx) | |
(when (and (ld/is-leap-year date) (= 59 day-idx)) | |
(format ". Celebrate St. Tib's Day!")) | |
(when (= 50 day-of-season) | |
(format ". Celebrate %s!" (get holidays season-idx))) | |
(when (= 5 day-of-season) | |
(format ". Celebrate %s!" (get apostles season-idx)))))) | |
(testing "discordian-date" | |
(are [date expected] (= expected (discordian-date date)) | |
(ld/of 2010 7 22) | |
"Pungenday, the 57th day of Confusion in the YOLD 3176" | |
(ld/of 2012 2 28) | |
"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178" | |
(ld/of 2012 2 29) | |
"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib's Day!" | |
(ld/of 2012 3 1) | |
"Setting Orange, the 60th day of Chaos in the YOLD 3178" | |
(ld/of 2010 1 5) | |
"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!" | |
(ld/of 2011 5 3) | |
"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!" | |
(ld/of 2015 10 19) | |
"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment