Created
October 13, 2019 23:51
-
-
Save aambrioso1/a06225e8cda50d831261fc75b2dfab12 to your computer and use it in GitHub Desktop.
streak.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find the length of the longest streak of positive values in a list of numbers | |
gains1 = [-2 ,-2, 1, 1] | |
def find_streak(values): | |
streakimg = False | |
streak = 0 | |
pos = 0 | |
start = 0 | |
finish = 0 | |
current_start = 0 | |
max_streak = 0 | |
for value in values: | |
if value > 0: | |
if streaking == False: | |
current_start = pos | |
streak += 1 | |
streaking = True | |
else: | |
if streak > max_streak and streaking == True: | |
max_streak = streak | |
start = current_start | |
finish = pos | |
streaking = False | |
streak = 0 | |
if streak > max_streak: | |
max_streak = streak | |
start = current_start | |
finish = pos | |
pos += 1 | |
return (max_streak, start, finish) | |
print(find_streak(gains1)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment