-
-
Save anonymous/8780ed09439a29f9bc51 to your computer and use it in GitHub Desktop.
Survivor S32 swap simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import itertools | |
import collections | |
Player = collections.namedtuple('Player', 'name tribe') | |
all_players = { | |
Player('Anna', 'beauty'), | |
Player('Aubry', 'brain'), | |
Player('Cydney', 'brawn'), | |
Player('Debbie', 'brain'), | |
Player('Joe', 'brain'), | |
Player('Julia', 'beauty'), | |
Player('Jason', 'brawn'), | |
Player('Michele', 'beauty'), | |
Player('Neal', 'brain'), | |
Player('Nick', 'beauty'), | |
Player('Peter', 'brain'), | |
Player('Scot', 'brawn'), | |
Player('Tai', 'beauty'), | |
} | |
all_tribes = {'brain', 'brawn', 'beauty'} | |
class Tribe: | |
def __init__(self, players): | |
self.players = players | |
self.counts = collections.Counter(p.tribe for p in self.players) | |
def has_majority(self, which): | |
return self.counts[which] > (len(self.players) // 2) | |
def has_plurality(self, which): | |
o1, o2 = all_tribes - {which} | |
return self.counts[which] > self.counts[o1] and self.counts[which] > self.counts[o2] | |
outcomes = [] | |
for players in itertools.combinations(all_players, len(all_players) // 2): | |
t1 = Tribe(players) | |
t2 = Tribe(all_players.difference(players)) | |
descr = [] | |
for t in sorted(all_tribes): | |
if t1.has_majority(t) or t2.has_majority(t): descr.append('{} majority'.format(t)) | |
elif t1.has_plurality(t) or t2.has_plurality(t): descr.append('{} plurality'.format(t)) | |
outcomes.append(' and '.join(descr) or 'none') | |
print('summary of {} possible (5, 5, 3) -> (6, 7) swap outcomes:'.format(len(outcomes))) | |
for outcome, count in collections.Counter(outcomes).most_common(): | |
print('{:40} {:6.2%} ({:4} ways)'.format(outcome, count / len(outcomes), count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment