Uses 9620K of libraries. Click here for Pure Java version (1676L/11K/39K).
1 | !752 |
2 | |
3 | !include #1004584 // GenOpt 3 |
4 | |
5 | static final int numbers = 2; // how many numbers to sort |
6 | |
7 | sclass Data { |
8 | int[] numbers; |
9 | Grid grid; |
10 | |
11 | *() {} |
12 | *(int[] *numbers) {} |
13 | } |
14 | |
15 | sclass MyGenOpt extends GenOpt<Data> { |
16 | void fillSandbox(Sandbox s, Data d) { |
17 | d.grid = new Grid(d.numbers); |
18 | final Grid g = d.grid; |
19 | |
20 | s.setOuter("get", new OneArgFunction() { |
21 | public LuaValue call(LuaValue arg) { |
22 | ret Lua.value(g.get(arg.toint())); |
23 | } |
24 | }); |
25 | |
26 | s.setOuter("swap", new TwoArgFunction() { |
27 | public LuaValue call(LuaValue a, LuaValue b) { |
28 | g.swap(a.toint(), b.toint()); |
29 | ret Lua.NIL; |
30 | } |
31 | }); |
32 | } |
33 | |
34 | double getScore(Sandbox s, Data data, LuaValue result) { |
35 | int[] sorted = sortedArray(data.numbers); |
36 | int errors = 0; |
37 | for (int i = 0; i < numbers; i++) |
38 | if (data.grid.get(i) != sorted[i]) |
39 | ++errors; |
40 | ret 100-errors; |
41 | } |
42 | |
43 | Data makeData() { |
44 | int[] data = new int[numbers]; |
45 | for (int i = 0; i < numbers; i++) |
46 | data[i] = random(100); |
47 | ret new Data(data); |
48 | } |
49 | |
50 | void updatePool(L<Make> pool) { |
51 | pool.clear(); |
52 | pool.add(new Bubblesort); |
53 | } |
54 | } |
55 | |
56 | p { |
57 | new MyGenOpt go; |
58 | go.steps = numbers*numbers*10; // execution steps limit |
59 | go.go(); |
60 | } |
61 | |
62 | |
63 | //// CONTESTANTS //// |
64 | |
65 | static O bubblesort_bot; |
66 | |
67 | sclass Bubblesort implements Make { |
68 | public S getLua() { |
69 | if (bubblesort_bot == null) |
70 | bubblesort_bot = hotwire(numbers == 2 ? "#1003167" : "#1003158"); |
71 | ret (S) call(bubblesort_bot, "makeLua"); |
72 | } |
73 | } |
Began life as a copy of #1003166
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004585 |
Snippet name: | Auto-generate Lua code to sort numbers [using 2 numbers, WORKS] |
Eternal ID of this version: | #1004585/1 |
Text MD5: | 4f4e9de8e539ed141fb9b60cb41fd6f7 |
Transpilation MD5: | e7c60ed1f39694e60442f9cbd8bd0a3f |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-23 15:11:05 |
Source code size: | 1572 bytes / 73 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 486 / 584 |
Referenced in: | [show references] |