perm function

Produces the possible permutations of a set of nodes