Example #1
0
def tryExchange(arg1):
    global counter, n
    n = arg1
    counter = 0
    maxN= 100
    bestScore = (float('inf'), float('inf'))
    bestCost = []
    bestSoFar = []
    for i in range(1, maxN/2-4):
        for j in range(i+1, maxN/2-3):
            for h in range(j+1, maxN/2-2):
                for k in range(h+1, maxN/2-1):
                    for g in range(k+1, maxN/2):
                        tryDenom = [i,j,h,k, g]
                        cost = initCost(tryDenom)
                        exactCost = calcExactCost(tryDenom, cost)
                        exchangeCost = calcExchangeCost(exactCost, tryDenom)
                        if 0 not in exchangeCost:
                            #print "for ", tryDenom
                            #print "0 haitte nai", exchangeCost
                            result =winner.getAvgCost(exchangeCost)
                            if result[0] < bestScore[0]:
                                bestScore = result
                                bestSoFar = tryDenom
                                bestCost = exchangeCost
                                #print "bestCost!! %s" % bestCost
    print "With N=%s and best FOR EXCHANGE is %s with score: %s with avg # of coins:%s" %(n, bestSoFar, bestScore[0], bestScore[1])
Example #2
0
def nextBestExchange(lastWinner):
    global counter
    bestScore = (float('inf'), float('inf'))
    bestCost = []
    bestSoFar = []
    for i in xrange(1, maxN/2):
        if(i not in lastWinner):
            tryDenom = lastWinner+[i]
            cost = initCost(tryDenom)
            counter += 1
            exactCost = calcExactCost(tryDenom, cost)
            exchangeCost = calcExchangeCost(exactCost, tryDenom)
            if 0 not in exchangeCost:
                print "for ", tryDenom
                #print "0 haitte nai", exchangeCost
                result =winner.getAvgCost(exchangeCost)
                if result[0] < bestScore[0]:
                    bestScore = result
                    bestSoFar = tryDenom
                    bestCost = exchangeCost
                    print "bestCost!! %s" % bestCost
    print "With N=%s and %s denom, the best score is: %s with avg # of coins:%s with denomination: %s" %(n, len(lastWinner)+1, bestScore[0], bestScore[1],bestSoFar)
    print "With best cost %s"%bestCost
    return (bestSoFar, bestScore)