예제 #1
0
from pangrams import PangramFinder

# Get initial pangram
pg = PangramFinder()
results = pg.run_search(10, 1, 10, False)[0]["pangram"]

def optimize(pangram):
    """
    
    """
    num_copies = len(pangram) # one set for swapping, one for removing
    copies = list()
    
    for index in range(num_copies):
        copy = swap(pangram, index)
        copies.append(copy)

    


def swap(pangram, index):
    # takes a string. breaks it into a list. swaps word at <index> with a random word
    # TODO: All this shit

def remove(pangram, index):
    # TODO: All this shit

예제 #2
0
import random

from pangrams import PangramFinder


# Get initial pangram
pg = PangramFinder()
results = pg.run_search(10, 1, 10, True)[0]["pangram"]

def optimize(pangram, iterations):
    """

    """
    if iterations > 0:
        num_copies = len(pangram.split()) # one set for swapping, one for removing
        copies = list()
        copies.append(pangram)
        for index in range(0, num_copies - 1):
            copies.append(swap(pangram, index))
            #copies.append(remove(pangram, index))

        scored = pg.score(copies)
        return optimize(pg.get_top_scores(1, scored)[0]["pangram"], iterations - 1)
    else:
        return pangram

def swap(pangram, index):
    """
    Swaps a word in a pangram at [index]
    """
    words = pangram.split()