Home
Insert
Update snippet 'Very Fast Permutations'
Title
Description
I spent a lot of time this week profiling different permutation functions from various places on the internet. The following was by far the fastest:
Source code
module List = // From: http://stackoverflow.com/questions/286427/calculating-permutations-in-f // Much faster than anything else I've tested let rec permutations = function | [] -> seq [List.empty] | x :: xs -> Seq.collect (insertions x) (permutations xs) and insertions x = function | [] -> [[x]] | (y :: ys) as xs -> (x::xs)::(List.map (fun x -> y::x) (insertions x ys))
Tags
list
seq
sequences
collections
permutations
combinatorial
f#
list
seq
sequences
collections
permutations
combinatorial
f#
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update