Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Last active April 12, 2018 16:12
Show Gist options
  • Save paulosuzart/73e3cc649c10717a733839c423a972e9 to your computer and use it in GitHub Desktop.
Save paulosuzart/73e3cc649c10717a733839c423a972e9 to your computer and use it in GitHub Desktop.
stocks = [(24, '2014-01-02'),
(23, '2014-01-03'),
(22, '2014-01-04'),
(26, '2014-01-05'),
(19, '2014-01-06'),
(20, '2014-01-08'),
(25, '2014-01-09'),
(24, '2014-01-10')]
def big_drop(s):
"""
Assumes s to be a non empty array of tuples
"""
assert len(s) > 0
last_peak = s[0]
biggest_drop = 0
for stock in s:
print("last peak: %s, biggest drop: %s" % (last_peak, biggest_drop))
last_peak_price = last_peak[0]
price = stock[0]
if last_peak_price >= price:
drop = last_peak_price - price
if drop > biggest_drop:
biggest_drop = drop
else:
last_peak = stock
return biggest_drop
if __name__ == '__main__':
b = big_drop(stocks)
print("The biggest price drop is: %s" % b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment