#!/usr/bin/python#open filefile1 = open('data.txt', 'r')file1.seek(0)#scan filefile = file1.read()file1.close()cols=60rows=35i = 0j = 0data = [ 0 ] * (cols*rows)data2 = [ 0 ] * (cols*rows)#copy data getting rid of line ends and spacerswhile j < cols*rows: if file[i]!="\n": data[j] = file[i] if file[i]!="*": if file[i]!=" ": data2[j] = int(file[i]) j+=1 else: i-=1 i+=2#process dataj = 0k = 0for j in range(0,rows): for k in range(0,cols): if data[cols*j+k]=="*": if k>0:#subtract one from left if data[cols*j+k-1]!="*": data2[cols*j+k-1]-=1 if j>0:#subtract one from left-up if data[cols*(j-1)+k-1]!="*": data2[cols*(j-1)+k-1]-=1 if j>0:#subtract one from up if data[cols*(j-1)+k]!="*": data2[cols*(j-1)+k]-=1 if k<(cols-1):#subtract one from up-right if data[cols*(j-1)+k+1]!="*": data2[cols*(j-1)+k+1]-=1 if k<(cols-1):#subtract one from right if data[cols*j+k+1]!="*": data2[cols*j+k+1]-=1 if j<(rows-1):#subtract one from right-down if data[cols*(j+1)+k+1]!="*": data2[cols*(j+1)+k+1]-=1 if j<(rows-1):#subtract one from down if data[cols*(j+1)+k]!="*": data2[cols*(j+1)+k]-=1 if k>0:#subtract one from down-left if data[cols*(j+1)+k-1]!="*": data2[cols*(j+1)+k-1]-=1for i in range(0,rows*cols): if data2[i]!=0: print "error in box", i