Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created April 4, 2011 05:48
Show Gist options
  • Select an option

  • Save oskimura/901184 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/901184 to your computer and use it in GitHub Desktop.
module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar
import Text.Printf
import Data.Maybe
splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy p [] = []
splitBy p xs = a : (splitBy p $ dropWhile p $ b)
where
(a, b) = break p xs
split :: String -> [String]
split = splitBy (=='.')
add18old = addGregorianYearsClip 18
yesOrNo x = if x then "YES" else "NO"
check (dd:mm:yy:_) = fromGregorianValid ((fromIntegral yy)+2000) mm dd
toDay (dd:mm:yy:_) = fromGregorian ((fromIntegral yy)+2000) mm dd
diff = diffDays
main = do { (as:bs:_) <- map (map ((+ 0) .read)) . map split . lines <$> getContents
; printf "%s\n" . yesOrNo . any (>= 0) $ [((toDay as) `diff` (add18old ys)) | ys <- catMaybes . map check . permutations $ bs]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment