Skip to content

Commit 717c817

Browse files
committed
Haskell/Permutation: Add
1 parent c860af7 commit 717c817

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Haskell/Permutation/main.hs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Data.List
2+
main = putStrLn $ show output
3+
output = length$permutation2 "123456789"
4+
5+
permutation l@[x] = [l]
6+
permutation l@(h:t) = [_insert i sub|i<-[0..length l - 1],sub<-permutation t]
7+
where
8+
_insert i sub = left ++ h:right
9+
where
10+
(left,right) = splitAt i sub
11+
12+
permutation2 l@[x] = [l]
13+
permutation2 l = concat [_use i|i<-[1..length l]]
14+
where
15+
_use i = map (_head:) $permutation2 _tail
16+
where
17+
_head = l !! (i - 1)
18+
_tail = (init $take i l) ++ drop i l

0 commit comments

Comments
 (0)