#%% total_rent = 5400 total_rent #%% values = pd.DataFrame({ # Room : 1 2 3 4 'Alice' : [30, 20, 0, 200 ], 'Bob' : [201, 32, 23, 0 ], 'Caitlin' : [31, 204, 29, 0 ], 'Dave' : [32, 26, 212, 0 ] }).T values #%% rental_harmony(total_rent,values) #%% import random total_rent = 0 def random_values(n,m=100) : letters = [chr(i + ord('A')) for i in range(0,n)] return pd.DataFrame({letters[i] : random.sample(range(0, m), n) for i in range(0,n)}).T #%% n=5 envy_free = True trials = 0 while envy_free and trials < 1000: if trials % 100 == 0 : print (str(trials) + ' trials completed')
total_rent = 5400 total_rent #%% #Have each housemate choose their least-favorite room, and assign it #a marginal value of zero dollars. Then, ask them to imagine living in #that room and paying slightly-less-than-average rent. How much extra #would they be willing to pay to move into each other room? #Enter those values here: values = pd.DataFrame({ # Room : 1 2 3 4 'Alice' : [30, 20, 0, 200 ], 'Bob' : [201, 32, 23, 0 ], 'Caitlin' : [31, 204, 29, 0 ], 'Dave' : [32, 26, 212, 0 ] }).T values #%% #Compute the (room,price) assignment that is maximally-far from #creating ency between any two housemates; this assignment #necessarily also maximizes the total utility of the group, #measured in marginal dollars: (solution,envies,envy_free) = rental_harmony(total_rent,values) solution #%% envies #%% envy_free