Created
April 20, 2011 03:43
-
-
Save oskimura/930289 to your computer and use it in GitHub Desktop.
Haskellだと小数点のmodをとるのが大変
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
| module Main where | |
| import Control.Applicative | |
| import Data.List | |
| import Data.Maybe | |
| import Data.Function (on) | |
| import Text.Printf | |
| 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 (==':') | |
| primes3 = 2:f [3] [3,5..] | |
| where f (x:xs) ys = let (ps, qs) = span (< x^2) ys | |
| in ps ++ f (xs ++ ps) [z | z <- qs, mod z x /= 0] | |
| input = lines <$> readFile "input.txt" | |
| rr :: (Read a, Num a) => String -> a | |
| rr = read | |
| timeAngle hh mm = a | |
| where | |
| a = (fromIntegral ha) + ma | |
| ha = (30 * (read hh)::Integer) `mod` 360 | |
| ma = (30 / 60) * ((read mm) :: Float) | |
| minutesAngle mm = (360 / 60) * (read mm) | |
| format text = d1 ++ if d2 == ".0" then "" else d2 | |
| where | |
| (d1,d2) = break (=='.') text | |
| f hh mm = ta ++ " " ++ ma | |
| where | |
| ta = format . show . timeAngle hh $ mm | |
| ma = format . show . minutesAngle $ mm | |
| main :: IO () | |
| main = | |
| do {ns <- lines<$>getContents | |
| ; mapM_ (\hour -> printf "%s" . (\ [hh,mm] -> f hh mm) . split $ hour) ns | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment