I'm trying to implement a program that returns the number of existing partitions of an integer n as part of an assignment. I wrote the code below, but it returns the wrong number (Partitions n returns the result of Partitions n-1). I don't get why this happens. I've tried many things and still don't know how to fix it, can anyone please help me?
[edited code out to avoid plagiarism from my colleagues :p]
m stands for the biggest number allowed in a partition, so partition(4,4) would be 5 = 4, 3+1, 2+2, 2+1+1, 1+1+1+1, but partition (4,1) would be 1 = 1+1+1+1. Execution: java Partitions n
else if (n <= 1 | m == 1)should probably beelse if (n <= 1 || m == 1)partitionas a function of two integersnandm(besides the memoization array, which also stores a function of two integers). I'm sure you had a good reason for this, but the rest of us don't know what the definition of yourpartition(n,m)is.