Project Euler Problem 071
import Data.List import Data.Ratio -- a/b c/dの隣接項は(a+c)/(b+d) anr :: (Num t, Num t1) => (t, t1) -> (t, t1) -> (t, t1) anr (a,b) (c,d) = (a+c,b+d) an :: (Integer,Integer) -> (Integer,Integer) -> Ratio Integer -> Integer -> (Integer,Integer) an ll rr dest limit= imp ll rr ll where imp l r ans = if y>limit then ans else if (x%y)< dest then imp n r n else imp l n l where n@(x,y) = anr l r ans1 :: Integer ans1 = fst $ an (0,1) (1,1) (3%7) (10^(6::Integer)) -- 428570 main :: IO () main = print ans1