Added partitionfunc from https://stackoverflow.com/questions/18503096/python-integer-partitioning-with-given-k-partitions