Snapshot permission updates.

This commit is contained in:
dongar committed 2024-03-07 09:46:05 -06:00
1 parent 414380740f
commit d570b16b60
3 files changed
+43 -5

No files matched your search

+22 -3
View File
@@ -61,10 +61,29 @@ class SimilaritySolver(object):
for word in wordle_dictionary: for word in wordle_dictionary:
scored_words[word] = self._score_word(position_matches, word_matches, word) scored_words[word] = self._score_word(position_matches, word_matches, word)
result = list(wordle_dictionary) # Return as list of (word, score) sorted by high-score, word.
result.sort(key=lambda word: scored_words[word], reverse=True) result = sorted(scored_words.items(), key=lambda kv: kv[0])
result = sorted(result, key=lambda kv: kv[1], reverse=True)
return result
return [(word, scored_words[word]) for word in result]
class LimitsSolver(object):
def scored_words(self, words=dictionary.words()):
# word: score
scored_words = dict()
for word in words:
reduced = const.filter_words(words)
# Our score is how many words did we remove from consideration.
score = len(words) - len(reduced)
scored_words[word] = score
# Return as list of (word, score) sorted by high-score, word.
result = sorted(scored_words.items(), key=lambda kv: kv[0])
result = sorted(result, key=lambda kv: kv[1], reverse=True)
return result
if __name__ == "__main__": if __name__ == "__main__":
+20 -1
View File
@@ -2,15 +2,18 @@
import unittest import unittest
import dictionary
import solver import solver
test_dictionary = dictionary.words()
class TestSolver(unittest.TestCase): class TestSolver(unittest.TestCase):
def test_SimilaritySolver(self): def test_SimilaritySolver(self):
"""Minimal end to end test.""" """Minimal end to end test."""
solve = solver.SimilaritySolver() solve = solver.SimilaritySolver()
result = solve.scored_words() result = solve.scored_words(test_dictionary)
expected = [ expected = [
("cares", 139631), ("cares", 139631),
@@ -22,6 +25,22 @@ class TestSolver(unittest.TestCase):
self.assertListEqual(result[:5], expected) self.assertListEqual(result[:5], expected)
def test_LimitsSolver(self):
"""Minimal end to end test."""
solve = solver.LimitsSolver()
result = solve.scored_words(test_dictionary)
expected = [
("aahed", 5),
("aalii", 5),
("aargh", 5),
("aaron", 5),
("abaca", 5),
]
self.assertListEqual(result[:5], expected)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
+1 -1
View File
@@ -9,7 +9,7 @@
"editor.defaultFormatter": "ms-python.black-formatter", "editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.organizeImports": true "source.organizeImports": "explicit"
}, },
}, },
"python.formatting.provider": "none", "python.formatting.provider": "none",