Python Challenge level 16: “let me get this straight”
In level 16 the title says everything.
Hint 1: there are 5 pink pixels in each row
Fact 1: pink is color 195 in the image’s color index (says The Gimp).
import urllib, Image,cStringIO
def straighten(line): # five equal consecutive pink pixels are the clue
idx=0
while line[idx]!=195:
idx+=1
return line[idx:]+line[:idx]
url = 'http://huge:file@www.pythonchallenge.com/pc/return/mozart.gif'
im = Image.open(cStringIO.StringIO(urllib.urlopen(url).read()))
for y in range(im.size[1]):
line=[im.getpixel((x, y)) for x in range(im.size[0])]
line=straighten(line)
[im.putpixel((x, y),line[x]) for x in range(len(line))]
im.save('16.gif')
We don’t really need “Fact 1” to solve this problem, but it simplifies the code a bit. Instead of looking for pink pixels my first version looked for five equal pixels, but the result was slightly distorted in the lines where the level number is drawn.
The resulting image shows the word “romance”, and that’s where Level 17 awaits. I must say number 17 looks good. The most promising I’ve seen until now, and I’ve loved almost every single one of them. We’ll see if it can be as easily solved as this one.
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.