Last active
August 29, 2015 14:19
-
-
Save takayahilton/a9a5a23011736adada60 to your computer and use it in GitHub Desktop.
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
{- | |
同じ大きさの5枚の正方形の板を一列に並べ | |
赤色,緑色,青色のペンキを用いて,隣り合う正方形どうしが異なる色となるように, | |
この掲示板を塗り分ける。ただし,塗り分ける際には,3色のペンキをすべて使わなければならないわけではなく,2色のペンキだけで塗り | |
分けることがあってもよいものとする。 | |
すべての塗り方を列挙してください。 | |
また、その場合の組み合わせが何通りあるかもカウントしてください。 | |
-} | |
module Main where | |
import Control.Monad | |
data Color= R|G|B deriving (Eq ,Show) | |
fill::[Color]->[[Color]] | |
fill list@(x:_) = do | |
color <- [R,G,B] | |
guard $ x /= color | |
return $ color:list | |
fillAll = [[R],[G],[B]] >>= (fill >=> fill >=> fill >=> fill ) | |
main :: IO () | |
main = do | |
putStr $ unlines $ map (\x -> unwords $ map (\y-> show y) x) fillAll | |
print $ length fillAll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test