Counting block combinations

Page 1 of 1

0 Replies - 1717 Views - Last Post: 24 February 2013 - 12:04 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=313348&amp;s=4f83a00186fcf753cf5b83d91ccb3be6&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 loxa

Reputation: 0
• 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):
#print("P:",position,"S:",blocklength,"Res:",solutions)
solutions+=prob(blocksize-position-blocklength-1,colorsize)

#print("Blocksize:",blocksize-position-blocklength-1,"Colorsize:",colorsize,)
return solutions

print(prob(10,3))
```

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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }