Skip to main content
added 83 characters in body
Source Link

My first approach was to use NestWhile (edit: this is ugly! I did not know about the Fold[] function when I wrote this):

My first approach was to use NestWhile:

My first approach was to use NestWhile (edit: this is ugly! I did not know about the Fold[] function when I wrote this):

Tweeted twitter.com/#!/StackMma/status/231798694335369216
edited tags; edited tags
Link
deleted 1 characters in body
Source Link
linearExtensions[set_, po_] := 
    Module[{patterns},
        patterns = {___, #[[1]], ___, #[[2]], ___}& /@ po;
        First[NestWhile[First@NestWhile[{Cases[#[[1]], First[#[[2]]]], Rest[#[[2]]]}&,
            Rest[#[[2]]]} &, {Permutations[set], patterns}, Length[#[[2]]] > 0&]]0&]
    ]

My second approach, which turned out to be significantly slower, was to expand a set of rules from the partial order and use selectSelect on the list of permutations.

linearExtensions[set_, po_] := 
    Module[{patterns},
        patterns = {___, #[[1]], ___, #[[2]], ___}& /@ po;
        First[NestWhile[{Cases[#[[1]], First[#[[2]]]], 
            Rest[#[[2]]]} &, {Permutations[set], patterns}, Length[#[[2]]] > 0&]]
    ]

My second approach, which turned out to be significantly slower, was to expand a set of rules from the partial order and use select on the list of permutations.

linearExtensions[set_, po_] := 
    Module[{patterns},
        patterns = {___, #[[1]], ___, #[[2]], ___}& /@ po;
        First@NestWhile[{Cases[#[[1]], First[#[[2]]]], Rest[#[[2]]]}&,
            {Permutations[set], patterns}, Length[#[[2]]] > 0&]
    ]

My second approach, which turned out to be significantly slower, was to expand a set of rules from the partial order and use Select on the list of permutations.

Source Link
Loading