【激突】関数型言語 VS オブジェクト指向言語
■ このスレッドは過去ログ倉庫に格納されています
0178デフォルトの名無しさん
2012/03/18(日) 07:28:55.36allPattern 0 _ = [[]]
allPattern _ [] = [[]]
allPattern n ns = [x:xs | x <- ns, xs <- allPattern (n-1) ns]
permutations n xs = filter checkPermu $ allPattern n xs
各要素(リスト)から先頭要素が偶数のもののみ抽出
filter (\x -> (even.head) x) $ allPattern 3 [1..3]
各要素のリストが昇順になっているもののみ抽出
filter (\(x:y:z:[]) -> x <= y && y <= z) $ allPattern 3 [1..3]
■ このスレッドは過去ログ倉庫に格納されています