Created
October 12, 2014 13:07
-
-
Save spiiin/1882d49b7f21961b7aee to your computer and use it in GitHub Desktop.
find longest sequence of 8-multiple values
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
import os | |
fn = os.path.expanduser("~/desktop/dump.bin") | |
with open(fn, "rb")as f: | |
d = f.read() | |
d = map(ord, d) | |
def repWord(d): | |
ans = [] | |
for x in xrange(0,len(d),2): | |
ans.append(d[x]*256+d[x+1]) | |
return ans | |
dd = repWord(d) | |
def findLongest(dd): | |
ans = [] | |
x = 0 | |
startAddr = 0 | |
curLen = 0 | |
while x < len(dd): | |
val = dd[x] | |
if val % 8 == 0: | |
curLen += 1 | |
else: | |
if curLen > 10: | |
ans.append((startAddr,curLen)) | |
startAddr = x | |
curLen = 0 | |
x+=1 | |
return ans | |
ans = findLongest(dd) | |
ans.sort(key=lambda v:v[1]) | |
for x in ans: | |
print x | |
(5247, 11040) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment