Created
December 6, 2016 22:39
-
-
Save j10sanders/47a6ce466a70754812fb2d44033d52dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scores = {"a": 1, "e": 1, "i": 1, "l": 1, "n": 1, "o": 1, "r": 1, "s": 1, "t": | |
1, "u": 1, "d": 2, "g": 2, "b": 3, "c": 3, "m": 3, "p": 3, "f": 4, | |
"h": 4, "v": 4, "w": 4, "y": 4, "k": 5, "j": 8, "x": 8, "q": 10, "z": 10} | |
def scrabble(x, n, cases): | |
words = [] | |
wordscores = [] | |
scrabble_ladder_l = [] | |
scrabble_ladder_r = [] | |
for i in cases: | |
i = list(i) | |
if len(i) == x: | |
words.append(cases) | |
j = sum([scores[letter] for letter in i]) | |
wordscores.append(j) | |
print(wordscores) | |
maxscore = wordscores.index(max(wordscores)) | |
print(maxscore) | |
for word in words[:maxscore]: | |
if (compareWords(words[maxscore], word)) is not None: | |
scrabble_ladder_l.append(compareWords(words[maxscore], word)) | |
print(scrabble_ladder_l) | |
for word in words[maxscore:]: | |
if (compareWords(words[maxscore], word)) is not None: | |
scrabble_ladder_r.append(compareWords(words[maxscore], word)) | |
print(scrabble_ladder_r) | |
if len(scrabble_ladder_l) > 0 and len(scrabble_ladder_r) > 0: | |
return (1) | |
if len(scrabble_ladder_l) == len(scrabble_ladder_r): | |
return True | |
def compareWords(word1, word2): | |
score = 0 | |
spell1 = list(word1) | |
for i, letter in enumerate(list(word2)): | |
if letter != spell1[i]: | |
score +=1 | |
if score ==1: | |
return word2 | |
else: | |
pass | |
x = 2 | |
n = 20 | |
cases = ["ae", "ax", "ay"] | |
print(scrabble(x, n, cases)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment