Skip to content

Instantly share code, notes, and snippets.

@bulv1ne
Created March 28, 2014 16:55
Show Gist options
  • Save bulv1ne/9837531 to your computer and use it in GitHub Desktop.
Save bulv1ne/9837531 to your computer and use it in GitHub Desktop.
numbers = map(int, open("num.txt").readlines())
filtered_list = []
for i in numbers:
# Check against last element of last list
if filtered_list and filtered_list[-1][-1] < i:
# Append element to last list
filtered_list[-1].append(i)
else:
# Create a new list
filtered_list.append([i])
# Only get the longuest list from filtered_list
longest_list = max(filtered_list, key=lambda l: len(l))
length = len(longest_list)
total = abs(sum(longest_list))
print "The longest sequence no in File is: %d and sum is %d"% (length, total)
fil=open("num.txt","r").readlines()
mylo=[]
for l in fil:
mylo.append(int(l))
long_seq,i,temp,max_seq_index=0,0,1,0
while i<len(mylo):
if long_seq>temp: temp,max_seq_index=long_seq,i-1
long_seq,j=1,i
while j!=len(mylo)-1 and mylo[j]<mylo[j+1] :
long_seq+=1
j+=1
i+=1
total=abs(sum(mylo[max_seq_index:max_seq_index+temp]))
print "The longest sequence no in File is: %d and sum is %d"% (temp,total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment