Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Permutations/F-Sharp/permutations-1.fs
Normal file
20
Task/Permutations/F-Sharp/permutations-1.fs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
let rec insert left x right = seq {
|
||||
match right with
|
||||
| [] -> yield left @ [x]
|
||||
| head :: tail ->
|
||||
yield left @ [x] @ right
|
||||
yield! insert (left @ [head]) x tail
|
||||
}
|
||||
|
||||
let rec perms permute =
|
||||
seq {
|
||||
match permute with
|
||||
| [] -> yield []
|
||||
| head :: tail -> yield! Seq.collect (insert [] head) (perms tail)
|
||||
}
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
perms (Seq.toList argv)
|
||||
|> Seq.iter (fun x -> printf "%A\n" x)
|
||||
0
|
||||
5
Task/Permutations/F-Sharp/permutations-2.fs
Normal file
5
Task/Permutations/F-Sharp/permutations-2.fs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let permutations xs =
|
||||
let rec insert x = function
|
||||
| [] -> [[x]]
|
||||
| head :: tail -> (x :: (head :: tail)) :: (List.map (fun l -> head :: l) (insert x tail))
|
||||
List.fold (fun s e -> List.collect (insert e) s) [[]] xs
|
||||
Loading…
Add table
Add a link
Reference in a new issue