-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge_16.py
31 lines (23 loc) · 890 Bytes
/
challenge_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
"""Challenge 16 at http://www.pythonchallenge.com/pc/return/mozart.html"""
import Image
if __name__ == '__main__':
# By looking at the picture, we found that every row has a mark segment
# with color palette number 195.
# The hint in the web page says "let me get this straight", so we try
# align the mark segments to a straight line.
im = Image.open('mozart.gif')
x, y = im.size
data = list(iter(im.getdata()))
new_data = []
for j in range(y):
start = j * x
end = start + x
row = data[start:end]
mark = row.index(195)
# shift row, making it start at the mark position
new_row = row[mark:] + row[:mark]
new_data += new_row
im.putdata(new_data)
im.show()
# The picture now shows "romance". So the URL of next level is
# http://www.pythonchallenge.com/pc/return/romance.html