Libraryless. Click here for Pure Java version (6187L/43K/143K).
1 | !7 |
2 | |
3 | static CondensedStrings2 words; |
4 | |
5 | p { |
6 | File zip = loadLibrary("#1002028"); // words.zip |
7 | byte[] data = loadBinaryFromZip(zip, "words.txt"); |
8 | S text = fromUTF8(data); |
9 | //print("UTF expansion: " + (l(data)-l(text))); // if 0, then strings can be extra-condensed. |
10 | data = null; |
11 | L<S> lines = toLines(text); |
12 | //print("Sorted? " + yn(isSortedList(lines))); |
13 | //print("Percentage sorted: " + formatDouble(percentageSorted(lines), 3)); |
14 | //print("Unsorted indexes: " + struct(unsortedIndexes(lines))); |
15 | time { sort(lines); } |
16 | //print("Unsorted indexes: " + struct(unsortedIndexes(lines))); |
17 | text = null; |
18 | words = new CondensedStrings2(lines); |
19 | print(l(words) + " words loaded!"); |
20 | //printMemoryInfo(); |
21 | makeBot(); |
22 | } |
23 | |
24 | answer { |
25 | if (match("random english words", s)) |
26 | ret randomWords(10); |
27 | if (match("* random english words", s, m)) |
28 | ret randomWords(parseInt(m.get(0))); |
29 | if (match("1 random english word", s) || match("random english word", s)) |
30 | ret randomWords(1); |
31 | if (match("how many english words do you know?", s, m)) |
32 | ret format("I know * english words. Even funny ones such as ", words.size()) + quote(randomWord()); |
33 | if (match("is * an english word?", s, m)) |
34 | ret isWordQuick(m.unq(0)) ? " Yes." : "Not in my dictionary..."; |
35 | if "English words *-*" { |
36 | int i = parseInt(m.unq(0)); |
37 | int j = parseInt(m.unq(1)); |
38 | ret structure(subList(words, i-1, min(i+50, j-1))); |
39 | } |
40 | if "number of characters in english dictionary" |
41 | ret str(words.totalSize()); |
42 | if "number of different characters in english dictionary" |
43 | ret str(countDifferentChars()); |
44 | } |
45 | |
46 | static int countDifferentChars() { |
47 | new HashSet<Character> chars; |
48 | for (S s : words) |
49 | for (int i = 0; i < l(s); i++) |
50 | chars.add(s.charAt(i)); |
51 | ret l(chars); |
52 | } |
53 | |
54 | static S randomWord() { |
55 | ret words.get(random(words.size())); |
56 | } |
57 | |
58 | static S randomWords(int n) { |
59 | n = min(n, 100); |
60 | new L<S> l; |
61 | for (int i = 0; i < n; i++) |
62 | l.add(randomWord()); |
63 | ret join(" ", l) + (random(2) == 0 ? "?" : "!"); |
64 | } |
65 | |
66 | static bool isWord(S word) { |
67 | ret words.contains(toLower(word)); |
68 | } |
69 | |
70 | // assumes list is sorted (which we did) |
71 | static bool isWordQuick(S word) { |
72 | word = toLower(word); |
73 | int i = Collections.binarySearch(words, word); |
74 | ret i >= 0; |
75 | } |
Began life as a copy of #1002030
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002036 |
Snippet name: | Huge English Dictionary Bot |
Eternal ID of this version: | #1002036/5 |
Text MD5: | b7a3a86c5cac3c707232cc111019983d |
Transpilation MD5: | f3020440daa182822668ef3180f0abbc |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-04-07 14:59:29 |
Source code size: | 2309 bytes / 75 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 798 / 2556 |
Version history: | 4 change(s) |
Referenced in: | [show references] |