# This program simulates flipping a coin 1000 times and then # calculates the longest run of consecutive heads or consecutive # tails. Is this number larger or smaller than you would have # guessed? import random def makestr(n): return [random.randint(0,1) for _ in xrange(n)] def maxmonochrome(s): maxsofar = 0 for i in range(len(s)): current = 0 for j in range(len(s[i:])): if s[i] == s[i+j]: current = j+1 if current > maxsofar: maxsofar = current else: break return maxsofar s = makestr(1000) print maxmonochrome(s)