Learn R Programming

arrangements (version 1.0.0)

partitions: Partitions generator

Description

This function partitions an non-negative interger into k parts or any part size. The results are in lexicographical or reversed lexicographical order.

Usage

partitions(n, k = NULL, descending = FALSE, type = "r")

Arguments

n

an non-negative integer to be partitioned

k

number of parts

descending

logical to use reversed lexicographical order

type

if "r", "c" or "l" is specified, the returned value would be a "row-major" matrix, a "column-major" matrix or a list respectively

See Also

ipartitions for iterating partitions and npartitions to calculate number of partitions

Examples

Run this code
# NOT RUN {
# all partitions of 6
partitions(6)
# reversed lexicographical order
partitions(6, descending = TRUE)

# fixed number of parts
partitions(10, 5)
# reversed lexicographical order
partitions(10, 5, descending = TRUE)

# column major
partitions(6, type = "c")
partitions(6, 3, type = "c")

# list output
partitions(6, type = "l")
partitions(6, 3, type = "l")

# zero sized partitions
dim(partitions(0))
dim(partitions(5, 0))
dim(partitions(5, 6))
dim(partitions(0, 0))
dim(partitions(0, 1))

# }

Run the code above in your browser using DataLab