示例#1
0
def largest_stock_payout(stocks):
    ''' Given a stream of stocks and their values, return the
    max stock payout that could be achieved by buying and selling
    at any ordered time.
    
    :param stocks: a stream of { 'stock-name': [stock-values] }
    :returns: The max payout of the stock stream
    '''
    return { name: largest_difference(vs)
       for name, vs in stocks.items() }
示例#2
0
def robot_battery_capacity(coordinates):
    ''' Given a stream of coordinates for a robot, return
    the maximum battery capacity needed to traverse the landscape
    if it only takes power to move up in the Z direction and we gain
    power by moving down in the Z direction.
    
    :param coordinates: a stream of (x,y,z) coordinates
    :returns: The max battery capacity needed to traverse
    '''
    return largest_difference((z for _,_,z in coordinates))