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).

1  
!752
2  
3  
!include #1003165 // GenOpt
4  
5  
static final int numbers = 2; // how many numbers to sort
6  
static bool useCheat = false;
7  
8  
p {
9  
  typeWriterConsole();
10  
  steps = numbers*numbers*10; // execution steps limit
11  
  go();
12  
}
13  
14  
static int getScore(Grid g, int[] data) {
15  
  int[] sorted = sortedArray(data);
16  
  int errors = 0;
17  
  for (int i = 0; i < numbers; i++)
18  
    //if (g.get(i) > g.get(i+1))
19  
    if (g.get(i) != sorted[i])
20  
      ++errors;
21  
  ret errors;
22  
}
23  
24  
// makeData
25  
26  
static int[] makeData() {
27  
  int[] data = new int[numbers];
28  
  for (int i = 0; i < numbers; i++)
29  
    data[i] = random(100);
30  
  ret data;
31  
}
32  
33  
//// CONTESTANTS ////
34  
35  
static O bubblesort_bot;
36  
37  
sclass Bubblesort implements Make {
38  
  public S getLua() {
39  
    if (bubblesort_bot == null)
40  
      bubblesort_bot = hotwire(numbers == 2 ? "#1003167" : "#1003158");
41  
    ret (S) call(bubblesort_bot, "makeLua");
42  
  }
43  
}
44  
45  
static class Cheat implements Make {
46  
  public S getLua() {
47  
    ret [[
48  
      for i = 0, 10-1 do
49  
        for j = i, 10-1 do
50  
          if get(j) < get(i) then
51  
            swap(i, j)
52  
          end
53  
        end
54  
      end
55  
    ]];
56  
  }
57  
}
58  
59  
// updatePool
60  
61  
static void updatePool() {
62  
  pool.clear();
63  
  pool.add(new Bubblesort);
64  
  if (useCheat)
65  
    pool.add(new Cheat);
66  
}

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: 714 / 772
Referenced in: [show references]