Partitions of a number
In mathematics there are still many open problems, but they are getting more and more bizarre to even be comprehended. One open problem that is easy to grasp is the following: given a positive integer N, let a partition of N be defined as a summation of positive numbers K = n1+n2+…+nn for 1 <= ni <= N, such that K = N. How many such K’s exist? In other words, how many different ways are there to express a number N as a summation of positive numbers? For example, the number 4 can be written as: 1) 1+1+1+1 2) 1+1+2 3) 1+3 4) 2+2 5) 4 Hence, there are a total of 5 different partitions of the number 4. What would be the formula of #Partitions(N)? No one knows… It is known to be exponential, though. Now, switching to algorithms, how do we write a code to generate all the partitions of a number? Code itself is very suitable for functional language: a base case when the target number reaches 0, followed by the induction where we change not only the starting...