import string import urllib import re # r'http://www.pythonchallenge.com/pc/def/map.html' def PuzzleOne(): """ http://www.pythonchallenge.com/pc/def/map.html """ trans = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:]+string.ascii_lowercase[:2]) s = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj." print string.translate(s, trans) print "http://www.pythonchallenge.com/pc/def/" + string.translate("map", trans) + ".html" def PuzzleTwo(): """ http://www.pythonchallenge.com/pc/def/ocr.html """ f = urllib.urlopen(r'http://www.pythonchallenge.com/pc/def/ocr.html') while f.readline().startswith("find rare characters in the mess below:") is False: pass while f.readline().startswith("") or len(t) == 0: done = True else: s += t f.close() # Begin solution print filter(lambda x: x in string.letters, s) # d = {} # for ch in guts: # d[ch] = d.get(ch, 0) + 1 # print "".join(ch for ch in s if d[ch] < 5) # requires Python 2.4 def GetCypher(url): f = urllib.urlopen(r'http://www.pythonchallenge.com/pc/def/equality.html') while f.readline().startswith("") or len(t) == 0: done = True else: s += t f.close() return s def PuzzleThree(): """ http://www.pythonchallenge.com/pc/def/equality.html One small letter, surrounded by EXACTLY three big bodyguards on each of its sides. """ s = GetCypher(r'http://www.pythonchallenge.com/pc/def/equality.html') s = s.replace("\n","").replace(chr(13),"") p = re.compile('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]') matches = p.findall(s) print ''.join(matches) def PuzzleFour(): """ http://www.pythonchallenge.com/pc/def/linkedlist.html One small letter, surrounded by EXACTLY three big bodyguards on each of its sides. """ # [ 12345, 92512, 64505, 50010, 29193... ] url = r'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' f = urllib.urlopen(url + "12345") pass if __name__ == '__main__': PuzzleFour()