def main():

    # try to read an existing or new puzzle from command line (not required)
    try:
        puzzle_idx = sys.argv[1].strip().upper()
    except:
        print('Please enter a puzzle. Exiting...')
        exit(0)

    if puzzle_idx is not None:

        # check validity of letters
        utils.check_letters(puzzle_idx)

        # choose standard sorting for all puzzle file names
        puzzle_idx = utils.sort_letters(puzzle_idx)

    # select puzzle, generate it if it doesn't exist
    puzl_path = utils.select_puzzle(puzzle_idx)

    # load json puzzle data
    puzl = utils.read_puzzle(puzl_path)

    # solve puzzle (cheat mode)
    solve(puzl)
def get_letters():

    alphabet_list = list(string.ascii_uppercase)

    while True:
        # generate sample of alphabet (can inlcude each letter only once)
        random_list = random.sample(alphabet_list, params.TOTAL_LETTER_COUNT)

        # make sure each letter list includes at least one vowel
        if [i for i in random_list if i in params.VOWEL_LIST]:
            return utils.sort_letters(''.join(random_list))
def main(puzzle_input=None):

    # get array of previously generated puzzles, to check against
    existing_puzzles = get_existing_puzzles()

    words = get_words(params.WORD_LIST_PATH)
    #words = words[0:10000] #debug
    print('total words: ', len(words))
    pool = get_pangramable_letter_pool(words)
    print(f'unique {params.TOTAL_LETTER_COUNT}-letter pool: ' + str(len(pool)))

    # header for csv output
    print('\t'.join(
        ('letters', 'word_count', 'total_score', 'pangram_count', 'is_valid')))

    if len(sys.argv) > 1:
        puzzle_input = sys.argv[1].strip().upper()
    else:
        puzzle_input = None

    # user has requested a specific puzzle be created
    if puzzle_input is not None:
        # check validity of letters
        utils.check_letters(puzzle_input)

        # manually request one puzzle by defining letters  on command line
        # alphabetize the non-center letters (all but first in array)
        puzzle_input = utils.sort_letters(puzzle_input)

        make_puzzles(words, pool, existing_puzzles, puzzle_input)

    # user/code has no specific puzzle to create, generating many
    else:
        idx_valid = 0

        # generating N puzzles based on params
        for _ in range(params.MAX_PUZZLE_TRIES):
            idx_valid += make_puzzles(words, pool, existing_puzzles, None)

            # reached target count of puzzles, exiting loop
            if idx_valid >= params.PUZZLE_COUNT:
                exit(0)

    return puzzle_input
def main():
    
    # try to read an existing or new puzzle from command line (not required)
    try:
        puzzle_idx = sys.argv[1].strip().upper()
    except:
        puzzle_idx = None

    if puzzle_idx is not None:
        
        # check validity of letters
        utils.check_letters(puzzle_idx)

        # choose standard sorting for all puzzle file names
        puzzle_idx = utils.sort_letters(puzzle_idx)

    puzl_path = utils.select_puzzle(puzzle_idx)

    puzl = utils.read_puzzle(puzl_path)

    play(puzl)
def main(puzzle_input=None):

    words = get_words(params.WORD_LIST_PATH)
    #words = words[0:10000] #debug

    # header for csv output
    print('\t'.join(('index', 'letters', 'word_count', 'total_score',
                     'pangram_count', 'is_valid')))

    if len(sys.argv) > 1:
        puzzle_input = sys.argv[1].strip().upper()
    else:
        puzzle_input = None

    # user has requested a specific puzzle be created
    if puzzle_input is not None:
        # check validity of letters
        utils.check_letters(puzzle_input)

        # manually request one puzzle by defining letters  on command line
        # alphabetize the non-center letters (all but first in array)
        puzzle_input = utils.sort_letters(puzzle_input)

        make_puzzles(words, puzzle_input)

    # user/code has no specific puzzle to create, generating many
    else:
        idx_valid = 0

        # generating N puzzles based on params
        for i in range(params.MAX_PUZZLE_TRIES):
            idx_valid += make_puzzles(words, None)

            # reached target count of puzzles, exiting loop
            if idx_valid >= params.PUZZLE_COUNT:
                exit(0)

    return puzzle_input
def get_letters_from(letters_list):
    # pick one entry at random, then shuffle the letters
    letters = random.choice(letters_list)
    letters = ''.join(random.sample(letters, len(letters)))
    return utils.sort_letters(letters)