another implementation of the partition function