-
Notifications
You must be signed in to change notification settings - Fork 1
/
JumbleSolver
53 lines (43 loc) · 1.58 KB
/
JumbleSolver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: aloks
#
# Created: 10/09/2013
# Copyright: (c) aloks 2013
# Licence: <your licence>
#-------------------------------------------------------------------------------
import sys
class Solver():
def __init__(self):
self.dictfile = "C:/Users/aloks/Downloads/dictionary.txt"
def getWords(self):
self.dictfile
word = (file(self.dictfile).read())
# Returns a list of words from dictionary.txt
return word.split()
def getRightWords(self, jumbleword):
possible_words = [] #This list will contain all the possible words
jumbled_word_length = len(jumbleword)
words = self.getWords()
for word in words:
jumbled_word = jumbleword
if len(word) == jumbled_word_length:
letters = list(word)
for letter in letters:
if jumbled_word.find(letter) != -1:
jumbled_word = jumbled_word.replace(letter,'',1)
if not jumbled_word:
#print possible works
possible_words.append(word)
return possible_words;
if __name__ == '__main__':
testObject = Solver()
if len(sys.argv) != 2:
print "python %s <jumbled_word>" % sys.argv[0]
sys.exit()
jumbled_input_strings= sys.argv[1]
possible_words = testObject.getRightWords(jumbled_input_strings)
print "possible_words_options:"
print '\n'.join(possible_words)