Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate numeric partitions for integer

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.

like image 430
Tomas Greif Avatar asked Jun 23 '26 20:06

Tomas Greif


1 Answers

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
like image 100
A5C1D2H2I1M1N2O1R2T1 Avatar answered Jun 26 '26 16:06

A5C1D2H2I1M1N2O1R2T1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!