-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_16.py
49 lines (39 loc) · 1.14 KB
/
level_16.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
#!/bin/env python
# coding=utf-8
# http://huge:file@www.pythonchallenge.com/pc/return/mozart.html
# Let me get #FF00FF straight.
from io import BytesIO
from itertools import groupby
import requests
from PIL import Image
PREFIX = "http://huge:file@www.pythonchallenge.com/pc/return/"
url = PREFIX + 'mozart.gif'
def solve(something):
im = Image.open(BytesIO(something))
width, height = im.size
p = list(im.getdata())
sample = p[:width]
maxlen = 0
for (k, v) in groupby(sample):
curlen = len(list(v))
if curlen > maxlen:
maxlen = curlen
separator = k
# separator = 195
unknown = im.copy()
data = []
for j in range(height):
line = p[j * width:j * width + width]
index = line.index(separator)
data += line[index:] + line[:index]
unknown.putdata(data)
return unknown
def plot(im):
im.show()
if __name__ == "__main__":
r = requests.get(url)
something = r.content
answer = solve(something)
plot(answer)
# romance
# http://huge:file@www.pythonchallenge.com/pc/return/romance.html