Example #1
0
def testGreedys(items, maxUnits):
    '''
    :param items: list of Food
    :param maxUnits: >= 0
    :return:
    '''
    print('Use greedy by value to allocate', maxUnits, 'calories')
    testGreedy(items, maxUnits, Food.getValue)
    print('Use greedy by cost to allocate', maxUnits, 'calories')
    testGreedy(
        items, maxUnits, lambda x: 1 / Food.getCost(x)
    )  # 1/func so it sort by least expensive to most, Food.getCost sorts by most to least
    print('Use greedy by density to allocate', maxUnits, 'calories')
    testGreedy(items, maxUnits, Food.density)