1 | sclass BoolGuesserByWordAtIndex extends F1<S, Bool> { |
2 | bool defaultValue; |
3 | Set<S> exceptions; |
4 | int wordIndex; |
5 | |
6 | *() {} |
7 | *(bool *defaultValue, Set<S> *exceptions, int *wordIndex) {} |
8 | |
9 | Bool get(S s) { |
10 | ret defaultValue ^ contains(exceptions, getWord(s, wordIndex)); |
11 | } |
12 | } |
13 | |
14 | static F1<S, Bool> boolGuesserByWordAtIndex(Map<S, Bool> examples, final int wordIndex) { |
15 | Map<S, Bool> map = mapKeys(examples, func(S s) { getWord(s, wordIndex) }); |
16 | int diff = countValues(map, true)-countValues(map, false); |
17 | print("diff=" + diff); |
18 | final bool defaultValue = diff > 0; |
19 | final Set<S> exceptions = new TreeSet(keysWithValue(map, !defaultValue)); |
20 | ret BoolGuesserByWordAtIndex(defaultValue, exceptions, wordIndex); |
21 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010890 |
Snippet name: | boolGuesserByWordAtIndex |
Eternal ID of this version: | #1010890/5 |
Text MD5: | 2c384c0474241d9da70b637e15e8f520 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-10-11 18:22:19 |
Source code size: | 741 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 497 / 517 |
Version history: | 4 change(s) |
Referenced in: | [show references] |