Project Euler 99

http://projecteuler.net/index.php?section=problems&id=99


指数の計算をする代わりにlogの計算をする。

split :: [Char] -> Char -> [Char] -> [[Char]]
split [] d s = [s]
split (c:cs) d s | c == d    = s:(split cs d [])
                 | otherwise = split cs d (s ++ [c])

log_value :: [Char] -> Double
log_value s = (fromIntegral y) * (log (fromIntegral x)) where
        [s1,s2] = split s ',' []
        x = read s1 :: Int
        y = read s2 :: Int

greater x y = if snd x > snd y then x else y

main = do
    cs <- readFile "base_exp.txt"
    print (fst (foldr greater (0,0) (zip [1..] (map log_value (lines cs)))))