Libraryless. Click here for Pure Java version (1674L/11K/37K).
!752 static L<S> themap = litlist( "mine", "yours", "my", "your", "you are", "i am", "are you", "am i", "for me", "for you", "against me", "against you", "with me", "with you", "without me", "without you", "i", "you", "me", "you" ); p { makeBot("Switcheroo"); } answer { if (matchStart("switcheroo", s, m)) { S rest = m.rest(); ret switcheroo(rest); } } static S switcheroo(S s) { L<S> tok = javaTok(s); for (int i = 1; i < l(tok); i += 2) { for (int j = 0; j < l(themap); j += 2) { S x = themap.get(j), y = themap.get(j+1); L<S> tokx = javaTok(x), toky = javaTok(y); matchReplace(tok, i, tokx, toky); matchReplace(tok, i, toky, tokx); } } ret join(tok); } static void matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) { //printFormat("Matching * * *", i, get(tok, i), tokx); if (tokRegionMatch(tok, i, tokx)) { printFormat("Replacing * *", tokx, toky); for (int j = 0; j*2+1 < l(tokx); j++) tok.set(i+j*2, "*" + toky.get(1+j*2)); } } static boolean tokRegionMatch(L<S> tok, int i, L<S> tokx) { for (int j = 0; j*2+1 < l(tokx); j++) if (!eqic(get(tok, i+j*2), get(tokx, 1+j*2))) ret false; ret true; }
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