The following python scripts computes a permutation of outcomes for electoral success if Obama holds leaning blue states. I computed a total of 18 distinct electoral outcomes which lead to success, this actually could be reduced a bit, since there maybe set overlap if not including the state of Florida which automatically provides Obama a win if Obama holds every other projected state and leaning states are included. Just run script in Idle then type 'perms' or you could modify script for a list print
mapdict = {'va': 13, 'nh': 4, 'oh': 18, 'wi': 10, 'ia': 6, 'co': 9}
def checkset(pickmap, mappicks):
mpcheck = True
checkcont = 0
for mappick in mappicks:
checkcont = 0
for pick in pickmap:
if pick in mappick:
checkcont += 1
if checkcont == len(mappick):
return True
def checkmap(inmap, score):
mappicks = {}
mappick = []
newscore = score
for state in inmap:
newscore = score
newscore += mapdict[state]
mapcopy = inmap.copy()
del mapcopy[state]
if newscore < 27:
#print(state, len(mapcopy))
returnpicks = checkmap(mapcopy, newscore)
for pick in returnpicks:
#print (state, pick)
if returnpicks[pick] > 26:
cpick = list(pick)
rpick = cpick[0:len(cpick)]
rpick.append(state)
rtuppick = tuple(rpick)
if not checkset(rtuppick, mappicks):
mappicks[rtuppick] = returnpicks[pick]
else:
mappicks[tuple([state])] = newscore
return mappicks
perms = checkmap(mapdict, 0)
mapdict = {'va': 13, 'nh': 4, 'oh': 18, 'wi': 10, 'ia': 6, 'co': 9}
def checkset(pickmap, mappicks):
mpcheck = True
checkcont = 0
for mappick in mappicks:
checkcont = 0
for pick in pickmap:
if pick in mappick:
checkcont += 1
if checkcont == len(mappick):
return True
def checkmap(inmap, score):
mappicks = {}
mappick = []
newscore = score
for state in inmap:
newscore = score
newscore += mapdict[state]
mapcopy = inmap.copy()
del mapcopy[state]
if newscore < 27:
#print(state, len(mapcopy))
returnpicks = checkmap(mapcopy, newscore)
for pick in returnpicks:
#print (state, pick)
if returnpicks[pick] > 26:
cpick = list(pick)
rpick = cpick[0:len(cpick)]
rpick.append(state)
rtuppick = tuple(rpick)
if not checkset(rtuppick, mappicks):
mappicks[rtuppick] = returnpicks[pick]
else:
mappicks[tuple([state])] = newscore
return mappicks
perms = checkmap(mapdict, 0)
No comments:
Post a Comment