Dec-03-2018, 08:38 AM
That code is just a small snippet of a 12,000 line code. I've always been reluctant to post code because how can you make someone understand an excerpt from a huge code base? I thought that code was reasonably well self-contained such that others might get off on it. It's mostly just a combinatorics problem.
Think of it this way. Suppose you have any number of blocks greater than 2. You number the blocks from 1 to n. You then have to fit the blocks into 2 categories and each block cannot appear twice in the same category. Further, the first block must always be in the first category or if it is in the second category then it must be the only block that is in that category. For each n, how many different ways are there to arrange the blocks? That's basically the problem that the code answers.
Think of it this way. Suppose you have any number of blocks greater than 2. You number the blocks from 1 to n. You then have to fit the blocks into 2 categories and each block cannot appear twice in the same category. Further, the first block must always be in the first category or if it is in the second category then it must be the only block that is in that category. For each n, how many different ways are there to arrange the blocks? That's basically the problem that the code answers.