Previous Page Next Page Contents

combinat::permute -- permutations of a list

Introduction

combinat::permute(list) computes all the reorderings of the given list list.

combinat::permute(n) computes all the reorderings of the list [1,2,...,n].

Call(s)

combinat::permute(n)
combinat::permute(list)
combinat::permute(list,Duplicate)

Parameters

n - a nonnegative integer
list - a list

Options

Duplicate - The result may contain identical lists if there are duplicates in the given list list.

Returns

A list of type DOM_LIST containing every reordered list as an element.

Details

Option: Duplicate

Example 1

There are exactly two ways of ordering two elements.

>> combinat::permute([a,b]) 
                             [[a, b], [b, a]]

Example 2

An integer argument n is equivalent to the list of the first n integers.

>> combinat::permute(3) 
      [[2, 3, 1], [3, 2, 1], [1, 3, 2], [3, 1, 2], [1, 2, 3],
      
         [2, 1, 3]]

Example 3

By default, one gets all distinct reorderings.

>> combinat::permute([a,a,b]) 
                     [[a, b, a], [b, a, a], [a, a, b]]

Example 4

But if one wants to get a list with duplicated reordered entries, this is also possible.

>> combinat::permute([a,a,b],Duplicate) 
      [[a, b, a], [b, a, a], [a, b, a], [b, a, a], [a, a, b],
      
         [a, a, b]]

Example 5

Sets are not allowed as an argument.

>> combinat::permute({3,4}) 
      Error: argument must be a list or a non-negative integer! [com\
      binat::permute]

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000