2007-07-08から1日間の記事一覧

コインを減らす払い方

http://ja.doukaku.org/3/ import Data.List (notElem, nub, minimumBy, group) import Control.Monad (filterM, guard) pay 0 = [] pay n | n >= 500 = 500:pay (n - 500) | n >= 100 = 100:pay (n - 100) | n >= 50 = 50 :pay (n - 50) | n >= 10 = 10 :pa…

ピラミッドを作る

http://ja.doukaku.org/8/ pyramid n i | n == i = [replicate (2 * n - 1) '*'] | otherwise = let p = pyramid n (i + 1) in (f (reverse (f (head p)))):p where f [] = [] f (x:xs) = if x == ' ' then x:f xs else ' ':xs f n = mapM_ print $ pyramid n…