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

54
LINES

< > BotCompany Repo | #1002165 // Switch first/second person

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1674L/11K/37K).

1  
!752
2  
3  
static L<S> themap = litlist(
4  
  "mine", "yours",
5  
  "my", "your",
6  
  "you are", "i am",
7  
  "are you", "am i",
8  
  "for me", "for you",
9  
  "against me", "against you",
10  
  "with me", "with you",
11  
  "without me", "without you",
12  
  "i", "you",
13  
  "me", "you"
14  
);
15  
16  
p {
17  
  makeBot("Switcheroo");
18  
}
19  
20  
answer {
21  
  if (matchStart("switcheroo", s, m)) {
22  
    S rest = m.rest();
23  
    ret switcheroo(rest);
24  
  }
25  
}
26  
27  
static S switcheroo(S s) {
28  
  L<S> tok = javaTok(s);
29  
  for (int i = 1; i < l(tok); i += 2) {
30  
    for (int j = 0; j < l(themap); j += 2) {
31  
      S x = themap.get(j), y = themap.get(j+1);
32  
      L<S> tokx = javaTok(x), toky = javaTok(y);
33  
      matchReplace(tok, i, tokx, toky);
34  
      matchReplace(tok, i, toky, tokx);
35  
    }
36  
  }
37  
  ret join(tok);
38  
}
39  
40  
static void matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) {
41  
  //printFormat("Matching * * *", i, get(tok, i), tokx);
42  
  if (tokRegionMatch(tok, i, tokx)) {
43  
    printFormat("Replacing * *", tokx, toky);
44  
    for (int j = 0; j*2+1 < l(tokx); j++)
45  
      tok.set(i+j*2, "*" + toky.get(1+j*2));
46  
  }
47  
}
48  
49  
static boolean tokRegionMatch(L<S> tok, int i, L<S> tokx) {
50  
  for (int j = 0; j*2+1 < l(tokx); j++)
51  
    if (!eqic(get(tok, i+j*2), get(tokx, 1+j*2)))
52  
      ret false;
53  
  ret true;
54  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002165
Snippet name: Switch first/second person
Eternal ID of this version: #1002165/1
Text MD5: 42bc554505461090bec34066caa4a1a7
Transpilation MD5: c2611c559f1584feaa0f6aee33a0f928
Author: stefan
Category: nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-23 00:16:41
Source code size: 1270 bytes / 54 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 649 / 1727
Referenced in: [show references]