<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Dryice Liu's Blog &#187; python_challenge</title>
	<link>http://dryice.name/blog</link>
	<description></description>
	<pubDate>Tue, 31 Aug 2010 12:01:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>
	<language>en</language>
			<item>
		<title>challenge 6, continued</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-6-continued/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-6-continued/#comments</comments>
		<pubDate>Mon, 08 May 2006 06:51:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>
<category>python</category><category>python-challenge</category>
		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-6-continued/</guid>
		<description><![CDATA[A year has passed since I visited Python Challenge the last time. And it&#8217;s not easy to start it again  I&#8217;ve got a project that deals with Python image process, so I spend some time on the PIL handbook. And after that, I think trying this challenge is a good practice  
However after [...]]]></description>
			<content:encoded><![CDATA[<p>A year has passed since I visited <a href="http://www.pythonchallenge.com/">Python Challenge</a> the last time. And it&#8217;s not easy to start it again <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I&#8217;ve got a project that deals with Python image process, so I spend some time on the <a href="http://www.pythonware.com/library/pil/handbook/">PIL handbook</a>. And after that, I think trying this challenge is a good practice <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>However after I load the image</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import Image<br />
im = Image.open(&quot;channel.jpg&quot;)</div>
<p>I don&#8217;t know what to do next. I tried to exam the various attributes of the image, but got nothing.</p>
<p>Think it again on &#8220;It really looks like a Y, isn&#8217;t it? now, go back. &#8221; at <a href="http://www.pythonchallenge.com/pc/def/y.html">http://www.pythonchallenge.com/pc/def/y.html</a>. What if the zip goes back? Hmmm, it should looks like a &#8220;1&#8243; or &#8220;l&#8221;. then I tried <a href="http://www.pythonchallenge.com/pc/def/l.html">http://www.pythonchallenge.com/pc/def/l.html</a> because &#8220;1.html&#8221; has already been taken. OK, something there! &#8220;yes. but there are more. &#8221; Good! I tried 2, 3, 6, 33 &#8220;l&#8221;s and several combination with &#8220;w&#8221;, &#8220;o&#8221;, and &#8220;0&#8243;, but all 404.</p>
<p>I think now the problem is to find out how many &#8220;l&#8221;s are there. I tried every attributes of ImageStat but they are all tooooo big. No more hint. I think I should wait the next time.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=692&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_692" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-6-continued/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 5</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-5/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-5/#comments</comments>
		<pubDate>Sun, 29 May 2005 01:55:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-5/</guid>
		<description><![CDATA[Well this is not an easy one.
The unpickling is as easy as it should:
import pickle
f = open(&#8221;banner.p&#8221;, &#8220;r&#8221;)
x = pickle.load(f)
But after that I was lost. x is a list of lists, with 23 items, each item are constructed with one or more tuples, each tuple has two elements: one &#8221; &#8221; or &#8220;#&#8221;, and one [...]]]></description>
			<content:encoded><![CDATA[<p>Well this is not an easy one.</p>
<p>The unpickling is as easy as it should:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import pickle</div>
<p>f = open(&#8221;banner.p&#8221;, &#8220;r&#8221;)<br />
x = pickle.load(f)<br />
But after that I was lost. x is a list of lists, with 23 items, each item are constructed with one or more tuples, each tuple has two elements: one &#8221; &#8221; or &#8220;#&#8221;, and one number. What should I do with this?</p>
<p>I re-read the pickle documents several times and there looks no other thing I can do.</p>
<p>The HTML said &#8220;pickle banner.p&#8221;. Should I pickle it instead of unpickle it? I pickled x with different protocols, but protocol 1 and 2 produced binary output, that I can&#8217;t understand.</p>
<p>The first and last elements of x are all [&#8221; &#8220;, 95]. So these should be the same letter. But 95 in ASCII is &#8220;_&#8221;. What&#8217;s that?</p>
<p>The file name is &#8220;banner.p&#8221;. Is this related? There&#8217;s no banner in the picture. Wait&#8230; The pic!</p>
<p>I looked through the hex of the JPG but found the number in x doesn&#8217;t mean a position as I thought: there are too many small numbers ([0-9]).</p>
<p>a</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">for i in x:<br />
print len(i)</div>
<p>doesn&#8217;t help. The numbers are odd.</p>
<p>then</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">for i in x:<br />
print i</div>
<p>And i was caught by the first several lines:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">[(&#8217; &#8216;, 95)]<br />
[(&#8217; &#8216;, 14), (&#8217;#', 5), (&#8217; &#8216;, 70), (&#8217;#', 5), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]<br />
[(&#8217; &#8216;, 15), (&#8217;#', 4), (&#8217; &#8216;, 71), (&#8217;#', 4), (&#8217; &#8216;, 1)]</div>
<p>There looks there are some patern in it&#8230; Yes, the number in each line adds up the same! It&#8217;s 95! So the &#8221; &#8221; and &#8220;#&#8221; must be standing for something, like 0 and 1!&#8230; Or is this a bitmap picture?</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">f2 = open(&quot;out&quot;, &quot;w&quot;)</div>
<p>for i in x:<br />
for j in i:<br />
f2.write(j[0]*j[1])<br />
f2.write(&#8221;\n&#8221;)</p>
<p>f2.close()<br />
And I got in the file out: channel ! The Challenge 6 is at <a href="http://www.pythonchallenge.com/pc/def/channel.html">http://www.pythonchallenge.com/pc/def/channel.html</a> !</p>
<p>Finially I understand what the &#8220;banner&#8221; mean, the out put in file out looks like the output of command banner <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Finially I got this. Now challenge 6:</p>
<p>The title is &#8220;now there are pairs&#8221;. There&#8217;s no hint. Again there&#8217;s some hint in the HTML source: zip. I know there&#8217;s a gzip module and a zipfile module. But what are they expecting me to do? Zip the picture? Or the HTML file?</p>
<p>Well I&#8217;ve spend too much time on this today so let&#8217;s wait for tomorrow. Things are getting harder, and more interesting <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=739&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_739" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 6</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-6/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-6/#comments</comments>
		<pubDate>Tue, 24 May 2005 11:35:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-6/</guid>
		<description><![CDATA[Well first I need to figure out what to zip. I took a look at the HTML source again and found something unusual: the hint looks like:
&#38;#60;html&#38;gt; &#38;#60;!&#8211; &#38;#60;&#8211; zip &#8211;&#38;gt;
There&#8217;s an extra &#8220;&#60;—&#8221; in the HTML comment. I believe this is pointing me what to zip. But after I tried zip &#8220;html&#8221;, &#8220;&#60;html&#8221;, the [...]]]></description>
			<content:encoded><![CDATA[<p>Well first I need to figure out what to zip. I took a look at the HTML source again and found something unusual: the hint looks like:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">&amp;#60;html&amp;gt; &amp;#60;!&#8211; &amp;#60;&#8211; zip &#8211;&amp;gt;</div>
<p>There&#8217;s an extra &#8220;&lt;—&#8221; in the HTML comment. I believe this is pointing me what to zip. But after I tried zip &#8220;html&#8221;, &#8220;&lt;html&#8221;, the whole THML source file, the jpg image, all gave nothing.</p>
<p>I stared at the page again and found the zip looks like a &#8220;Y&#8221;, so I tried <a href="http://www.pythonchallenge.com/pc/def/y.html">http://www.pythonchallenge.com/pc/def/y.html</a>. There&#8217;s something there! &#8220;It really looks like a Y, isn&#8217;t it? now, go back.&#8221;</p>
<p>There&#8217;s some other thing in the picture! Stared at it again and I found on the top right corner there&#8217;s a &#8220;&lt;—&#8221; like sign pointing to something like &#8220;333333&#8243; or &#8220;wwwwww&#8221;. But <a href="http://www.pythonchallenge.com/pc/def/333333.html">http://www.pythonchallenge.com/pc/def/333333.html</a> <a href="http://www.pythonchallenge.com/pc/def/wwwwww.html">http://www.pythonchallenge.com/pc/def/wwwwww.html</a></p>
<p>All gave nothing.</p>
<p>I also noticed there are chars on the button, &#8220;sprint&#8221;, and there are something looks like chars in the middle of the zip, something like an &#8220;o&#8221; or 0, and something like &#8220;v&#8221;. I tried several combinations but they all gave me 404.</p>
<p>I think the problem is in the title: &#8220;now there are pairs&#8221;. What does this mean? There&#8217;s no &#8220;pair&#8221; module in the library. The &#8220;zip&#8221; hint should be related the zip modules or the zip in the picture.</p>
<p>I also tried &#8220;yy.html&#8221; and several double letters, no luck again.</p>
<p>Wait, there is a PIL module! I&#8217;ve heared about it doing things about picture but never use it. Think about the &#8220;Peak Hell&#8221; and &#8220;pickle&#8221; thing yesterday. I think this is a pretty good guess.</p>
<p>Well I&#8217;ve got PIL installed today. I think I&#8217;d leave the document reading to tomorrow. The document is at <a href="http://www.pythonware.com/library/pil/handbook/">http://www.pythonware.com/library/pil/handbook/</a></p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=741&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_741" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-6/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 4</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-4/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-4/#comments</comments>
		<pubDate>Sun, 22 May 2005 00:29:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-4/</guid>
		<description><![CDATA[Following the idea yesterday, here is my first script:
import urllib;
import string;
import re;
def followNothing(url):
page=urllib.urlopen(url)
pagecontent = page.read()
print pagecontent
result =re.search(&#8221;[0-9]{5}&#8221;, pagecontent)
if result:
num = pagecontent[result.start():result.end()]
nexturl = &#8220;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=&#8221; + num
followNothing(nexturl)
else:
print &#8220;fix the script!&#8221;
and I got:
In [12]: followNothing(&#34;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345&#34;)
and the next nothing is 92512
and the next nothing is 64505
&#38;#60;font color=red&#38;gt;Your hands are getting tired &#38;#60;/font&#38;gt;and the next nothing is 50010
and the next [...]]]></description>
			<content:encoded><![CDATA[<p>Following the idea yesterday, here is my first script:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import urllib;<br />
import string;<br />
import re;</div>
<p>def followNothing(url):<br />
page=urllib.urlopen(url)<br />
pagecontent = page.read()<br />
print pagecontent<br />
result =re.search(&#8221;[0-9]{5}&#8221;, pagecontent)<br />
if result:<br />
num = pagecontent[result.start():result.end()]<br />
nexturl = &#8220;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=&#8221; + num<br />
followNothing(nexturl)<br />
else:<br />
print &#8220;fix the script!&#8221;<br />
and I got:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [12]: followNothing(&quot;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345&quot;)<br />
and the next nothing is 92512<br />
and the next nothing is 64505<br />
&amp;#60;font color=red&amp;gt;Your hands are getting tired &amp;#60;/font&amp;gt;and the next nothing is 50010<br />
and the next nothing is 29193<br />
and the next nothing is 89924<br />
and the next nothing is 65471<br />
and the next nothing is 69977<br />
and the next nothing is 6306<br />
fix the script!</div>
<p>OK, it&#8217;s not necessary to be 5 numbers.</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import urllib;<br />
import string;<br />
import re;</div>
<p>def followNothing(url):<br />
page=urllib.urlopen(url)<br />
pagecontent = page.read()<br />
print pagecontent<br />
result =re.search(&#8221;[0-9]+&#8221;, pagecontent)<br />
if result:<br />
num = pagecontent[result.start():result.end()]<br />
nexturl = &#8220;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=&#8221; + num<br />
followNothing(nexturl)<br />
else:<br />
print &#8220;fix the script!&#8221;<br />
and&#8230;</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">&#8230;.<br />
and the next nothing is 37852<br />
and the next nothing is 61066<br />
There maybe misleading numbers in the<br />
text. One example is 61067. Look only for the next nothing and the next nothing is 53522<br />
You&#8217;ve been misleaded to here. Go to previous<br />
one and check.<br />
fix the script!</div>
<p>OK,</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import urllib;<br />
import string;<br />
import re;</div>
<p>def followNothing(url):<br />
page=urllib.urlopen(url)<br />
pagecontent = page.read()<br />
print pagecontent<br />
result =re.search(&#8221;next nothing is [0-9]+&#8221;, pagecontent)<br />
if result:<br />
num = pagecontent[result.start()+16:result.end()]<br />
nexturl = &#8220;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=&#8221; + num<br />
followNothing(nexturl)<br />
else:<br />
print &#8220;fix the script!&#8221;<br />
And after a long time&#8230;</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">and the next nothing is 92118<br />
Yes. Divide by two and keep going.<br />
fix the script!</div>
<p>I visited <a href="http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=46059">http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=46059</a> and found it&#8217;s still &#8220;and the next nothing is 33110&#8243;</p>
<p>Don&#8217;t know what the pattern is so just do it manually this time: call followNothing(&#8221;http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=33110&#8243;)</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">and the next nothing is 27719<br />
and the next nothing is 65667<br />
peak.html<br />
fix the script!</div>
<p>OK, challenge 5 is at <a href="http://www.pythonchallenge.com/pc/def/peak.html">http://www.pythonchallenge.com/pc/def/peak.html</a></p>
<p>The hint is &#8220;pronounce it&#8221;, the title is &#8220;peak hell&#8221;. Vies the page source and there is another hint: &#8220;peak hell sounds familiar ? &#8221;</p>
<p>Well I&#8217;m not a native speaker so I first look throu the module names. And I found pickle <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> visit <a href="http://www.pythonchallenge.com/pc/def/pickle.html">http://www.pythonchallenge.com/pc/def/pickle.html</a> and it told me &#8220;yes! pickle!&#8221;. No title, no more hints, no more source. What&#8217;s going on?</p>
<p>So I took a look at the source of <a href="http://www.pythonchallenge.com/pc/def/peak.html">http://www.pythonchallenge.com/pc/def/peak.html</a> again and found a wired line:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">&amp;#60;peakhell src=&quot;banner.p&quot;/&amp;gt;</div>
<p>Give <a href="http://www.pythonchallenge.com/pc/def/banner.p">http://www.pythonchallenge.com/pc/def/banner.p</a> a vist and got a mess. I think I&#8217;ll need to unpickling this mess tomorrow.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=742&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_742" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 3</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-3/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-3/#comments</comments>
		<pubDate>Sat, 21 May 2005 02:03:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-3/</guid>
		<description><![CDATA[Well, it said EXACTLY three big bodyguard, so the first try is like this:
import re
target = re.compile(r&#8221;[!A-Z][A-Z]{3}([a-z])[A-Z]{3}[!A-Z]&#8221;)
f = open(&#8221;mess.txt&#8221;, &#8220;r&#8221;)
myout = target.findall(f.read())
And I got this:
In [7]: print myout
[&#8217;e', &#8216;i&#8217;, &#8216;z&#8217;, &#8216;r&#8217;, &#8216;v&#8217;, &#8216;g&#8217;, &#8216;b&#8217;, &#8216;m&#8217;, &#8217;s&#8217;, &#8216;z&#8217;, &#8216;u&#8217;, &#8216;o&#8217;, &#8216;w&#8217;, &#8216;i&#8217;, &#8216;b&#8217;, &#8216;z&#8217;, &#8216;b&#8217;, &#8216;c&#8217;, &#8216;j&#8217;, &#8216;g&#8217;, &#8216;d&#8217;, &#8216;o&#8217;, &#8216;h&#8217;, &#8216;l&#8217;, &#8216;
z&#8217;, &#8216;x&#8217;, &#8216;j&#8217;, &#8216;v&#8217;, [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it said <em>EXACTLY</em> three big bodyguard, so the first try is like this:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import re</div>
<p>target = re.compile(r&#8221;[!A-Z][A-Z]{3}([a-z])[A-Z]{3}[!A-Z]&#8221;)</p>
<p>f = open(&#8221;mess.txt&#8221;, &#8220;r&#8221;)</p>
<p>myout = target.findall(f.read())<br />
And I got this:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [7]: print myout<br />
[&#8217;e', &#8216;i&#8217;, &#8216;z&#8217;, &#8216;r&#8217;, &#8216;v&#8217;, &#8216;g&#8217;, &#8216;b&#8217;, &#8216;m&#8217;, &#8217;s&#8217;, &#8216;z&#8217;, &#8216;u&#8217;, &#8216;o&#8217;, &#8216;w&#8217;, &#8216;i&#8217;, &#8216;b&#8217;, &#8216;z&#8217;, &#8216;b&#8217;, &#8216;c&#8217;, &#8216;j&#8217;, &#8216;g&#8217;, &#8216;d&#8217;, &#8216;o&#8217;, &#8216;h&#8217;, &#8216;l&#8217;, &#8216;<br />
z&#8217;, &#8216;x&#8217;, &#8216;j&#8217;, &#8216;v&#8217;, &#8216;e&#8217;, &#8216;g&#8217;, &#8216;f&#8217;, &#8216;q&#8217;, &#8216;b&#8217;, &#8216;i&#8217;, &#8216;i&#8217;, &#8216;a&#8217;, &#8216;v&#8217;, &#8216;j&#8217;, &#8216;j&#8217;, &#8216;g&#8217;, &#8216;t&#8217;, &#8216;c&#8217;, &#8216;j&#8217;, &#8216;k&#8217;, &#8216;g&#8217;, &#8216;c&#8217;, &#8216;l&#8217;, &#8216;g&#8217;, &#8216;m&#8217;<br />
, &#8217;s&#8217;, &#8216;n&#8217;, &#8216;j&#8217;, &#8216;j&#8217;, &#8216;m&#8217;, &#8216;z&#8217;, &#8216;z&#8217;, &#8217;s&#8217;, &#8217;s&#8217;, &#8216;q&#8217;, &#8216;q&#8217;, &#8216;q&#8217;, &#8216;l&#8217;, &#8216;i&#8217;, &#8216;j&#8217;, &#8216;z&#8217;, &#8216;f&#8217;, &#8216;a&#8217;, &#8216;l&#8217;, &#8216;j&#8217;, &#8216;p&#8217;, &#8216;x&#8217;, &#8216;j&#8217;, &#8216;t&#8217;,<br />
&#8216;k&#8217;, &#8217;s&#8217;, &#8216;a&#8217;, &#8216;q&#8217;, &#8216;e&#8217;, &#8216;o&#8217;, &#8216;c&#8217;, &#8216;t&#8217;, &#8216;c&#8217;, &#8216;n&#8217;, &#8216;w&#8217;, &#8216;x&#8217;, &#8216;y&#8217;, &#8216;l&#8217;, &#8216;l&#8217;, &#8216;g&#8217;, &#8216;b&#8217;, &#8216;f&#8217;, &#8216;m&#8217;, &#8216;i&#8217;, &#8216;w&#8217;, &#8216;k&#8217;, &#8216;f&#8217;, &#8216;i&#8217;, &#8216;u<br />
&#8216;, &#8216;z&#8217;, &#8216;j&#8217;, &#8216;g&#8217;, &#8216;t&#8217;, &#8216;f&#8217;, &#8216;d&#8217;, &#8216;p&#8217;, &#8216;e&#8217;, &#8216;j&#8217;, &#8217;s&#8217;, &#8216;b&#8217;, &#8216;y&#8217;, &#8216;u&#8217;, &#8217;s&#8217;, &#8216;m&#8217;, &#8216;i&#8217;, &#8216;j&#8217;, &#8216;j&#8217;, &#8216;o&#8217;, &#8216;p&#8217;, &#8216;e&#8217;, &#8217;s&#8217;, &#8217;s&#8217;, &#8216;j&#8217;,<br />
&#8216;n&#8217;, &#8216;t&#8217;, &#8216;h&#8217;, &#8217;s&#8217;, &#8216;m&#8217;, &#8216;o&#8217;, &#8216;x&#8217;, &#8216;v&#8217;, &#8216;j&#8217;, &#8216;k&#8217;, &#8216;g&#8217;, &#8216;u&#8217;, &#8216;d&#8217;, &#8216;w&#8217;, &#8216;t&#8217;, &#8216;f&#8217;, &#8216;b&#8217;, &#8216;e&#8217;, &#8216;a&#8217;, &#8216;u&#8217;, &#8216;n&#8217;, &#8216;g&#8217;, &#8216;p&#8217;, &#8216;i&#8217;, &#8216;<br />
b&#8217;, &#8216;k&#8217;, &#8216;j&#8217;, &#8216;n&#8217;, &#8216;i&#8217;, &#8216;k&#8217;, &#8216;x&#8217;, &#8216;g&#8217;, &#8216;i&#8217;, &#8216;b&#8217;, &#8216;l&#8217;, &#8216;a&#8217;, &#8216;z&#8217;, &#8216;l&#8217;, &#8216;i&#8217;, &#8216;c&#8217;, &#8216;d&#8217;, &#8216;j&#8217;, &#8216;g&#8217;, &#8216;u&#8217;, &#8216;o&#8217;, &#8216;j&#8217;, &#8216;v&#8217;, &#8216;e&#8217;, &#8216;l&#8217;<br />
, &#8216;y&#8217;, &#8216;i&#8217;, &#8216;d&#8217;, &#8216;o&#8217;, &#8216;m&#8217;, &#8216;f&#8217;, &#8216;m&#8217;, &#8216;k&#8217;]</div>
<p>What&#8217;s this? Checked the mess again and there&#8217;s no punctuation in it. Is the URL so long?</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [12]: &quot;&quot;.join(myout)<br />
Out[12]: &#8216;eizrvgbmszuowibzbcjgdohlzxjvegfqbiiavjjgtcjkgclgmsnjjmzzssqqqlijzfaljpxjtksaqeoctcnwxyllgbfmiwkfiuzjgtfdpejsbyus<br />
mijjopessjnthsmoxvjkgudwtfbeaungpibkjnikxgiblazlicdjguojvelyidomfmk&#8217;</div>
<p>The loooooong.html doesn&#8217;t work. Should I ignore the &#8220;\n&#8221;?</p>
<p>Wait.. that &#8220;!&#8221; in the RE!&#8230; I&#8217;ve been in C these days <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So here is the next version:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import re</div>
<p>target = re.compile(r&#8221;[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]&#8221;)</p>
<p>f = open(&#8221;mess.txt&#8221;, &#8220;r&#8221;)</p>
<p>myout = &#8220;&#8221;.join(target.findall(f.read()))<br />
And I got</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [41]: myout<br />
Out[41]: &#8216;linkedlist&#8217;</div>
<p>OK, <a href="http://www.pythonchallenge.com/pc/def/linkedlist.html">http://www.pythonchallenge.com/pc/def/linkedlist.html</a> ! It told me to go to <a href="http://www.pythonchallenge.com/pc/def/linkedlist.php">http://www.pythonchallenge.com/pc/def/linkedlist.php</a>. This is Challenge 4!</p>
<p>There&#8217;s no hint in Challenge 4. The title is &#8220;follow the chain&#8221;. Well, I clicked on the image and it brings me to <a href="http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345">http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345</a> &#8220;and the next nothing is 92512&#8243;. OK, <a href="http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=92512">http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=92512</a>. OK, 64505. 50010, 29193, &#8230;</p>
<p>Wait, on <a href="http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=64505">http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=64505</a>, it says &#8220;Your hands are getting tired and the next nothing is 50010&#8243;. I didn&#8217;t notice this and keep following the numbers for a while. Now I think I should make a script to do it. Tomorrow <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=743&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_743" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 2</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-2/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-2/#comments</comments>
		<pubDate>Thu, 19 May 2005 12:17:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-2/</guid>
		<description><![CDATA[First of all I checked the lib to see if there&#8217;s an OCR module, looks no, at least not in the standard distribution  
OK, it says to find the rare chars, so here is my first try:
f = open(&#34;mess.txt&#34;, &#34;r&#34;)
ss = {}
for c in f.read():
if ss.has_key(c):
ss[c] += 1
else:
ss[c]=1
And here is the output:
In [6]: ss
Out[6]:
{&#8217;\n&#8217;: [...]]]></description>
			<content:encoded><![CDATA[<p>First of all I checked the lib to see if there&#8217;s an OCR module, looks no, at least not in the standard distribution <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>OK, it says to find the rare chars, so here is my first try:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">f = open(&quot;mess.txt&quot;, &quot;r&quot;)</div>
<p>ss = {}</p>
<p>for c in f.read():<br />
if ss.has_key(c):<br />
ss[c] += 1<br />
else:<br />
ss[c]=1<br />
And here is the output:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [6]: ss<br />
Out[6]:<br />
{&#8217;\n&#8217;: 1220,<br />
&#8216;!&#8217;: 6079,<br />
&#8216;#&#8217;: 6115,<br />
&#8216;$&#8217;: 6046,<br />
&#8216;%&#8217;: 6104,<br />
&#8216;&amp;amp;&#8217;: 6043,<br />
&#8216;(&#8217;: 6154,<br />
&#8216;)&#8217;: 6186,<br />
&#8216;*&#8217;: 6034,<br />
&#8216;+&#8217;: 6066,<br />
&#8216;@&#8217;: 6157,<br />
&#8216;[&#8217;: 6108,<br />
&#8216;]&#8217;: 6152,<br />
&#8216;^&#8217;: 6030,<br />
&#8216;_&#8217;: 6112,<br />
&#8216;a&#8217;: 1,<br />
&#8216;e&#8217;: 1,<br />
&#8216;i&#8217;: 1,<br />
&#8216;l&#8217;: 1,<br />
&#8216;q&#8217;: 1,<br />
&#8216;t&#8217;: 1,<br />
&#8216;u&#8217;: 1,<br />
&#8216;y&#8217;: 1,<br />
&#8216;{&#8217;: 6046,<br />
&#8216;}&#8217;: 6105}</div>
<p>I tried <a href="http://www.pythonchallenge.com/pc/def/aeilqtuy.html">http://www.pythonchallenge.com/pc/def/aeilqtuy.html</a> and got a 404. I think I need to preserve the order. Anyway they are all lower case chars so</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import string</div>
<p>f = open(&#8221;mess.txt&#8221;, &#8220;r&#8221;)</p>
<p>out = [c for c in f.read() if c in string.ascii_lowercase]<br />
And here is what I got:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [15]: out<br />
Out[15]: [&#8217;e', &#8216;q&#8217;, &#8216;u&#8217;, &#8216;a&#8217;, &#8216;l&#8217;, &#8216;i&#8217;, &#8216;t&#8217;, &#8216;y&#8217;]</div>
<p><a href="http://www.pythonchallenge.com/pc/def/equality.html">http://www.pythonchallenge.com/pc/def/equality.html</a>, got it!</p>
<p>The hit is: One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.</p>
<p>The title is &#8220;re&#8221;. So this is re related. But I don&#8217;t know what the hit means and decided to take a look at the page source. Ah, there&#8217;s a mess in there, again!</p>
<p>So tomorrow, I&#8217;ll use re to search the mess and find some patien, maybe a lower case surounded by three upper case or something similiar.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=744&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_744" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 1</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-1/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-1/#comments</comments>
		<pubDate>Wed, 18 May 2005 01:50:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-1/</guid>
		<description><![CDATA[After staring at the mess sentence at the end for a while, I realize there&#8217;s not too mucy &#8220;k,o,e&#8221; in it so the idea yesterday won&#8217;t work.
Look again at the pic and I think I found what&#8217;s in it: int(k)+2 = m, int(o)+2 = q, int(e)+2 = g. I think this is it.
It took me [...]]]></description>
			<content:encoded><![CDATA[<p>After staring at the mess sentence at the end for a while, I realize there&#8217;s not too mucy &#8220;k,o,e&#8221; in it so the idea yesterday won&#8217;t work.</p>
<p>Look again at the pic and I think I found what&#8217;s in it: int(k)+2 = m, int(o)+2 = q, int(e)+2 = g. I think this is it.</p>
<p>It took me some time cause Python don&#8217;t do the type cast as we do in c/cpp. I checked the manual with keyword like &#8220;char&#8221; &#8220;ascii&#8221; and found curses.ascii and binascii. The curses.ascii might be some help but not what I want. Finally I found str() and ord(). So here is the first version:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">sentence = &quot;&quot;&quot;<br />
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr<br />
gl zw fylb gq glcddgagclr ylb rfyr&#8217;q ufw rfgq rcvr gq qm jmle. sqgle<br />
qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.<br />
&quot;&quot;&quot;</div>
<p>def add2(s):<br />
return [chr(ord(i)+2) for i in s]<br />
Ooops, it print one char per line.</p>
<p>So here is the second version:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">sentence = &quot;&quot;&quot;<br />
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr<br />
gl zw fylb gq glcddgagclr ylb rfyr&#8217;q ufw rfgq rcvr gq qm jmle. sqgle<br />
qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.<br />
&quot;&quot;&quot;</div>
<p>def add2(s):<br />
return &#8220;&#8221;.join([chr(ord(i)+2) for i in s])<br />
I got</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [33]: add2(sentence)<br />
Out[33]: &#8216;\x0ci&quot;hope&quot;you&quot;didnt&quot;tr{nsl{te&quot;it&quot;|y&quot;h{nd0&quot;th{ts&quot;wh{t&quot;computers&quot;{re&quot;for0&quot;doing&quot;it\x0cin&quot;|y&quot;h{nd&quot;is&quot;inefficient&quot;{<br />
nd&quot;th{t)s&quot;why&quot;this&quot;text&quot;is&quot;so&quot;long0&quot;using\x0cstring0m{ketr{ns*+&quot;is&quot;recommended0&quot;now&quot;{pply&quot;on&quot;the&quot;url0\x0c&#8217;</div>
<p>Hmm, I should make that in one line and convert alphas only.</p>
<p>Wait&#8230; I saw something about string in it. Let me check the document&#8230;</p>
<p>OK, I&#8217;ve found string.maketrans() and string.translate(). So here is the third version:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import string</div>
<p>sentence = &#8220;\<br />
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr \<br />
gl zw fylb gq glcddgagclr ylb rfyr&#8217;q ufw rfgq rcvr gq qm jmle. sqgle \<br />
qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. \<br />
&#8221;</p>
<p>trans = string.maketrans(&#8221;abcdefghijklmnopqrstuvwxyz&#8221;,<br />
&#8220;cdefghijklmnopqrstuvwxyzab&#8221;)</p>
<p>def add2(s):<br />
return string.translate(s, trans)<br />
And now</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [46]: add2(sentence)<br />
Out[46]: &quot;i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that<br />
&#8217;s why this text is so long. using string.maketrans() is recommended. now apply on the url.\n&quot;</div>
<p>OK, I&#8217;ve got it!</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">In [48]: add2(&quot;map&quot;)<br />
Out[48]: &#8216;ocr&#8217;</div>
<p>So the next challenge is at <a href="http://www.pythonchallenge.com/pc/def/ocr.html">http://www.pythonchallenge.com/pc/def/ocr.html</a> <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>One more thing about this challenge: the title is &#8220;What about making trans?&#8221;. That is a hint too.</p>
<p>Now challenge 2: the hint is &#8220;recognize the characters. maybe they are in the book, but MAYBE they are in the page source.&#8221; View the html source and found &#8220;find rare characters in the mess below:&#8221; and some mess of characters. This looks like base64 or uuencoded. Let&#8217;s wait for tomorrow.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=745&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_745" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Challenge 0</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-0/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-0/#comments</comments>
		<pubDate>Tue, 17 May 2005 14:33:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-0/</guid>
		<description><![CDATA[OK, this is marked as &#8220;warming up&#8221; so it should be easy.
The hint is &#8220;look at the URL address.&#8221;. OK, this is challenge 0 and the url is 0.html. So I changed it to 1.html.
There is a page there! It shows &#8220;2**38 is much much larger.&#8221;. OK I know what the &#8220;238&#8243; in the pic [...]]]></description>
			<content:encoded><![CDATA[<p>OK, this is marked as &#8220;warming up&#8221; so it should be easy.</p>
<p>The hint is &#8220;look at the URL address.&#8221;. OK, this is challenge 0 and the url is 0.html. So I changed it to 1.html.</p>
<p>There is a page there! It shows &#8220;2**38 is much much larger.&#8221;. OK I know what the &#8220;238&#8243; in the pic mean. Load IPython and give 2**38, I get 274877906944L. So I changed the name to 274877906944L.html. &#8220;the L in unnecessary&#8221;. OK, 274877906944.html.</p>
<p>I got it! now the challenge 1 url: <a href="http://www.pythonchallenge.com/pc/def/map.html">http://www.pythonchallenge.com/pc/def/map.html</a></p>
<p>There are &#8220;k-&gt;m, o-&gt;q, e-&gt;g&#8221; in the pic and the hint is &#8220;everybody thinks twice before solving this.&#8221;</p>
<p>There are some sentence at the end. The first glance is that to replace the &#8220;k,o,e&#8221; in the sentence, but what does &#8220;think twice&#8221; mean? Let&#8217;s wait for tomorrow.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=747&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_747" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-0/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

