예제 #1
0
def get_dots(n, s, e):
    captions = ['', 'First dots', 'Second dots']
    dots = pcutils.get_string_from_page('return/',
                                        'good',
                                        start=s,
                                        end=e,
                                        un='huge',
                                        pw='file')
    pcutils.print_lines(dots.split(pcutils.NEWLINE), captions[n])
    dots = list(map(int, ''.join(dots.splitlines()).split(',')))
    print()
    return list(zip(dots[0::2], dots[1::2]))
예제 #2
0
    print(f'Linked list:')
    key = '90052'
    while key is not None:
        next_key, message = linked_list[key]
        print(f'    key={key}: message={message}')
        key = next_key

    print()

    print(f'Collecting comments...')
    key = '90052'
    answer = ''
    while key is not None:
        next_key = linked_list[key][0]
        comment = archive.getinfo(key + '.txt').comment.decode('ascii')
        answer += comment
        key = next_key

    print()

    print(f'Voila!')
    print(answer)

    print(f'Trying hockey.html...')
    pcutils.try_page('def/', 'hockey')
    message = pcutils.get_string_from_page('def/', 'hockey')
    print(f'Message: {message}')

    print(f'Trying oxygen.html')
    pcutils.try_page('def/', 'oxygen', caption='Next challenge page')
def get_answer():
    n = '1'
    answers = [n]
    for i in range(1, 31):
        answers.append(look_and_say(answers[i - 1]))
    print(f'Look and say lengths:')
    for i, n in enumerate(answers):
        print(f'  n = {i} -- length = {len(n)}')
    print()
    return str(len(answers[30]))


if __name__ == '__main__':
    pcutils.try_page('return/', 'bull',
                     un=UN, pw=PW,
                     caption='Next challenge page')
    print()

    page = 'sequence'
    pcutils.try_page('return/', page, ending='.txt',
                     un=UN, pw=PW,
                     caption='Clue')
    message = pcutils.get_string_from_page(
                     'return/', page, ending='.txt',
                     un=UN, pw=PW)
    print(f'Message: {message}')

    pcutils.try_page('return/', get_answer(),
                     un=UN, pw=PW,
                     caption='Next challenge page')
예제 #4
0
        return 'a'
    if ch == 'z':
        return 'b'
    return chr(ord(ch) + 2)


def shift_all(sentences):
    return [
        ''.join(shift2(ch) if 'a' <= ch <= 'z' else ch for ch in sentence)
        for sentence in sentences
    ]


if __name__ == '__main__':
    pcutils.try_page('def/', 'map', caption='Challenge page')

    print()

    encoded = pcutils.get_string_from_page('def/',
                                           'map',
                                           start='<font color="#f000f0">',
                                           end='</tr></td>')
    pcutils.print_lines(encoded.split('. '), 'Message to decode')

    pcutils.print_lines(''.join(shift_all(encoded)).split('. '),
                        'Decoded message')

    page = ''.join(shift2(ch) for ch in 'map')
    print(f'map shifted: {page}')
    pcutils.try_page('def/', page, '.html', caption='Next challenge page')
예제 #5
0
        10 + max([x for x, y in dots1] + [x for x, y in dots2]))
    for i in range(1, len(dots1)):
        pt1, pt2 = dots1[i - 1], dots1[i]
        cv2.line(canvas, pt1, pt2, pcutils.BLACK)

    for i in range(1, len(dots2)):
        pt1, pt2 = dots2[i - 1], dots2[i]
        cv2.line(canvas, pt1, pt2, pcutils.RED)

    cv2.imshow('Looks like a cow: ', canvas)
    cv2.waitKey(0)


if __name__ == '__main__':
    pcutils.try_page('return/', 'good', un=UN, pw=PW, caption='Challenge page')
    print()

    connect_the_dots(get_dots(1, 'first:', 'second:'),
                     get_dots(2, 'second:', '-->'))
    print()

    pcutils.try_page('return/', 'cow', un=UN, pw=PW, caption='Cow page')
    message = pcutils.get_string_from_page('return/', 'cow', un=UN, pw=PW)
    print(f'Message: {message}')

    pcutils.try_page('return/',
                     'bull',
                     un=UN,
                     pw=PW,
                     caption='Next challenge page')
예제 #6
0
'''
the python challenge 3
'''
import pcutils
import re

if __name__ == '__main__':
    pcutils.try_page('def/', 'equality', caption='Challenge page')

    print()

    mess_below = pcutils.get_string_from_page('def/',
                                              'equality',
                                              start='<!--',
                                              end='-->')
    pcutils.print_lines(
        mess_below.split(pcutils.NEWLINE)[0:10], 'Mess below from web page')
    print('...')

    print()

    pattern = '[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}'
    matches = re.findall(pattern, mess_below)
    pcutils.print_lines(matches, 'Matches')

    print()

    page = ''.join(s[4] for s in matches)
    pcutils.try_page('def/', page, caption='Trying page in url...')
    message = pcutils.get_string_from_page(
        'def/',
예제 #7
0
'''
the python challenge 2
'''
import pcutils
import collections

if __name__ == '__main__':
    pcutils.try_page('def/', 'ocr', caption='Challenge page')

    print()

    s = pcutils.get_string_from_page(
        'def/',
        'ocr',
        start='<!--',
        end='-->',
    )
    mess_below = s[s.index('%'):]
    pcutils.print_lines(
        mess_below.split(pcutils.NEWLINE)[0:10], 'Mess below from web page')
    print('...')

    print()

    frequencies = collections.defaultdict(lambda: 0)
    for ch in mess_below:
        if ch.isalnum():
            frequencies[ch] += 1
    pcutils.print_lines(frequencies.items(),
                        'Frequencies of characters in mess')