コード例 #1
0
def puzzlify(text):
    text = text.lower()
    code, actual = get_random_code()
    encode_table = string.maketrans("".join(actual),"".join(code))
    encoded_text = string.translate(text, encode_table)
    puzzle = Puzzle(encoded_text)
    puzzle.set("".join(code),"".join(actual))
    return puzzle
コード例 #2
0
def puzzlify(text):
    text = text.lower()
    code, actual = get_random_code()
    encode_table = string.maketrans("".join(actual), "".join(code))
    encoded_text = string.translate(text, encode_table)
    puzzle = Puzzle(encoded_text)
    puzzle.set("".join(code), "".join(actual))
    return puzzle
コード例 #3
0
def puzzlify(text):
    """ Given a text, randomly generate a dictionary 
        to encode the text. Return a Puzzle in the solved
        state.
    """
    code, actual = get_random_code()
    encode_table = string.maketrans(actual, code)
    puzz = text.lower().translate(encode_table)
    puzzle = Puzzle(puzz)
    puzzle.set(code, actual)
    return puzzle
コード例 #4
0
def puzzlify(text):
    """ Given a text, randomly generate a dictionary 
        to encode the text. Return a Puzzle in the solved
        state.
    """
    code, actual = get_random_code()
    encode_table = string.maketrans(actual, code)
    puzz = text.lower().translate(encode_table)
    puzzle = Puzzle(puzz)
    puzzle.set(code, actual)
    return puzzle
コード例 #5
0
def generate_puzzle(text):
    """ Given a text, randomly generate a dictionary 
        to encode the text. Return a Puzzle in the solved
        state.
    """
    code, actual = get_random_code()
    code = ''.join(code)
    actual = ''.join(actual)
    trtab = string.maketrans(actual, code)
    puzz = text.lower().translate(trtab)
    puzzle = Puzzle(puzz)
    puzzle.set(code, actual)
    return puzzle
コード例 #6
0
def generate_puzzle(text):
    """ Given a text, randomly generate a dictionary 
        to encode the text. Return a Puzzle in the solved
        state.
    """
    code, actual = get_random_code()
    code = ''.join(code)
    actual = ''.join(actual)
    trtab = string.maketrans(actual, code)
    puzz = text.lower().translate(trtab)
    puzzle = Puzzle(puzz)
    puzzle.set(code, actual)
    return puzzle
コード例 #7
0
def load_puzzle(filename):
    """ load_puzzle(filename)
        Return a Puzzle object initialized with data from a file.
        The file should be formatted with the puzzle in all caps,
        and a clue of the form '# X = g' on the last line, preceded
        by a blank line.
    """
    with open(filename) as infile:
        lines = infile.readlines()

    puzzle_text = ' '.join([line.strip() for line in lines[:-1]])
    clue = re.search(re.compile(r'.*([A-Z]).*([a-z])'), lines[-1]).groups()
    puzzle = Puzzle(puzzle_text)
    if clue:
        puzzle.set(*clue)
    return puzzle
コード例 #8
0
def load_puzzle(filename):
    """ load_puzzle(filename)
        Return a Puzzle object initialized with data from a file.
        The file should be formatted with the puzzle in all caps,
        and a clue of the form '# X = g' on the last line, preceded
        by a blank line.
    """
    with open(filename) as infile:
        lines = infile.readlines()

    puzzle_text = ' '.join([line.strip() for line in lines[:-1]])
    clue = re.search(re.compile(r'.*([A-Z]).*([a-z])'), lines[-1]).groups()
    puzzle = Puzzle(puzzle_text)
    if clue:
        puzzle.set(*clue)
    return puzzle