Python Challenge level 18: “can you tell the difference?”
Level 18 is imaginative again.
Hint 1: it is more obvious that what you might think.
Fact 1: the main difference between images is brightness, we’ll go to brightness.html which is an almost twin page except for a new hint.
Hint 2: maybe consider deltas.gz.
After retrieving deltas.gz, we can go on with the script:
import gzip,difflib
deltas=gzip.GzipFile('deltas.gz', 'rb').read()
deltas=deltas.splitlines()
left,right,png=[],[],['','','']
for row in deltas:
left.append(row[:53])
right.append(row[56:])
diff = list(difflib.ndiff(left,right))
for row in diff:
bytes = [chr(int(byte,16)) for byte in row[2:].split()]
if row[0]=='-': png[0]+=''.join(bytes)
elif row[0]=='+': png[1]+=''.join(bytes)
elif row[0]==' ': png[2]+=''.join(bytes)
for i in range(3):
open('18_%d.png' %i,'wb').write(png[i])
The images created show the following texts:
18_0.png: fly
18_1.png: butter
18_2.png: ../hex/bin.html
That’s that. As allways, once you figure out the module you should be using makes the solution pretty straight forward. Level 19 is next.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.