pythonchallenge Level 18

第18关地址:http://www.pythonchallenge.com/pc/return/balloons.html

账号:huge 密码:file

pythonchallenge Level 18

查看源码

pythonchallenge Level 18

获得提示信息

标题:can you tell the difference?

提示:it is more obvious that what you might think

两只鹅的亮度不一样,亮度brightness

打开http://www.pythonchallenge.com/pc/return/brightness.html

pythonchallenge Level 18

发现还是鹅(⊙o⊙)…

查看源码,得到提示信息maybe consider deltas.gz

打开https://www.pythonchallenge.com/pc/return/deltas.gz 得到下载文件deltas.gz

看样子是要处理deltas.gz

import gzip

file = open("deltas.txt",'wb')
f = gzip.GzipFile("deltas.gz")
data = f.read()
file.write(data)
file.close()

解压deltas.gz,得到一个deltas.txt,打开是两组数字

pythonchallenge Level 18

使用difflib找不同

import gzip, difflib


file = open("deltas.txt",'wb')
f = gzip.GzipFile("deltas.gz")
data = f.read()
file.write(data)
file.close()

file = open("deltas.txt",'r')
dataA = []
dataB = []
for line in file:
    dataA.append(line[:53]+"\n")
    dataB.append(line[56:])

diff = difflib.Differ().compare(dataA,dataB)

left = open("z_18left.png","wb")
right = open("z_18right.png","wb")
diff_data = open("z_18diff.png","wb")
same_data = open("z_18same.png","wb")
for line in diff:
    flag = line[0]
    line_data = line[1:].strip()
    if len(line_data)!=0:
        bs = bytes([int(o,16) for o in line_data.split(" ") if o])
        if flag == '-':
            # print("仅在左边出现",line_data) # - 仅在左边出现
            left.write(bs)
        elif flag == '+':
            # print("仅在右边出现",line_data)  # + 仅在右边出现
            right.write(bs)
        elif flag == '?':
            # print("存在疑问的",line_data) # ? 存在疑问的
            diff_data.write(bs)
        else:
            # print("相同的",line_data) # 相同的
            same_data.write(bs)

left.close()
right.close()
diff_data.close()
same_data.close()

得到四张图,其中

只在左边出现的生成了:fly

只在右边出现的生成了:butter

相同的生成了:../hex/bin.html

pythonchallenge Level 18pythonchallenge Level 18pythonchallenge Level 18

获得下一关地址:http://www.pythonchallenge.com/pc/hex/bin.html

账号:butter 密码:fly

上一篇:pythonchallenge Level 6


下一篇:gnuplot