Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1010890 // boolGuesserByWordAtIndex

JavaX fragment (include)

sclass BoolGuesserByWordAtIndex extends F1<S, Bool> {
  bool defaultValue;
  Set<S> exceptions;
  int wordIndex;
  
  *() {}
  *(bool *defaultValue, Set<S> *exceptions, int *wordIndex) {}
  
  Bool get(S s) {
    ret defaultValue ^ contains(exceptions, getWord(s, wordIndex));
  }
}

static F1<S, Bool> boolGuesserByWordAtIndex(Map<S, Bool> examples, final int wordIndex) {
  Map<S, Bool> map = mapKeys(examples, func(S s) { getWord(s, wordIndex) });
  int diff = countValues(map, true)-countValues(map, false);
  print("diff=" + diff);
  final bool defaultValue = diff > 0;
  final Set<S> exceptions = new TreeSet(keysWithValue(map, !defaultValue));
  ret BoolGuesserByWordAtIndex(defaultValue, exceptions, wordIndex);
}

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: 496 / 515
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)