سؤال

Is there any implementation of integer partitioning in R?

For example for input 4 I would like to get 5 vectors:

4
3 , 1
2 , 2
2 , 1 , 1
1 , 1 , 1 , 1

There are implementations in Python, Erlang, Java, C, Perl, but I can't find anything in R.

هل كانت مفيدة؟

المحلول

Use the "partitions" package:

install.packages("partitions")
library(partitions)
parts(4)
#               
# [1,] 4 3 2 2 1
# [2,] 0 1 2 1 1
# [3,] 0 0 0 1 1
# [4,] 0 0 0 0 1
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top