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
Beispiel #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
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
Beispiel #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
Beispiel #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
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
Beispiel #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
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