!7 static CondensedStrings2 words; p { File zip = loadLibrary("#1002028"); // words.zip byte[] data = loadBinaryFromZip(zip, "words.txt"); S text = fromUTF8(data); //print("UTF expansion: " + (l(data)-l(text))); // if 0, then strings can be extra-condensed. data = null; L lines = toLines(text); //print("Sorted? " + yn(isSortedList(lines))); //print("Percentage sorted: " + formatDouble(percentageSorted(lines), 3)); //print("Unsorted indexes: " + struct(unsortedIndexes(lines))); time { sort(lines); } //print("Unsorted indexes: " + struct(unsortedIndexes(lines))); text = null; words = new CondensedStrings2(lines); print(l(words) + " words loaded!"); //printMemoryInfo(); makeBot(); } answer { if (match("random english words", s)) ret randomWords(10); if (match("* random english words", s, m)) ret randomWords(parseInt(m.get(0))); if (match("1 random english word", s) || match("random english word", s)) ret randomWords(1); if (match("how many english words do you know?", s, m)) ret format("I know * english words. Even funny ones such as ", words.size()) + quote(randomWord()); if (match("is * an english word?", s, m)) ret isWordQuick(m.unq(0)) ? " Yes." : "Not in my dictionary..."; if "English words *-*" { int i = parseInt(m.unq(0)); int j = parseInt(m.unq(1)); ret structure(subList(words, i-1, min(i+50, j-1))); } if "number of characters in english dictionary" ret str(words.totalSize()); if "number of different characters in english dictionary" ret str(countDifferentChars()); } static int countDifferentChars() { new HashSet chars; for (S s : words) for (int i = 0; i < l(s); i++) chars.add(s.charAt(i)); ret l(chars); } static S randomWord() { ret words.get(random(words.size())); } static S randomWords(int n) { n = min(n, 100); new L l; for (int i = 0; i < n; i++) l.add(randomWord()); ret join(" ", l) + (random(2) == 0 ? "?" : "!"); } static bool isWord(S word) { ret words.contains(toLower(word)); } // assumes list is sorted (which we did) static bool isWordQuick(S word) { word = toLower(word); int i = Collections.binarySearch(words, word); ret i >= 0; }