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

71
LINES

< > BotCompany Repo | #1004586 // Lua Indent Guesser Experiment (dev.)

JavaX source code - run with: x30.jar

!752

!include #1004584 // GenOpt 3

p {
  S input = loadSnippet("#1004584");
  L<S> lines = toLines(input);
  int[] indents = new int[l(lines)];
  for i over indents:
    indents[i] = getIndent(lines.get(i));
}

sclass MyGenOpt extends GenOpt<Data> {
  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<Make> 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");
  }
}

Author comment

Began life as a copy of #1004585

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004586
Snippet name: Lua Indent Guesser Experiment (dev.)
Eternal ID of this version: #1004586/1
Text MD5: f7c71a5c03b208de4f43618751085444
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:26:09
Source code size: 1599 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 476 / 459
Referenced in: [show references]