0 Replies - 1679 Views - Last Post: 24 February 2013 - 12:04 PM Rate Topic: -----

#1 loxa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-December 12

Counting block combinations

Posted 24 February 2013 - 12:04 PM

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:

def prob(blocksize,colorsize):
    solutions = 1
    for position in range(0,blocksize-colorsize+1):
        #print('\n',"New position:",position)
        for blocklength in range(colorsize,blocksize-position+1):

    return 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.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1