Skip to content

Instantly share code, notes, and snippets.

@olaugh
Created January 29, 2010 20:21
Show Gist options
  • Save olaugh/290084 to your computer and use it in GitHub Desktop.
Save olaugh/290084 to your computer and use it in GitHub Desktop.
Index: src/libzyzzyva/LetterBag.cpp
===================================================================
--- src/libzyzzyva/LetterBag.cpp (revision 2547)
+++ src/libzyzzyva/LetterBag.cpp (working copy)
@@ -109,6 +109,8 @@
QList<QChar> letters;
QList<int> counts;
QList<const QList<double>*> combos;
+ bool useBlanks = false;
+
for (int i = 0; i < word.length(); ++i) {
QChar c = word.at(i);
@@ -139,33 +141,35 @@
}
totalCombos += thisCombo;
- // Calculate the combinations with one blank
- for (int i = 0; i < numLetters; ++i) {
- --counts[i];
- thisCombo = subChooseCombos[ letterFrequencies[BLANK_CHAR] ][1];
- for (int j = 0; j < numLetters; ++j) {
- thisCombo *= (*combos[j])[ counts[j] ];
+ if (useBlanks) {
+ // Calculate the combinations with one blank
+ for (int i = 0; i < numLetters; ++i) {
+ --counts[i];
+ thisCombo = subChooseCombos[ letterFrequencies[BLANK_CHAR] ][1];
+ for (int j = 0; j < numLetters; ++j) {
+ thisCombo *= (*combos[j])[ counts[j] ];
+ }
+ totalCombos += thisCombo;
+ ++counts[i];
}
- totalCombos += thisCombo;
- ++counts[i];
- }
- // Calculate the combinations with two blanks
- for (int i = 0; i < numLetters; ++i) {
- --counts[i];
- for (int j = i; j < numLetters; ++j) {
- if (!counts[j])
- continue;
- --counts[j];
- thisCombo = subChooseCombos[ letterFrequencies[BLANK_CHAR] ][2];
-
- for (int k = 0; k < numLetters; ++k) {
- thisCombo *= (*combos[k])[ counts[k] ];
+ // Calculate the combinations with two blanks
+ for (int i = 0; i < numLetters; ++i) {
+ --counts[i];
+ for (int j = i; j < numLetters; ++j) {
+ if (!counts[j])
+ continue;
+ --counts[j];
+ thisCombo = subChooseCombos[ letterFrequencies[BLANK_CHAR] ][2];
+
+ for (int k = 0; k < numLetters; ++k) {
+ thisCombo *= (*combos[k])[ counts[k] ];
+ }
+ totalCombos += thisCombo;
+ ++counts[j];
}
- totalCombos += thisCombo;
- ++counts[j];
+ ++counts[i];
}
- ++counts[i];
}
return totalCombos;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment