import time import sys c=time.clock() f=open('in8_8.txt','r') a=[] a=f.readlines() count =0 rows=9 col=22 x=0 previous=1 for i in range(0,rows): if (x==col and i!=rows): previous=(rows-i)*col+1 count=count+previous-1 break; count=count+previous-1 for j in range(x,col): if(a[i][j]=="0" ): previous=j+1 break else: count+=1 x+=1 f1=open('out_28_8_8.txt','w') f1.write("No of 1s : "+str(count)) t=time.clock() f1.write("\nTime : " +str(t-c)) mem=sys.getsizeof(i)+sys.getsizeof(j)+sys.getsizeof(count)+sys.getsizeof(x)+sys.getsizeof(previous) f1.write("\nMemory :"+str(mem)) f1.close() f.close()