-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
186 lines (148 loc) · 8.75 KB
/
Program.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Find the most ambiguous ("worst") four-letter combos in Wordle. Streak killers
//string wordle_long_list = @"Data\wordle-allowed-guesses.txt";
//string wordle_short_list = @"Data\wordle-answers-alphabetical.txt";
string wordle_long_list = @"Data\wordle-nyt-allowed-guesses.txt";
string wordle_short_list = @"Data\wordle-nyt-answers-alphabetical.txt";
string output_long_list_focus = "output-longlist-focus.txt";
string output_short_list_focus = "output-shortlist-focus.txt";
string output_full_long_list_focus = "output-full-list.txt";
string prefix = ""; // "- "; // list prefix
Console.WriteLine("Finding the most ambiguous (\"worst\") four-letter combos in Wordle...");
Console.WriteLine();
var longList = File.ReadAllLines(wordle_long_list).OrderBy(w => w); // sorting is redundant but do anyway
var shortList = File.ReadAllLines(wordle_short_list).OrderBy(w => w);
var longCombos = GetCombos(shortList.Concat(longList)); // Note: Order matters here: displaying lists with default sorting shows short list items then long list
var shortCombos = GetCombos(shortList);
Dictionary<string, List<String>> GetCombos(IEnumerable<string> words) {
// e.g. "wor_y" => ["wordy", "worry"]
Dictionary<string, List<String>> combos = new();
foreach (var word in words) {
if (string.IsNullOrWhiteSpace(word)) continue;
if (word.StartsWith("//")) continue;
if (word.Length != 5) continue;
for (int i = 0; i < word.Length; i++) {
char[] chars = word.ToCharArray();
chars[i] = '_';
string underscored = new string(chars); // e.g. "_IGHT" or "F_GHT"
if (combos.ContainsKey(underscored)) {
combos[underscored].Add(word);
} else {
var newList = new List<string>();
newList.Add(word);
combos[underscored] = newList;
}
}
}
return combos;
}
void OutputLongFocus() {
using StreamWriter writer = new(output_long_list_focus);
writer.WriteLine("Worst combos ordered by most long list solutions: List of the most ambiguous four-letter wordle combos, ordered by number of allowed guesses. Only includes combos with at least one real answer from the short list. Count is given as ('total' = 'short list solutions' + 'additional long list solutions'). A '*' means the guess is allowed but not in the short list of possible answers. Source: https://github.com/pengowray/WorstWordle");
writer.WriteLine("");
var worstShortListCombos = shortCombos
//.OrderByDescending(l => l.Value.Count).ThenByDescending(l => longCombos[l.Key].Count).ThenBy(l => l.Key) // by short list count
.OrderByDescending(l => longCombos[l.Key].Count).ThenBy(l => l.Key) // by long list count
//.Where(l => l.Value.Count >= 2 || (l.Value.Count == 1 && longCombos[l.Key].Count >= 2)); // only if 2 or more items and 1 is in the short list
.Where(l => l.Value.Any()); // at least 1 short list
foreach (var item in worstShortListCombos) {
var key = item.Key;
var shortListGroup = item.Value;
var longListGroup = longCombos[key];
var nonAnswersButValid = longListGroup.Count - shortListGroup.Count;
if (nonAnswersButValid > 0) {
// put asterix on non-answer words
var longListGroupStarred = longListGroup
//.OrderBy(word => word)
.Select(word => GiveStar(key, word, shortListGroup));
//string count = $"({shortListGroup.Count} + {nonAnswersButValid})";
//string count = $"({shortListGroup.Count} / {longListGroup.Count})";
//string count = $"({longListGroup.Count})";
string count = $"({longListGroup.Count} = {shortListGroup.Count} + {nonAnswersButValid})";
writer.WriteLine($"{prefix}{key.ToUpper()} {count}: {string.Join(" ", longListGroupStarred)}");
} else {
string count = $"({shortListGroup.Count})";
//.Select(word => GiveStar(key, word, shortListGroup))
// note: never has "*"
writer.WriteLine($"{prefix}{key.ToUpper()} {count}: {string.Join(" ", shortListGroup.Select(word => GiveStar(key, word, shortListGroup)))}");
}
}
writer.Flush();
writer.Close();
}
OutputLongFocus();
void OutputShortFocus() {
using StreamWriter writer = new(output_short_list_focus);
writer.WriteLine("Worst combos ordered by most short list solutions: List of the most ambiguous four-letter wordle combos, ordered by most number of possible short list solutions. Count is given as ('short list solutions' + 'additional long list solutions' = 'total'). A '*' means the guess is allowed but not in the short list of possible answers. Source: https://github.com/pengowray/WorstWordle");
writer.WriteLine("");
var worstShortListCombos = shortCombos
.OrderByDescending(l => l.Value.Count).ThenByDescending(l => longCombos[l.Key].Count).ThenBy(l => l.Key) // by short list count
//.Where(l => l.Value.Count >= 2 || (l.Value.Count == 1 && longCombos[l.Key].Count >= 2)); // only if 2 or more items and 1 is in the short list
.Where(l => l.Value.Any()); // at least 1 short list
foreach (var item in worstShortListCombos) {
var key = item.Key;
var shortListGroup = item.Value;
var longListGroup = longCombos[key];
var nonAnswersButValid = longListGroup.Count - shortListGroup.Count;
if (nonAnswersButValid > 0) {
// put asterix on non-answer words
var longListGroupStarred = longListGroup
//.OrderBy(word => word) // note: default order puts short list first
.Select(word => GiveStar(key, word, shortListGroup));
//string count = $"({shortListGroup.Count} / {longListGroup.Count})";
//string count = $"({longListGroup.Count})";
//string count = $"({shortListGroup.Count} + {nonAnswersButValid})";
//string count = $"({longListGroup.Count} = {shortListGroup.Count} + {nonAnswersButValid})";
string count = $"({shortListGroup.Count} + {nonAnswersButValid} = {longListGroup.Count})";
writer.WriteLine($"{prefix}{key.ToUpper()} {count}: {string.Join(" ", longListGroupStarred)}");
} else {
string count = $"({shortListGroup.Count})";
writer.WriteLine($"{prefix}{key.ToUpper()} {count}: {string.Join(" ", shortListGroup)}");
}
}
writer.Flush();
writer.Close();
}
OutputShortFocus();
void OutputLongList() {
using StreamWriter writer = new(output_full_long_list_focus);
writer.WriteLine("Full list of worst combos ordered by most long list solutions: List of the most ambiguous four-letter wordle combos, ordered by number of possible long list solutions. Includes combos even without a real answer from the short list. Count is given as ('total' = 'short list solutions' + 'additional long list solutions'). A '*' means the guess is allowed but not in the short list of possible answers. Source: https://github.com/pengowray/WorstWordle");
writer.WriteLine("");
var worstLongListCombos = longCombos
.OrderByDescending(l => l.Value.Count) // by long count
.ThenByDescending(l => shortCombos.ContainsKey(l.Key) ? shortCombos[l.Key].Count : 0)
.ThenBy(l => l.Key);
foreach (var longItem in worstLongListCombos) {
var key = longItem.Key;
var longListGroup = longItem.Value;
var shortListGroup = shortCombos.ContainsKey(key) ? shortCombos[key] : new List<string>();
var nonAnswersButValid = longListGroup.Count - shortListGroup.Count;
// put asterix on non-answer words
var longListGroupStarred = longListGroup
//.OrderBy(word => word)
.Select(word => GiveStar(key, word, shortListGroup));
string count = $"({longListGroup.Count} = {shortListGroup.Count} + {nonAnswersButValid})";
writer.WriteLine($"{prefix}{key.ToUpper()} {count}: {string.Join(" ", longListGroupStarred)}");
}
writer.Flush();
writer.Close();
}
OutputLongList();
string GiveStar(string underscored, string solution, IEnumerable<string> shortGroup) {
string longlistStar = shortGroup.Contains(solution) ? "" : "*";
//string nowayStar = DoubleLetter(underscored, solution) ? "" : "‡";
string nowayStar = ""; // actually nah don't mark just because same letter twice.
return $"{nowayStar}{longlistStar}{solution}";
}
bool DoubleLetter(string underscored, string solution) {
int underscore = underscored.IndexOf('_');
if (underscore == -1) {
return true; // error / shouldn't happen
}
var ch = solution.Substring(underscore, 1);
if (underscored.Contains(ch)) {
// solution has same letter twice. That can actually happen.
return false;
}
return true;
}
Console.WriteLine("Done.");