Ejemplo n.º 1
0
def main():
    """http://www.pythonchallenge.com/pc/def/equality.html"""
    clean_text = re.sub('\s', '', text)
    all = re.findall('[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]', text)
    result = ''.join([res[4] for res in all])
    print result
    print pych_url(result)
Ejemplo n.º 2
0
def main():
    """http://www.pythonchallenge.com/pc/def/channel.html"""

    zf = download_zipfile()
    comments = []

    #read the readme file
    readme = zf.read('readme.txt')
    nothing = re.search('hint1: start from (\d+)', readme).group(1)
    print 'start: {start}'.format(start=nothing)

    while nothing:
        fname = nothing + '.txt'
        info = zf.getinfo(fname)
        comment = info.comment
        content = zf.read(fname)
        print '{fname}: {comment} - {content}'.format(fname=fname, comment=comment, content=content)
        comments.append(comment)

        result = re.search('nothing is (\d+)$', content)
        if result:
            nothing = result.group(1)
        else:
            nothing = 0

    print ''.join(comments)
    print pych_url('hockey')
    print pych_url('oxygen')
Ejemplo n.º 3
0
def main():
    """http://www.pythonchallenge.com/pc/def/peak.html
    http://www.pythonchallenge.com/pc/def/pickle.html"""

    stream = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p")
    obj = pickle.load(stream)
    for line in obj:
        print "".join(e[0] * e[1] for e in line)
    print pych_url("channel")
Ejemplo n.º 4
0
def main():
    """http://www.pythonchallenge.com/pc/def/ocr.html"""
    d = {ch: 0 for ch in string.printable}
    for ch in text:
        d[ch] += 1

    avg = len(text) / len(d)
    rare_chars = ''.join([ch for ch, val in d.items() if 0 < val < avg])

    by_appearance = ''.join(sorted(rare_chars, key=lambda c: text.find(c)))

    print by_appearance
    print pych_url(by_appearance)
Ejemplo n.º 5
0
def main():
    """solution for http://www.pythonchallenge.com/pc/def/map.html"""
    text = """
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."""

    letters = 'abcdefghijklmnopqrstuvwxyz'
    to = letters[2:] + letters[:2]

    trans = maketrans(letters, to)
    clear = text.translate(trans)

    print clear

    base = 'map'.translate(trans)
    print base
    print pych_url(base)
Ejemplo n.º 6
0
def main():
    """http://www.pythonchallenge.com/pc/def/linkedlist.html"""

    rx = re.compile('next nothing is (\d+)$')
    nothing = 12345
    #nothing = 3875
    #nothing = 82682
    #nothing = 66831

    while nothing:
        resource = urllib.urlopen(nothing_url(nothing))
        line = ''.join([l.rstrip() for l in resource.readlines()])
        print line
        match = rx.search(line)
        if match:
            nothing = match.group(1)
        elif re.search('Divide by two and keep going', line):
            nothing = int(nothing) / 2
        else:
            nothing = 0

    print pych_url(line,suffix=False)
Ejemplo n.º 7
0
def main():
    """http://www.pythonchallenge.com/pc/def/oxygen.html"""
    web_res = urllib.urlopen(pych_url('oxygen.png', False))
    f = StringIO.StringIO(web_res.read())

    im = PIL.Image.open(f)
    width, height = im.size
    x = 2
    text = ''
    ords = []
    while x < width:
        r, g, b, a = im.getpixel((x, height/2))
        if not r == g == b:
            break
        x += 7
        ords.append(r)
    text = ''.join(chr(ord) for ord in ords)
    print text
    arr_text = text[text.index('[')+1:text.index(']')]
    target = ''.join([chr(int(n)) for n in arr_text.split(', ')])
    print target
    print pych_url(target)
Ejemplo n.º 8
0
def main():
    """solution for http://www.pythonchallenge.com/pc/def/0.html"""
    result = 2**38
    print result
    print pych_url(result)