{- Copyright 2014 Ken Takusagawa This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License along with this program. If not, see . -} module Main where { import Data.Ratio((%),Rational); main=mainw; mainw=do{ print$automated glen [4,25] 365; print$automated (s293/7) [5,8,10,97,146,293] 52; print$automated (glen/7) [5,8,10] 52; print$automated s293 [4,32,58,97,146,293] 365; print$automated glen [4,33,100] 365; print $efrac$glen; wana [5,8,10]; return(); }; pe = print.efrac; wana l=do{ let{v=cd [52] l 1;}; print v; print $ efrac $ (head v)%(product l)*7; }; -- computes the next number of the accum sequence. automated::Rational->[Integer]->Integer->Integer; automated r accum start = let { offset::Rational; offset=case mod(length accum)2 of{ 1->1; 0-> -1; }; i :: Integer; i = countDays start accum 1; actual = r*fromInteger(product accum); } in case offset*(fromInteger i-actual) of{ 0->0; diff->let{ next=floor$recip diff} in next }; maindays=do{ let{p38=(+1)$(*146)$(subtract 1)$(*97)$(+1)$(*58)$(subtract 1)$(*32)$(+1)$(*4)$365;}; print $ efrac $ recip $ (p38-)$ s293*4*32*58*97*146; -- 293 print p38; print $ efrac $ s293*4*32*58*97*146; let{p26=(subtract 1)$(*97)$(+1)$(*58)$(subtract 1)$(*32)$(+1)$(*4)$365;}; print$efrac$ recip$ (subtract p26)$s293*4*32*58*97; print p26; print $ efrac $ s293*4*32*58*97; let{p27=(+1)$(*58)$(subtract 1)$(*32)$(+1)$(*4)$365;}; print $ efrac $ recip$(p27-)$ s293*4*32*58; print p27; print $ efrac $ s293*4*32*58; let{p46=(subtract 1)$(*32)$(+1)$(*4)$365;}; print $ efrac $recip$(subtract p46)$ s293*4*32; print p46; print $ efrac $ s293*4*32; print $ efrac $ recip $(1461-)$ (*4) $ s293; -- print $ efrac$ recip $(1461-)$ (*4) $ glen; print$efrac$averageYear$ orian; -- greedy method applied to Gregorian. print$efrac$averageYear$ [4,33,100]; ana [4,32,58,97,146,293]; putStrLn "done"; }; s293 :: Rational; s293 = 365 + 71%293; glen::Rational; glen = 146097%400; efrac :: Rational -> (Integer, Rational); efrac improp = let {i :: Integer; i=round improp}in (i,improp- fromInteger i); ana :: [Integer] -> IO(); ana l = do { let {v=cd [365] l 1}; print v; let{p=product l}; print $ p; print $ efrac$ (head v)%p; }; -- gregORIAN orian :: [Integer]; orian = [4,25,4]; -- count days cd accum [] _ = accum; cd a (h:t) offset = cd (((head a)*h+offset):a) t (negate offset); countDays::Integer->[Integer]->Integer->Integer; countDays accum (h:t) offset = countDays (accum*h+offset) t (negate offset); countDays accum [] _ = accum; averageYear :: [Integer] -> Rational; averageYear leapPattern = (countDays 365 leapPattern 1) % (product leapPattern) }