<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Python Challenge level 14: &#8220;walk around&#8221;</title>
	<atom:link href="http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/feed/" rel="self" type="application/rss+xml" />
	<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/</link>
	<description>Taher Shihadeh's ragbag</description>
	<lastBuildDate>Mon, 07 May 2012 21:29:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Dirk</title>
		<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/comment-page-1/#comment-7410</link>
		<dc:creator>Dirk</dc:creator>
		<pubDate>Sat, 14 Apr 2012 18:47:30 +0000</pubDate>
		<guid isPermaLink="false">http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/#comment-7410</guid>
		<description>Here is the dumb way to do it.
It took me a bit longer than five minutes.

&lt;code&gt;
import Image
im = Image.open(&quot;wire.png&quot;)
print &quot;Image info:&quot;,im.format, im.size, im.mode
out = Image.new(im.mode, (100,100))

x,y,steps,d = 0,0,0,0
maxsteps = 100
directions=[(1,0), (0,1), (-1,0), (0,-1)]
dx, dy = directions[d]
for i in range(0, 100*100):
    out.putpixel((x,y),im.getpixel((i,0)))

    steps += 1
    if steps == maxsteps:
        # change direction
        d = (d + 1 if d != 3 else 0)
        dx, dy = directions[d]
        steps = 0
        if d % 2 == 0:
            # make one step less when changing direction
            # from right to down OR from left to up 
            maxsteps -= 1
        
    # calculate next coordinates    
    x  = x + dx
    y  = y + dy

