February 24th, 2013, 01:46 PM
Join Date: Feb 2013
Time spent in forums: 58 m 30 sec
Reputation Power: 0
Counting block combinations
I am given the following problem : A row measuring seven units in length has red blocks with a minimum length of three units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square. There are exactly seventeen ways of doing this.
How many ways can a row measuring fifty units in length be filled?
Here's what I've wrote so far in python:
cache = *51
solutions = 1
if(colorsize>blocksize): return solutions
if(cache[blocksize] != 0): return cache[blocksize]
for position in range(0,blocksize-colorsize+1):
for blocklength in range(colorsize,blocksize-position+1):
cache[blocksize] = solutions
Can someone please explain to me how this recursive function works please. I've been studying recursive function and I understood how it works.The problem is that I cannot understand how the speffic one works.