We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c860af7 commit 717c817Copy full SHA for 717c817
Haskell/Permutation/main.hs
@@ -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
10
+ (left,right) = splitAt i sub
11
12
+permutation2 l@[x] = [l]
13
+permutation2 l = concat [_use i|i<-[1..length l]]
14
15
+ _use i = map (_head:) $permutation2 _tail
16
17
+ _head = l !! (i - 1)
18
+ _tail = (init $take i l) ++ drop i l
0 commit comments