--- /dev/null
+from string import ascii_lowercase
+import json
+import random
+
+with open("pruned_words.json", 'r') as f:
+ word_list = json.load(f)
+alphabet = ascii_lowercase
+vowels = "aeiouy" # y for special case like rhythm
+
+print("Strange Data about english words")
+
+letter_frequency = {letter: 0 for letter in alphabet}
+for word in word_list:
+ for letter in word:
+ letter_frequency[letter] += 1
+
+
+# print(letter_frequency)
+
+def get_value(a):
+ return letter_frequency[a]
+
+
+print(f"The most common letter is {max(letter_frequency, key=get_value)}.")
+print(f"The least common letter is {min(letter_frequency, key=get_value)}.")
+
+
+def get_second(a):
+ return a[1]
+
+
+total_letters = sum(letter_frequency.values())
+print(f"The total # of letters is {total_letters}.")
+
+letters = []
+weights = []
+for i in letter_frequency:
+ letters.append((round(letter_frequency[i] / total_letters * 100, 2), i))
+ weights.append(letter_frequency[i] / total_letters * 100)
+
+# print(letters)
+# print(weights)
+letters.sort(reverse=True)
+print("Percentage Composition")
+print(*letters)
+
+print("Choosing 16 letters using these weights")
+print(random.choices(alphabet, weights=weights, k=16))
+
+
+def non_vowel_substr(w):
+ vowel_indexes = []
+ for i, l in enumerate(w):
+ if l in vowels:
+ vowel_indexes.append(i)
+ longest_substr = 0
+ prev = -1
+ for val in vowel_indexes:
+ c = val - prev
+ if c > longest_substr:
+ longest_substr = c
+ # print(w[prev:val])
+ prev = val
+ c = len(w) - prev
+ if c > longest_substr:
+ longest_substr = c
+ # print(w[prev:len(w)])
+
+ return longest_substr - 1
+
+
+longest = 0
+longest_value = ""
+for word in word_list:
+ l = non_vowel_substr(word)
+ if l >= longest:
+ longest_value = word
+ longest = l
+print(f'The longest substring that has no vowels is in "{longest_value}" and has length {longest}.')
+from random import choice
+from queue import Queue
+from string import ascii_lowercase
+import json
+
+length, width = 4, 4
+with open("pruned_words.json", 'r') as f:
+ word_list = json.load(f)
+alphabet = ascii_lowercase
+weights = [8.464812190575197, 1.8290213382006486, 4.377463842181293, 3.238497204031964, 10.77374340292079,
+ 1.1220794892410257, 2.3639146242995768, 2.64283880414943, 8.95783107183879, 0.15584834882323761,
+ 0.7667338050095298, 5.577710795267362, 3.009862381185312, 7.195528282969081, 7.200021981915867,
+ 3.2521214123037474, 0.16781246449047607, 7.0440305216612025, 7.162211941733039, 6.607483411238427,
+ 3.7628002442053465, 0.945823450296398, 0.6405381447778209, 0.29978982655180736, 2.0193881642839093,
+ 0.4220928558487209]
+
+class Tile:
+
+ def __init__(self, x, y, letter):
+ self.letter = letter
+ self.neighbors = set()
+ for i in range(-1, 2):
+ for j in range(-1, 2):
+ if not (i == 0 and j == 0):
+ tx, ty = x + i, y + j
+ if (0 <= tx < width) and (0 <= ty < length):
+ self.neighbors.add((tx, ty))
+
+
+def find_words(b):
+ words = set()
+ q = Queue()
+ for i in b:
+ q.put((b[i].letter, i, set()))
+
+ while not q.empty():
+ word, current, seen = q.get()
+ if current in seen:
+ continue
+ else:
+ seen.add(current)
+
+ if len(word) >= length * width:
+ break
+
+ if word in word_list:
+ words.add(word)
+
+ for i in b[current].neighbors:
+ q.put((word + b[i].letter, i, seen.copy()))
+ return words
+
+
+board = {(i, j): Tile(i, j, choice(alphabet)) for i in range(width) for j in range(length)}
+
+for i, val in enumerate(board.values()):
+ print(val.letter, end=" ")
+ if (i + 1) % 4 == 0:
+ print()
+
+print(find_words(board))
+# c l t a
+# h x d o
+# r a m u
+# t f k g
+# {'haku', 'aku', 'trah', 'toma', 'fam', 'gud', 'frt', 'amdt', 'kadu', 'aft', 'rad', 'adam', 'tao', 'arf', 'fax', 'art', 'max', 'rat', 'adat', 'oda', 'dao', 'tod', 'tax', 'taku', 'mat', 'kudo', 'rha', 'omar', 'dar', 'douma', 'haft', 'moat', 'fram', 'dum', 'odum', 'rah', 'doug', 'moa', 'chat', 'xat', 'udo', 'dart', 'fado', 'kaf', 'mota', 'mud', 'dug', 'trad', 'odax', 'tom', 'cham', 'amu', 'xcl', 'udom', 'kam', 'raku', 'tar', 'toad', 'hld', 'tou', 'rada', 'mot', 'arx', 'trf', 'mad', 'mudar', 'mart', 'toa', 'mxd', 'maku', 'duo', 'cha', 'mado', 'toda', 'doum', 'mfr', 'tra', 'haf', 'oat', 'chart', 'dat', 'rax', 'dom', 'doat', 'adar', 'gum', 'dak', 'dato', 'ada', 'chad', 'adm', 'duka', 'marx', 'fart', 'chaft', 'mug', 'hat', 'ham', 'dumka', 'tad', 'ram', 'kat', 'tfr', 'kart', 'tram', 'oud', 'hcl', 'dam', 'ado', 'daft', 'dot', 'mah', 'duma', 'moud', 'raft', 'mar', 'dah', 'atom', 'far', 'mou', 'tam', 'hart', 'tahr', 'frat', 'hak', 'adatom', 'fra', 'char', 'toug', 'had', 'oad', 'fad', 'fat', 'doa', 'mod'}
with open("pruned_words.json", 'r') as f:
word_list = json.load(f)
-
-
pygame.init()
SCREEN_WIDTH, SCREEN_HEIGHT = 720, 720
dimensions = pygame.Vector2(SCREEN_WIDTH, SCREEN_HEIGHT)
-center = pygame.Vector2(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)
+center = pygame.Vector2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
screen = pygame.display.set_mode(dimensions, pygame.RESIZABLE)
pygame.display.set_caption("Word Hunt")
fps = 60
alphabet = string.ascii_lowercase
+weights = [8.464812190575197, 1.8290213382006486, 4.377463842181293, 3.238497204031964, 10.77374340292079,
+ 1.1220794892410257, 2.3639146242995768, 2.64283880414943, 8.95783107183879, 0.15584834882323761,
+ 0.7667338050095298, 5.577710795267362, 3.009862381185312, 7.195528282969081, 7.200021981915867,
+ 3.2521214123037474, 0.16781246449047607, 7.0440305216612025, 7.162211941733039, 6.607483411238427,
+ 3.7628002442053465, 0.945823450296398, 0.6405381447778209, 0.29978982655180736, 2.0193881642839093,
+ 0.4220928558487209]
+
class Colour:
- WHITE = (255,255,255)
- GRAY = (255/2,255/2,255/2)
- LIGHT_GRAY = (255*2/3,255*2/3,255*2/3)
- BLACK = (0,0,0)
+ WHITE = (255, 255, 255)
+ GRAY = (255 / 2, 255 / 2, 255 / 2)
+ LIGHT_GRAY = (255 * 2 / 3, 255 * 2 / 3, 255 * 2 / 3)
+ BLACK = (0, 0, 0)
RED = (255, 0, 0)
- GREEN = (0,255,0)
- BLUE = (0,0,255)
- YELLOW = (255/2, 255/2,0)
+ GREEN = (0, 255, 0)
+ BLUE = (0, 0, 255)
+ YELLOW = (255 / 2, 255 / 2, 0)