out.save(&#039;14.jpg&#039;)
out.show()
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Here is the dumb way to do it.<br />
It took me a bit longer than five minutes.</p>
<p><code><br />
import Image<br />
im = Image.open("wire.png")<br />
print "Image info:",im.format, im.size, im.mode<br />
out = Image.new(im.mode, (100,100))</p>
<p>x,y,steps,d = 0,0,0,0<br />
maxsteps = 100<br />
directions=[(1,0), (0,1), (-1,0), (0,-1)]<br />
dx, dy = directions[d]<br />
for i in range(0, 100*100):<br />
    out.putpixel((x,y),im.getpixel((i,0)))</p>
<p>    steps += 1<br />
    if steps == maxsteps:<br />
        # change direction<br />
        d = (d + 1 if d != 3 else 0)<br />
        dx, dy = directions[d]<br />
        steps = 0<br />
        if d % 2 == 0:<br />
            # make one step less when changing direction<br />
            # from right to down OR from left to up<br />
            maxsteps -= 1</p>
<p>    # calculate next coordinates<br />
    x  = x + dx<br />
    y  = y + dy</p>
<p>out.save('14.jpg')<br />
out.show()<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sumod</title>
		<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/comment-page-1/#comment-3382</link>
		<dc:creator>Sumod</dc:creator>
		<pubDate>Wed, 10 Aug 2011 07:27:47 +0000</pubDate>
		<guid isPermaLink="false">http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/#comment-3382</guid>
		<description>I got to bit.html and then got the message - &#039;you took the wrong curve&#039;. 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?</description>
		<content:encoded><![CDATA[<p>I got to bit.html and then got the message &#8211; &#8216;you took the wrong curve&#8217;. So I must have done the wrapping around incorrectly.</p>
<p>Not clear to me why we are using 200 as the limit. Can you please explain?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/comment-page-1/#comment-2724</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Wed, 01 Jun 2011 14:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/#comment-2724</guid>
		<description>The red pixels threw me off for a while.  If you simply stack the rows vertically they spell the word &quot;bit&quot; which takes you to a page that says &quot;you took the wrong curve.  Spent a long time after that trying to line up the red pixels another way :)</description>
		<content:encoded><![CDATA[<p>The red pixels threw me off for a while.  If you simply stack the rows vertically they spell the word &#8220;bit&#8221; which takes you to a page that says &#8220;you took the wrong curve.  Spent a long time after that trying to line up the red pixels another way :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus</title>
		<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/comment-page-1/#comment-8</link>
		<dc:creator>Marcus</dc:creator>
		<pubDate>Sat, 06 Oct 2007 19:43:26 +0000</pubDate>
		<guid isPermaLink="false">http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/#comment-8</guid>
		<description>Taher,

You&#039;re not kidding! I&#039;m on 24 right now and ... I&#039;m hitting a lot of dead ends. ... its sucking be back in!

/Marcus</description>
		<content:encoded><![CDATA[<p>Taher,</p>
<p>You&#8217;re not kidding! I&#8217;m on 24 right now and &#8230; I&#8217;m hitting a lot of dead ends. &#8230; its sucking be back in!</p>
<p>/Marcus</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Taher Shihadeh</title>
		<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/comment-page-1/#comment-5</link>
		<dc:creator>Taher Shihadeh</dc:creator>
		<pubDate>Fri, 05 Oct 2007 16:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/#comment-5</guid>
		<description>&lt;p&gt;Hey Marcus!&lt;br /&gt;
Thanks for the comment. I didn&#039;t think anyone was reading :-)&lt;br /&gt;
If you want to talk about embarrassing just wait to level 22. *THEN* we can talk about ugly code! ;)&lt;br /&gt;
I&#039;ve been busy this week so I&#039;ve stopped playing at level 24. But I&#039;ll be back soon. I hope the rest of the posts are useful for someone.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hey Marcus!<br />
Thanks for the comment. I didn&#8217;t think anyone was reading :-)<br />
If you want to talk about embarrassing just wait to level 22. *THEN* we can talk about ugly code! ;)<br />
I&#8217;ve been busy this week so I&#8217;ve stopped playing at level 24. But I&#8217;ll be back soon. I hope the rest of the posts are useful for someone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus</title>
		<link>http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/comment-page-1/#comment-4</link>
		<dc:creator>Marcus</dc:creator>
		<pubDate>Fri, 05 Oct 2007 11:13:37 +0000</pubDate>
		<guid isPermaLink="false">http://unixwars.com/2007/09/20/python-challenge-level-14-walk-around/#comment-4</guid>
		<description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Your soln inspired me to write another&lt;br /&gt;
Thank you!&lt;/p&gt;
&lt;p&gt;Using a generator:&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
def seqSquare(start):
    &#039;&#039;&#039;
    &lt;-- remember: 100*100 = (100+99+99+98) + (...  --&gt;
    
    &gt;&gt;&gt; assert reduce( lambda x,y: x+y, seqSquare(100)) == 100 * 100
    &gt;&gt;&gt; assert reduce( lambda x,y: x+y, seqSquare(50)) == 50 * 50
    &gt;&gt;&gt; assert reduce( lambda x,y: x+y, seqSquare(99)) == 99 * 99
    &#039;&#039;&#039;
    yield start
    while start &gt; 1:
        start -= 1
        yield start
        yield start

def walkywalky():
    from PIL import Image
    imS = Image.open( &#039;wire.png&#039;)
    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 &#039;(%d, %d) == %d&#039; % (x, y, p)
            imT.putpixel((x,y),imS.getpixel((p,0)))
            p += 1
        # print
        v += 1
    imT.show()
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>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 &#8230; embarrassing.</p>
<p>Your soln inspired me to write another<br />
Thank you!</p>
<p>Using a generator:</p>
<pre class="prettyprint">
def seqSquare(start):
    '''
    < -- remember: 100*100 = (100+99+99+98) + (...  -->

    &gt;&gt;&gt; assert reduce( lambda x,y: x+y, seqSquare(100)) == 100 * 100
    &gt;&gt;&gt; assert reduce( lambda x,y: x+y, seqSquare(50)) == 50 * 50
    &gt;&gt;&gt; assert reduce( lambda x,y: x+y, seqSquare(99)) == 99 * 99
    '''
    yield start
    while start &gt; 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()
</pre></p>
]]></content:encoded>
	</item>
</channel>
</rss>

