This file contains hidden or 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
from pymongo import MongoClient | |
from bson.code import Code | |
client = MongoClient() | |
db = client["dbname"] | |
col = db["collName"] | |
map = Code("function(){ if(this.fieldName){emit(this.fieldName,1);}}") | |
reduce = Code("function(key,values) {" |
This file contains hidden or 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
/*Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has N packets of candies and | |
would like to distribute one packet to each of the K children in the village (each packet may contain | |
different number of candies). To avoid a fight between the children, he would like to pick K out of N packets | |
such that the unfairness is minimized. | |
Suppose the K packets have (x1, x2, x3,….xk) candies in them, where xi denotes the number of candies in the | |
ith packet, then we define unfairness as | |
Sum [abs(X(i) - X(j))] 1<=i<j<=N |