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

66
LINES

< > BotCompany Repo | #1003166 // Synthesize An Algorithm [simple version [sorting 2 numbers], WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 5262K of libraries. Click here for Pure Java version (1858L/12K/41K).

!752

!include #1003165 // GenOpt

static final int numbers = 2; // how many numbers to sort
static bool useCheat = false;

p {
  typeWriterConsole();
  steps = numbers*numbers*10; // execution steps limit
  go();
}

static int getScore(Grid g, int[] data) {
  int[] sorted = sortedArray(data);
  int errors = 0;
  for (int i = 0; i < numbers; i++)
    //if (g.get(i) > g.get(i+1))
    if (g.get(i) != sorted[i])
      ++errors;
  ret errors;
}

// makeData

static int[] makeData() {
  int[] data = new int[numbers];
  for (int i = 0; i < numbers; i++)
    data[i] = random(100);
  ret data;
}

//// 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");
  }
}

static class Cheat implements Make {
  public S getLua() {
    ret [[
      for i = 0, 10-1 do
        for j = i, 10-1 do
          if get(j) < get(i) then
            swap(i, j)
          end
        end
      end
    ]];
  }
}

// updatePool

static void updatePool() {
  pool.clear();
  pool.add(new Bubblesort);
  if (useCheat)
    pool.add(new Cheat);
}

Author comment

Began life as a copy of #1003159

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: #1003166
Snippet name: Synthesize An Algorithm [simple version [sorting 2 numbers], WORKS]
Eternal ID of this version: #1003166/1
Text MD5: 49c9269b82abe29132707302717605cc
Transpilation MD5: c2548f3a70f7876e2aabc4624802d340
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-12 19:32:14
Source code size: 1284 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 777 / 861
Referenced in: #1004585 - Auto-generate Lua code to sort numbers [using 2 numbers, WORKS]