2008-11-29から1日間の記事一覧

Problem 18

http://projecteuler.net/index.php?section=problems&id=18 --Haskell (Input data from STDIN), 20090101 process :: [Int] -> [Int] -> [Int] process f t = zipWith max (zipWith (+) f (init t) ++ [last t]) (head t : zipWith (+) f (tail t)) main =…

Problem 19

http://projecteuler.net/index.php?section=problems&id=19 --Haskell, 20090101 zeller :: Int -> Int -> Int zeller y m = if (y + y`div`4 - y`div`100 + y`div`400 + (13*m+8)`div`5 + 1) `mod` 7 == 0 then 1 else 0 main = print $ sum $ map (sum . …

Problem 20

http://projecteuler.net/index.php?section=problems&id=20 --Haskell, 20090104 import Char (digitToInt) import Sequence (factorial) main = print $ sum $ map digitToInt $ show $ factorial!!99 数列モジュールを使用.

Problem 21

http://projecteuler.net/index.php?section=problems&id=21 --Haskell, 20090101 import List (nub) divisors :: Int -> Int divisors n = sum $ 1 : concat [nub [x, n`div`x] | x<-takeWhile ((<=n).(^2)) [2..], n`mod`x==0] main = print $ sum [x | x<…

Problem 22

http://projecteuler.net/index.php?section=problems&id=22 --Haskell (Input data from STDIN), 20090101 import Char (ord, isAlpha) import List (sort) split :: String -> [String] split ['"'] = [] split xs = let (f, t) = span isAlpha $ dropWhil…