Skip to content

Commit 1d525b5

Browse files
Inefficient anagram solution needs to be replaced
1 parent 3cab87c commit 1d525b5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

cse231/anagrams/anagrams.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
anagrams.py
3+
4+
Author: Rafeh Qazi
5+
6+
Modified: June 2016
7+
8+
Copyright (C) 2016 Rafeh Qazi
9+
"""
10+
11+
from collections import Counter
12+
13+
14+
def read_file(file):
15+
with open(file, 'r') as f:
16+
return [word[:-1] for word in f]
17+
18+
19+
file_data = read_file('shortWordList.txt')
20+
21+
# print(file_data)
22+
#
23+
# for _ in range(5):
24+
# print('\n')
25+
#
26+
# anagrams = []
27+
# for word_1 in file_data:
28+
# file_data.pop(0)
29+
# word_1_anagrams = []
30+
# for word_2 in file_data:
31+
# if Counter(word_1) == Counter(word_2):
32+
# if word_2 not in anagrams:
33+
# word_1_anagrams.append(word_2)
34+
# anagrams.append(word_2)
35+
# if word_1_anagrams:
36+
# print(word_1_anagrams)
37+
38+
# print(anagrams)

cse231/anagrams/shortWordList.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
able
2+
acre
3+
bale
4+
beyond
5+
binary
6+
boat
7+
brainy
8+
care
9+
cat
10+
cater
11+
crate
12+
lawn
13+
list
14+
race
15+
react
16+
sheet
17+
silt
18+
slit
19+
trace

cse231/number_guessing_game.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def report_results(user_number, secret_number):
100100
return correct_digits, correct_pos_digits
101101

102102

103+
103104
def player_progress(num_of_guesses, user_guess, correct_digits, correct_pos_digits):
104105
"""
105106
Report the player's current progress.

0 commit comments

Comments
 (0)