In my second post of the semester, I think it only makes sense to talk about the second assignment, which is due at the end of the week.
Although question one sounds intimidating at first, there really is a lot you can prove about Odd Maximal Contiguous Ones Free Strings. I figured the best way to really understand what the question was getting at was to actually look at valid OMCOFS of varying length and try to discern a pattern between the length of the string and how many OMCOFS can be found.
To make this simple and repeatable, I quickly wrote the following small set of python functions:
def enum(n, s):
if(len(s)==n):
return [s]
else:
return enum(n, s+'0')+ enum(n, s+'1')
def is_valid_omcof(s, count, index):
if index == len(s):
return count % 2 == 0
elif (s[index] == '0' and count%2!=0):
return False
elif (s[index] == '0' and count%2==0):
return is_valid_omcof(s, 0, index +1)
else:
return is_valid_omcof(s, count+1, index+1)
def count_omcofs(n):
count = 0
for i in enum(n, ''):
if is_valid_omcof(i, 0, 0):
print i
count+=1
return "count = "+ str(count)
Using these three functions, I can generate all the possible strings of length n, and check which one of them are valid OMCOFS. I started running it with different lengths and I found an interesting result about the listing process of omcofs. Programmatically:
list_omcofs(size) == ['0'+omcof for omcof in list_omcofs(size-1)] +
['11'+omcof for omcof in list_omcofs(size-2)]
Reducing problems down to linearly easier problems is probably not that useful in terms of efficiency improvements but if it ever became desirable to express the list of omcofs of any length recursively as a combination of smaller length strings (e.g. due to a max size limit for list_omcofs() ), this would come in handy.