!752 !include #1004584 // GenOpt 3 p { S input = loadSnippet("#1004584"); L lines = toLines(input); int[] indents = new int[l(lines)]; for i over indents: indents[i] = getIndent(lines.get(i)); } sclass MyGenOpt extends GenOpt { void fillSandbox(Sandbox s, Data d) { d.grid = new Grid(d.numbers); final Grid g = d.grid; s.setOuter("lastLine", new ZerogArgFunction() { public LuaValue call(LuaValue arg) { ret Lua.value(g.get(arg.toint())); } }); s.setOuter("thisLine", new TwoArgFunction() { public LuaValue call(LuaValue a, LuaValue b) { g.swap(a.toint(), b.toint()); ret Lua.NIL; } }); } double getScore(Sandbox s, Data data) { int[] sorted = sortedArray(data.numbers); int errors = 0; for (int i = 0; i < numbers; i++) if (data.grid.get(i) != sorted[i]) ++errors; ret 100-errors; } Data makeData() { int[] data = new int[numbers]; for (int i = 0; i < numbers; i++) data[i] = random(100); ret new Data(data); } void updatePool(L pool) { pool.clear(); pool.add(new Bubblesort); } } p { new MyGenOpt go; go.steps = numbers*numbers*10; // execution steps limit go.go(); } //// CONTESTANTS //// static O bubblesort_bot; sclass Bubblesort implements Make { public S getLua() { if (bubblesort_bot == null) bubblesort_bot = hotwire(numbers == 2 ? "#1003167" : "#1003158"); ret (S) call(bubblesort_bot, "makeLua"); } }