Sorry, your browser is not supported
To have the best experience using Skillshare, we recommend that you use one of these supported browsers.

22

1

I'm gonna pop some words, only got 20 Scrabble tiles in mah pocket...

scores = {"A": 1, "C": 3, "B": 3, "E": 1, "D": 2, "G": 2,
         "F": 4, "I": 1, "H": 4, "K": 5, "J": 8, "M": 3,
         "L": 1, "O": 1, "N": 1, "Q": 10, "P": 3, "S": 1,
         "R": 1, "U": 1, "T": 1, "W": 4, "V": 4, "Y": 4,
         "X": 8, "Z": 10}

f = open("sowpods.txt", "r")
words = []
for line in f:
    line = line.strip()
    words.append(line)
f.close()

import sys
rack = sys.argv[1]

blank_tile = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

first_rack = list(rack)
valid_words = []
if len(first_rack) == 6:
    for tile in blank_tile:
        for word in words:
            scrabble_rack = list(rack)
            scrabble_rack.append(tile)
            candidate = True
            for letter in word:
                if letter not in scrabble_rack:
                    candidate = False
                else:
                    scrabble_rack.remove(letter)
            if candidate == False or word in valid_words:
                pass
            else:
                valid_words.append(word)



    else:
        candidate = True
        for letter in word:
            if letter not in scrabble_rack:
                candidate = False
            else:
                scrabble_rack.remove(letter)
        if candidate == True:
            valid_words.append(word)
    
scorewords = []
for word in valid_words:
    point_total = 0
    score_and_word = []
    for letter in word:
        point_total = point_total + scores[letter]
    score_and_word.append(point_total)
    score_and_word.append(word)
    scorewords.append(score_and_word)
scorewords.sort()

for pair in scorewords:
    score = pair[0]
    word = pair[1]
    print(str(score) + " " + word)

#DONE, DONE, and DONE!

Improved project (to incorporate letters already on the board):

scores = {"A": 1, "C": 3, "B": 3, "E": 1, "D": 2, "G": 2,
         "F": 4, "I": 1, "H": 4, "K": 5, "J": 8, "M": 3,
         "L": 1, "O": 1, "N": 1, "Q": 10, "P": 3, "S": 1,
         "R": 1, "U": 1, "T": 1, "W": 4, "V": 4, "Y": 4,
         "X": 8, "Z": 10}
         
f = open("sowpods2.txt", "r")
words = []
for line in f:
    line = line.strip()
    words.append(line)
f.close()

import sys
rack = sys.argv[1]

common_words = []
for word in words:
    if len(word) <= 10:
        common_words.append(word)

valid_words = []
for word in common_words:
    scrabble_rack = list(rack)
    candidate = True
    for letter in word:
        if letter not in scrabble_rack and candidate == "False2":
            candidate = "False3"
        elif letter not in scrabble_rack and candidate == "False1":
            candidate = "False2"
        elif letter not in scrabble_rack and candidate == True:
            candidate = "False1"
        elif letter in scrabble_rack:
            scrabble_rack.remove(letter)
    if candidate != "False3":
        valid_words.append(word)


scorewords = []
for word in valid_words:
    point_total = 0
    score_and_word = []
    for letter in word:
        point_total = point_total + scores[letter]
    score_and_word.append(point_total)
    score_and_word.append(word)
    scorewords.append(score_and_word)
scorewords.sort()

for pair in scorewords:
    score = pair[0]
    word = pair[1]
    print(str(score) + " " + word)

Comments

Please sign in or sign up to comment.