{-# LANGUAGE ScopedTypeVariables #-}
{-
Copyright 2011 Ken Takusagawa
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
" ++ info_today ++ "
" ++ nextp ++ "
\n" ++ (case (its_your_birthday today start) of { True-> "Also, happy birthday!
\n"; _ -> "" }) ++ (case offset of { 0-> "Bookmark this page to automatically recalculate whenever you open the bookmark.
\n"; _ -> "" }) ++ "\n" ++ "List all your Prime Days this year
" ++ "Back to Prime Day Calculator
" ++ "Leave comments on this blog post
" ++ "View source code
")))); }); getToday :: IO(Day); getToday = (getZonedTime >>= (return . localDay . zonedTimeToLocalTime)); make_day :: [](String) -> Day; make_day x = (case x of { [(yr ), (mo ), (dy )]-> (fromGregorian (read yr) (read mo) (read dy)); _ -> (error ("expecting [year,month,day], but got " ++ (show x))) }); do_prime_day :: Day -> IO(String); do_prime_day today = (return ("Happy Prime Day!You have lived a prime number of days, as of " ++ (show_day today) ++ ".")); find_from_composite :: Day -> Integer -> [](Integer) -> IO(String); find_from_composite today total factors = (do{ let { dm :: (Integer, Integer); dm = (divMod total (last factors));}; let { last_chapter_ago :: Integer; last_chapter_ago = (fst dm);}; let { last_chapter_start :: Day; last_chapter_start = (addDays (negate last_chapter_ago) today);}; (case (snd dm) of { 0-> (return ()); _ -> (error "did not divide cleanly") }); (return ("Happy Composite Day!
" ++ "As of today, " ++ (show_day today) ++ ", your life may be divided into exactly " ++ (show(last(factors))) ++ " chapters" ++ " of " ++ (show last_chapter_ago) ++ " days each." ++ "
The latest chapter started on " ++ (show_day last_chapter_start) ++ " and ended yesterday. The next chapter begins today!"));
});
plural :: Integer -> String;
plural i = (case i of {
1-> "";
_ -> "s"
});
next_prime_day :: Integer -> Day -> IO(String);
next_prime_day total today = (do{
np :: Integer <- (next_prime ((+) 1 total));
let { interval :: Integer; interval = ((-) np total);};
let { the_day :: Day; the_day = (addDays interval today);};
(return ("Your next Prime Day is " ++ (case interval of {
1-> "tomorrow";
_ -> ("in " ++ (show interval) ++ " days")
}) ++ ", on " ++ (show_day the_day) ++ ".
Your average spacing between Prime Days is " ++ (printf "%.4f" ((log(fromInteger(total))) :: Double)) ++ " days."); _ -> "" }))); }); create_html :: String -> String -> String; create_html title body = (unlines ["", ("
" ++ (concat((intersperse "
\n")((map show_day)(prime_days)))) ++ "
" ++ "Previous year - " ++ "Next year" ++ "
" ++ "\n