Thursday, April 28, 2011

Python Challenge Level 02

In the level, you would see a hint, "recognize the characters. maybe they are in the book, but MAYBE they are in the page source." By the hint, I knew that I must check the source codes in the page.

The page source said "find rare characters in the mess below:", followed by a large chunk of text. I copied the text into "2.in" on my computer and ran to following codes to find the rarest characters, which were "aeilquty\n". By permutation, I knew the next level was "equality.html".

text = open('2.in').read()
print ''.join(sorted(set(text),lambda x,y: text.count(x) - text.count(y) ))

Thursday, April 14, 2011

Python Challenge Level 01

Obviously, by the hint, we must shift the alphabets to understand the ciphertext. Thus, I wrote as follows.

text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmglegrgl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgleqrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
print ''.join(map(lambda x: not x.isalpha() and x or x in "yz" and chr(ord(x)-24) or chr(ord(x)+2),text))

The hint indicates us to apply the shift to the url, which yields "ocr.html".

Python Challenge Level 00

In the level zero, there is a picture indicating 2^38, which is "274877906944" computed by the following codes.

print 2**38 

Thus, please go to "274877906944.html".

Python Challenge Introduction

Recently, inspired by David Huang, I began to play the Python Challenge again. This time, however, I intended to play in a code-golf manner. That is, writing codes as short as possible. I am not an expert in the area, but let's see how far I can achieve.