This file contains 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
-- Project Euler : Problem 18 | |
-- | |
-- 総当たり回避 | |
-- 三角形をひっくり返して,1つ下のリストに上のリストを足していく | |
triangle :: [[Int]] | |
triangle = [ | |
[75], | |
[95, 64], | |
[17, 47, 82], |
This file contains 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
import Data.List | |
-- [a]と[b]の全ての組み合わせをfで計算するzipWithみたいなもの | |
-- 例: zipWith' (*) [1,2,4,8] [1,3] | |
-- >> [1,3,2,6,4,12,8,24] | |
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] | |
zipWith' _ _ [] = [] | |
zipWith' _ [] _ = [] | |
zipWith' f (a:as) b = (map (f a) b) ++ (zipWith' f as b) |
This file contains 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
-- Project Euler : Problem 19 | |
isBissextile :: Int -> Bool | |
isBissextile y | |
| (y `mod` 400 /= 0) && (y `mod` 100 == 0) = False | |
| y `mod` 4 == 0 = True | |
| otherwise = False | |
-- y年m月の日数 | |
daysOfMonth :: Int -> Int -> Int |
This file contains 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
-- Project Euler : Problem 21 | |
import Data.List | |
-- [a]と[b]の全ての組み合わせをfで計算するzipWithみたいなもの | |
-- 例: zipWith' (*) [1,2,4,8] [1,3] | |
-- >> [1,3,2,6,4,12,8,24] | |
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] | |
zipWith' _ _ [] = [] | |
zipWith' _ [] _ = [] |
This file contains 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
-- Project Euler : Problem 22 | |
import Data.List | |
import Data.Char | |
import System.IO | |
alphabetScore :: Char -> Int | |
alphabetScore c = ord c - ord 'A' + 1 | |
nameScore :: String -> Int |
This file contains 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
-- Project Euler : Problem 23 | |
import Data.List | |
-- [a]と[b]の全ての組み合わせをfで計算するzipWithみたいなもの | |
-- 例: zipWith' (*) [1,2,4,8] [1,3] | |
-- >> [1,3,2,6,4,12,8,24] | |
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] | |
zipWith' _ _ [] = [] | |
zipWith' _ [] _ = [] |
This file contains 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
-- Project Euler : Problem 24 | |
-- 10の倍数 | |
multipleOf10 :: Int -> [Int] | |
multipleOf10 n = zipWith (^) (repeat 10) [0..n] | |
-- [a]の順列のInt番目 | |
permutaion :: (Eq a) => [a] -> Int -> [a] | |
permutaion [] _ = [] | |
permutaion [x] _ = [x] |
This file contains 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
-- Project Euler : Problem 25 | |
fibonacci :: [Integer] | |
fibonacci = 1:fib 1 2 | |
where fib a b = a:fib b (a + b) | |
main = print $ fst $ head $ dropWhile (\(x, y) -> y < 1000) $ | |
map (\(x, y) -> (x, length $ show $ y)) $ zip [1..] fibonacci | |
-- 4782 |
This file contains 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
-- Project Euler : Problem 29 | |
import Data.List | |
main = print $ length $ map head $ group $ sort [a^b | a <- [2..100], b <- [2..100]] | |
-- nubよりもmap head $ group の方が速かった | |
-- 9183 | |
-- ./dailycoding29 0.02s user 0.01s system 92% cpu 0.029 total |
This file contains 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
-- Project Euler : Problem 30 | |
import Data.Char | |
sumFactorialOf5 :: Int -> Int | |
sumFactorialOf5 = sum . map (^5) . map digitToInt . show | |
main = print $ sum [a | a <- [2..9^5*6], a == sumFactorialOf5 a] | |
-- 443839 |