いろんな言語で宿題スレ
at TECH
[
2ch
|
▼Menu
]
■コピペモード
□
スレを通常表示
□
オプションモード
□このスレッドのURL
■項目テキスト
500:デフォルトの名無しさん 09/07/17 22:02:58 >>487 import Control.Monad (guard) import Data.List (permutations) t487 :: Int -> Int -> [[Int]] t487 a b = do xs@[c,d,e,f,g,h,i] <- permutations $ filter (\x -> and [x /= a, x /= b]) [1..9] let n = a+b+c guard $ and [d+e+f == n, g+h+i == n, a+d+g == n, b+e+h == n, c+f+i == n, a+e+i == n, c+e+g == n] return (a:b:xs) main = let a = t487 8 1 in if null a then putStrLn "Impossible" else mapM_ printer a where printer :: [Int] -> IO () printer [] = return () printer (a:b:c:xs) = print [a,b,c] >> printer xs 501:デフォルトの名無しさん 09/07/17 22:26:05 >>492 import Control.Monad (foldM) t492 :: Int -> IO (Int,Int) t492 n = foldM f (maxBound :: Int,minBound :: Int) [1..n] where f (a,b) _ = do s <- getLine let n = read s return (min a n, max b n) main = getLine >>= t492 . read >>= print
次ページ
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
レスジャンプ
mixiチェック!
Twitterに投稿
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch
4630日前に更新/314 KB
担当:undef