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

27
LINES

< > BotCompany Repo | #1000584 // LInputPattern (learner)

JavaX fragment (include)

// for "find" tasks (e.g. "abcde" to "[[abc]]de")
static class LInputPattern extends LearnerImpl {
  static boolean debug;
  String regexp = "", findMarker1 = "[[", findMarker2 = "]]";
  
  public void processInOut(Object _in, Object _out) {
    String in = (String) _in, out = (String) _out;
    int i = out.indexOf(findMarker1), j = out.indexOf(findMarker2, i+1);
    if (j < 0) return;
    String s = out.substring(i+2, j);
    regexp = s.replaceAll("\\d+", Matcher.quoteReplacement("\\d+"));
    if (debug)
      debug("regexp: " + regexp);
  }
  
  public String processIn(Object _in) {
    String in = (String) _in;
    if (regexp.length() == 0)
      return in;
    else
      return in.replaceAll("(" + regexp + ")", findMarker1 + "$1" + findMarker2);
  }
  
  public void toJava(Code code) {
    code.line(code.var + " = ((String) " + code.var + ").replaceAll(" + quote("(" + regexp + ")") + ", \"[[$1]]\");");
  }
}

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
439 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
// for "find" tasks (e.g. "abcde" to "[[abc]]de")
static class LInputPattern extends LearnerImpl {
static boolean debug;
String regexp = "", findMarker1 = "[[", findMarker2 = "]]";

public void processInOut(Object _in, Object _out) {
String in = (String) _in, out = (String) _out;
int i = out.indexOf(findMarker1), j = out.indexOf(findMarker2, i+1);
if (j < 0) return;
String s = out.substring(i+2, j);
regexp = s.replaceAll("\\d+", Matcher.quoteReplacement("\\d+"));
if (debug)
debug("regexp: " + regexp);
}

public String processIn(Object _in) {
String in = (String) _in;
if (regexp.length() == 0)
return in;
else
return in.replaceAll("(" + regexp + ")", findMarker1 + "$1" + findMarker2);
}

public void toJava(Code code) {
code.line(code.var + " = ((String) " + code.var + ").replaceAll(" + quote("(" + regexp + ")") + ", \"[[$1]]\");");
}
}
}}
2015-08-18 14:40:56  delete 
436 #1000604 (pitcher) 2015-08-18 14:40:29

add comment

Snippet ID: #1000584
Snippet name: LInputPattern (learner)
Eternal ID of this version: #1000584/1
Text MD5: 586a51fe7c20d4110db5e5492aacb90e
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-18 14:40:29
Source code size: 951 bytes / 27 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 994 / 1573
Referenced in: #722 - IOIOI Processor (v15)
#738 - IOIOI Solver (v16, most recent one)
#1000585 - LInputPatternPrefixSuffix (learner, developing)
#1000622 - FRegExp
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)