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

31
LINES

< > BotCompany Repo | #1005160 // LMath2 (learner)

JavaX fragment (include)

// can multiply a number with a fixed other number
// input: S (number)
// output: S (number)
static class LMath2 extends LearnerImpl {
  static boolean debug;
  BigInteger factor;

  public void processInOut(Object _in, Object _out) {
    if (debug)
      print("LMath2: in = " + struct(_in));
    S in = cast _in;
    S out = cast _out;
    BigInteger[] inNumbers = new BigInteger[] {bigint(in)};
    BigInteger[] outNumbers = new BigInteger[] {bigint(out)};
    findOperation(inNumbers, outNumbers);
  }
  
  public void findOperation(BigInteger[] in, BigInteger[] out) {
    if (l(in) != 1 || l(out) != 1) tilt();
    BigInteger f = out[0].divide(in[0]);
    if (!eq(out[0], in[0].multiply(f))) tilt();
    if (factor != null && neq(factor, f)) tilt();
    factor = f;
  }
  
  public String processIn(Object _in) {
    S in = cast _in;
    BigInteger[] inNumbers = new BigInteger[] {bigint(in)};
    ret str(inNumbers[0].multiply(factor));
  }
}

Author comment

Began life as a copy of #1005157

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

No comments. add comment

Snippet ID: #1005160
Snippet name: LMath2 (learner)
Eternal ID of this version: #1005160/1
Text MD5: 9740e01cf998c253d005476b250d8bbf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-10-17 02:18:48
Source code size: 982 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 468 / 776
Referenced in: [show references]