1 | // can multiply a number with a fixed other number |
2 | // input: S (number) |
3 | // output: S (number) |
4 | static class LMath2 extends LearnerImpl { |
5 | static boolean debug; |
6 | BigInteger factor; |
7 | |
8 | public void processInOut(Object _in, Object _out) { |
9 | if (debug) |
10 | print("LMath2: in = " + struct(_in)); |
11 | S in = cast _in; |
12 | S out = cast _out; |
13 | BigInteger[] inNumbers = new BigInteger[] {bigint(in)}; |
14 | BigInteger[] outNumbers = new BigInteger[] {bigint(out)}; |
15 | findOperation(inNumbers, outNumbers); |
16 | } |
17 | |
18 | public void findOperation(BigInteger[] in, BigInteger[] out) { |
19 | if (l(in) != 1 || l(out) != 1) tilt(); |
20 | BigInteger f = out[0].divide(in[0]); |
21 | if (!eq(out[0], in[0].multiply(f))) tilt(); |
22 | if (factor != null && neq(factor, f)) tilt(); |
23 | factor = f; |
24 | } |
25 | |
26 | public String processIn(Object _in) { |
27 | S in = cast _in; |
28 | BigInteger[] inNumbers = new BigInteger[] {bigint(in)}; |
29 | ret str(inNumbers[0].multiply(factor)); |
30 | } |
31 | } |
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: | 568 / 878 |
Referenced in: | [show references] |