Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Python-3 Online

def findDollor(A, k, d, b):
    gain = k
    left = A[0] # current min of a interval
    initial = k # Dollar ready to be traded
    for i in range(1, len(A)):
        # Find the day the rate is not increasing
        if A[i] < A[i-1]:
            if left != A[i-1]:
                USD_if_traded = (initial-d)/left # USD to BDC
                USD_if_traded = (USD_if_traded-b)*A[i-1] # BDC to USD
                gain = max(gain, USD_if_traded)
                initial = gain # Use the newly gained amount to do the next transaction
            left = A[i] # start the next interval
    # One last interval left
    if left != A[len(A)-1]: 
        USD_if_traded = (initial-d)/left # USD to BDC
        USD_if_traded = (USD_if_traded-b)*A[len(A)-1] # BDC to USD
        gain = max(gain, USD_if_traded)
    return gain

A = [10000, 50, 60, 5, 9, 9, 9, 80, 30, 40, 40, 80, 85, 100, 150, 50, 80, 90, 200]
#A = [20, 20, 10]
d = 20
b = 10
k = 100
#table = findDollar(A, k, d, b)

USD_if_traded = (100-b)/10 # USD to BDC
USD_if_traded = (USD_if_traded-d)*100 # BDC to USD
print (USD_if_traded)



print (findDollor(A, k, d, b))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.