-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_27.py
52 lines (43 loc) · 1.43 KB
/
level_27.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/env python
# coding=utf-8
# http://butter:fly@www.pythonchallenge.com/pc/hex/speedboat.html
# Difference between data and palette[data].
# @see https://www.w3.org/Graphics/GIF/spec-gif87.txt
import bz2
from io import BytesIO
import requests
from PIL import Image
PREFIX = "http://butter:fly@www.pythonchallenge.com/pc/hex/"
url = PREFIX + 'zigzag.gif'
def solve(something):
im = Image.open(BytesIO(something))
palette = im.getpalette()
palette_gray = palette[::3]
data1 = list(im.getdata())
im2 = Image.new("L", im.size, 255)
data2 = [255] * len(data1)
exceptions = []
expected = None
for i, p in enumerate(data1):
if expected is not None and p != expected:
exceptions.append(p)
data2[i] = 0
expected = palette_gray[p]
im2.putdata(data2)
im2.show()
# not key word
# busy 2
allwords = bz2.decompress(bytes(exceptions)).decode().split(' ')
import keyword
answer = []
for word in allwords:
if not keyword.iskeyword(word) and word != 'print' and word != 'exec' and word not in answer:
answer.append(word)
return ",".join(answer)
if __name__ == "__main__":
r = requests.get(url)
something = r.content
answer = solve(something)
# ../ring/bell.html, repeat, switch
print(answer)
# http://repeat:switch@www.pythonchallenge.com/pc/ring/bell.html