Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created October 1, 2010 05:59
Show Gist options
  • Save oskimura/605806 to your computer and use it in GitHub Desktop.
Save oskimura/605806 to your computer and use it in GitHub Desktop.
module Euler19 where
import Control.Monad.List
euler19 = length [ (k,j,m,q) |
k <- [19 .. 20]
, j <- [0 .. 99]
, m <- [1 .. 12]
, q <- [1 .. 31]
, let n = (zeller k j m q)
, not(k==19) || j>0
, not(k==20) || j==0
, not (m == 9 || m == 4 || m==6 || m==11) || (q<=30)
, not ((leapYear (k*100+j)) && m==2) || (q<=29)
, ((leapYear (k*100+j)) && m==2) || (q<=28)
, n == 1 && q == 1
]
leapYear :: Integer -> Bool
leapYear y
| y `mod` 400 ==0 = True
| y `mod` 100 ==0 = False
| y `mod` 4 ==0 = True
| otherwise = False
zeller j k m q
| m < 3 = g j (k-1) (m+12) q
| otherwise = g j k m q
where
g j k m q = (q
+ ((((m+1)*26) `div` 10))
+ k
+ ((k `div` 4))
+ ((j `div` 4))
- 2*j) `mod` 7
floor' :: (Integral a) => a -> a
floor' = floor . fromIntegral
@oskimura
Copy link
Author

oskimura commented Oct 1, 2010

, not (P) || (Q)ね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment