Problem 191

completed February 23, 2012

Comments

I used the same method on this one as I did the problem that involved only increasing or decreasing numbers. I used a dictionary that held only the required information in it. Then with every new class day, I moved each grouping to its possible new locations.

Code

attendDict = {'O': 1, 'one L': 1, 'one A': 1, 'two A': 0, 'one L one A': 0, 'one L two A': 0}

i = 1
while i < 30:
	i += 1
	newDict = {'O': 0, 'one L': 0, 'one A': 0, 'two A': 0, 'one L one A': 0, 'one L two A': 0}
	newDict['O'] = attendDict['O'] + attendDict['one A'] + attendDict['two A']
	newDict['one L'] = attendDict['O'] + attendDict['one A'] + attendDict['two A'] + attendDict['one L one A'] + attendDict['one L two A'] + attendDict['one L']
	newDict['one A'] = attendDict['O']
	newDict['two A'] = attendDict['one A']
	newDict['one L one A'] = attendDict['one L']
	newDict['one L two A'] = attendDict['one L one A']
	attendDict = newDict.copy()
	
total = 0
for t in attendDict.itervalues():
	total += t

print total