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

38
LINES

< > BotCompany Repo | #1000885 // Answer questions 2

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

Libraryless. Click here for Pure Java version (234L/2K/7K).

!747

m {
  static S question = "Is port 80 open?";
  
  static class ThePortOracle {
    static S isPort_open(S s) {
      int port = parseInt(s);
      print("I'll check port " + port + "..."); 
      boolean b = isPortOpen(port);
      return b ? "Yes, it is open!" : "No, it is not open.";
    }
  }
  
  static S answerQuestion(S question) {
    L<S> tok = parse(question);
    S[] m = match2(parse("is port * open"), tok);
    if (m != null) return ThePortOracle.isPort_open(m[0]);
    return unknown(question);
  }
  
  static S unknown(S question) {
    return "? Unknown question: " + question;
  }

  p {
    if (args.length != 0)
      question = join(" ", args);
    print("Q: " + question);
    
    S answer = answerQuestion(question);
    print("A: " + answer);
  }
  
  static L<S> parse(S s) {
    return tokensToLowerCase(dropPunctuation(javaTokPlusPeriod(s)));
  }
}

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: #1000885
Snippet name: Answer questions 2
Eternal ID of this version: #1000885/1
Text MD5: 7e87bd40a6db5675c3e2bcc4881cf119
Transpilation MD5: 5d1fd4f6f5668fbb978d173babecd3ea
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-05 15:14:33
Source code size: 922 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 622 / 618
Referenced in: [show references]