Project Euler Problem 085
import Control.Monad import Data.List import Data.Ord -- 指定された幅、高さの長方形の個数 num :: (Enum a, Num a) => a -> a -> a num ww hh = sum [wl*hl| w<-[1..ww],h<-[1..hh],let wl=ww-w+1,let hl=hh-h+1] anslist :: [(Integer, (Integer, Integer))] anslist = [(num i j,(i,j)) | i<-[1..2011],j<-dropWhile (\x -> num i x < 1975000) $ takeWhile (\x -> num i x < 2025000) [1..]] -- (面積,長方形の個数,(縦,横)) ans :: (Integer, Integer, (Integer, Integer)) ans = (i*j,v,(i,j)) where (v,(i,j)) = head $ sortBy (comparing (abs.(subtract 2000000).fst)) $ anslist ans1 = let (a,_,_)= asn in a -- 2772 main :: IO () main = print ans1