Python Challenge level 14: “walk around”

Level 14 is really short once again.

Hint 1: image is a spiral. It’s direction could be meaningful
Hint 2: remember: 100*100 = (100+99+99+98) + …. (3+2+2+1)+1
Fact 1: wire.jpg is 1×10000 pixels = 100*100

I especially liked this level because it was straight forward. You didn’t have to imagine obscure meanings hidden in the hints. The wire.jpg is so streched that it resembles a barcode, so you can automatically know that there is something encoded somehow. Also the 100*100 sequence hint, and the 100*100 pixels couldn’t be clearer. I think it is the first level I solved in under 5 minutes since the easy ones at the beginning of the game.

#!/usr/bin/env python
import Image
im = Image.open("wire.png")
new = Image.new(im.mode,[100,100])
doubled_steps=200
directions=[(1,0), (0,1), (-1,0), (0,-1)] # vectors in [x,y] format
x,y,p=-1,0,0
while doubled_steps//2 > 0:
    for v in directions: # we will be taking steps in 4 directions
        steps=doubled_steps//2
        for s in range(steps):
            x,y=x+v[0],y+v[1]
            new.putpixel((x,y),im.getpixel((p,0)))
            p+=1
        doubled_steps-=1
new.save('14.jpg')

It’s a cat. We’ll learn its name in cat.html as well as the place to go if we’re looking for Level 15.

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.

5 Comments »

 
  • Marcus says:

    The double_steps threw me off, but made me study your snippet cos it is way more KISSable than my hack. my ipython log for that session … embarrassing.

    Your soln inspired me to write another
    Thank you!

    Using a generator:

    def seqSquare(start):
        '''
        < -- remember: 100*100 = (100+99+99+98) + (...  -->
    
        >>> assert reduce( lambda x,y: x+y, seqSquare(100)) == 100 * 100
        >>> assert reduce( lambda x,y: x+y, seqSquare(50)) == 50 * 50
        >>> assert reduce( lambda x,y: x+y, seqSquare(99)) == 99 * 99
        '''
        yield start
        while start > 1:
            start -= 1
            yield start
            yield start
    
    def walkywalky():
        from PIL import Image
        imS = Image.open( 'wire.png')
        imT = Image.new(imS.mode,(100,100))
    
        vector = [ (1,0), (0,1), (-1,0), (0,-1)]
        x,y,p,v = -1,0,0,0
        for steps in seqSquare(100):
            for step in range(steps):
                dx,dy = vector[v%4]
                x,y = x+dx, y+dy
                # print '(%d, %d) == %d' % (x, y, p)
                imT.putpixel((x,y),imS.getpixel((p,0)))
                p += 1
            # print
            v += 1
        imT.show()
    

  • Hey Marcus!
    Thanks for the comment. I didn’t think anyone was reading :-)
    If you want to talk about embarrassing just wait to level 22. *THEN* we can talk about ugly code! ;)
    I’ve been busy this week so I’ve stopped playing at level 24. But I’ll be back soon. I hope the rest of the posts are useful for someone.

  • Marcus says:

    Taher,

    You’re not kidding! I’m on 24 right now and … I’m hitting a lot of dead ends. … its sucking be back in!

    /Marcus

  • Kevin says:

    The red pixels threw me off for a while. If you simply stack the rows vertically they spell the word “bit” which takes you to a page that says “you took the wrong curve. Spent a long time after that trying to line up the red pixels another way :)

  • Sumod says:

    I got to bit.html and then got the message – ‘you took the wrong curve’. So I must have done the wrapping around incorrectly.

    Not clear to me why we are using 200 as the limit. Can you please explain?

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>