1 | // extensive version (better results) with full search |
2 | |
3 | static class LCombineTwoFunctions2 extends LearnerImpl { |
4 | static boolean debug; |
5 | static long instances; |
6 | Stepper stepper; |
7 | new List<O[]> examples; |
8 | |
9 | *() { |
10 | ++instances; |
11 | if (debug) |
12 | debug("Instances: " + instances); |
13 | } |
14 | public void finalize() {--instances; } |
15 | |
16 | public void processInOut(O in, O out) { |
17 | examples.add(new O[] {in, out}); |
18 | |
19 | if (stepper == null) |
20 | stepper = new Stepper(allFunctions()); |
21 | |
22 | while (!stepper.ended()) { |
23 | long time = System.currentTimeMillis(); |
24 | boolean b = check(stepper.current()); |
25 | time = System.currentTimeMillis()-time; |
26 | if (debug) debug("check time: " + time); |
27 | if (b) |
28 | ret; // ok, keep |
29 | else |
30 | stepper.step(); |
31 | } |
32 | |
33 | fail(); |
34 | } |
35 | |
36 | boolean check(Function[] fg) { |
37 | if (debug) { |
38 | debug("Examples: " + examples.size() + ", stepper size: " + stepper.functions.size()); |
39 | debug("Checking " + structure(fg)); |
40 | } |
41 | for (O[] e : examples) { |
42 | O o = tryProcess(fg[0], e[0]); |
43 | if (o != null) { |
44 | O x = tryProcess(fg[1], o); |
45 | if (e[1].equals(x)) |
46 | continue; // example ok |
47 | } |
48 | ret false; |
49 | } |
50 | ret true; // all examples ok |
51 | } |
52 | |
53 | public O processIn(O in) { |
54 | Function[] fg = stepper.current(); |
55 | ret fg[1].process(fg[0].process(in)); |
56 | } |
57 | |
58 | static O tryProcess(Function f, O in) null on exception { |
59 | ret f.process(in); |
60 | } |
61 | |
62 | static class Stepper { |
63 | List<Function> functions; |
64 | int i1, i2; |
65 | |
66 | *(List<Function> *functions) {} |
67 | |
68 | boolean ended() { |
69 | ret i1 >= functions.size(); |
70 | } |
71 | |
72 | Function[] current() { |
73 | ret new Function[] {functions.get(i1), functions.get(i2)}; |
74 | } |
75 | |
76 | void step() { |
77 | if (i2 < functions.size()-1) ++i2; |
78 | else { ++i1; i2 = 0; } |
79 | } |
80 | } |
81 | } |
Began life as a copy of #1000500
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
ID | Author/Program | Comment | Date | |
---|---|---|---|---|
913 | #1000604 (pitcher) | 2015-08-20 15:28:24 | ||
912 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { // extensive version (better results) with full search static class LCombineTwoFunctions2 extends LearnerImpl { static boolean debug; static long instances; Stepper stepper; new List<O[]> examples; *() { ++instances; if (debug) debug("Instances: " + instances); } public void finalize() {--instances; } public void processInOut(O in, O out) { examples.add(new O[] {in, out}); if (stepper == null) stepper = new Stepper(allFunctions()); while (!stepper.ended()) { long time = System.currentTimeMillis(); boolean b = check(stepper.current()); time = System.currentTimeMillis()-time; if (debug) debug("check time: " + time); if (b) ret; // ok, keep else stepper.step(); } fail(); } boolean check(F[] fg) { if (debug) { debug("Examples: " + examples.size() + ", stepper size: " + stepper.functions.size()); debug("Checking " + structure(fg)); } for (O[] e : examples) { O o = tryProcess(fg[0], e[0]); if (o != null) { O x = tryProcess(fg[1], o); if (e[1].equals(x)) continue; // example ok } ret false; } ret true; // all examples ok } public O processIn(O in) { F[] fg = stepper.current(); ret fg[1].process(fg[0].process(in)); } static O tryProcess(F f, O in) null on exception { ret f.process(in); } static class Stepper { List<Function> functions; int i1, i2; *(List<Function> *functions) {} boolean ended() { ret i1 >= functions.size(); } Function[] current() { ret new Function[] {functions.get(i1), functions.get(i2)}; } void step() { if (i2 < functions.size()-1) ++i2; else { ++i1; i2 = 0; } } } } }} | 2015-08-20 01:43:10 | delete |
Snippet ID: | #1000506 |
Snippet name: | LCombineTwoFunctions2 (learner) |
Eternal ID of this version: | #1000506/1 |
Text MD5: | b5c33c61bcf156a6da83e68f13f209bc |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-10-17 01:25:10 |
Source code size: | 1937 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 935 / 1580 |
Referenced in: | [show references] |