Transpiled version (1490L) is out of date.
1 | !759 |
2 | |
3 | // how many numbers to sort |
4 | static final int numbers = 10; |
5 | static int steps = numbers*numbers*10; // execution steps limit |
6 | |
7 | !include #1003139 // Assembly Machine |
8 | |
9 | sinterface Make { |
10 | abstract int[] getProgram(int startAddress); |
11 | } |
12 | |
13 | static L<Make> pool; |
14 | static int round; |
15 | |
16 | p { |
17 | pool = new L; |
18 | new Best<Make> best; |
19 | while (licensed()) { |
20 | ping(); |
21 | ++round; |
22 | updatePool(); |
23 | |
24 | new HashMap<Make, Number> scores; |
25 | int[] data = makeData(); |
26 | int startAddress = l(data); |
27 | |
28 | for (Make maker : pool) { |
29 | ping(); |
30 | new Grid grid; |
31 | grid.set(0, data); |
32 | int[] program = maker.getProgram(startAddress); |
33 | grid.set(startAddress, program); |
34 | runProgram_maxSteps = steps; |
35 | runProgram(grid, startAddress); |
36 | int score = getScore(grid); |
37 | scores.put(maker, score); |
38 | best.put(maker, score); |
39 | } |
40 | Make winner = lowest(scores); |
41 | print(round + " Best score: " + scores.get(winner) + " - " + structure(winner) + ", all time: " + best.score); |
42 | } |
43 | } |
44 | |
45 | // collects LOWEST score |
46 | sclass Best<A> { |
47 | A best; |
48 | int score; |
49 | |
50 | void put(A a, int score) { |
51 | if (best == null || score < this.score) { |
52 | best = a; |
53 | this.score = score; |
54 | } |
55 | } |
56 | |
57 | A get() { ret best; } |
58 | } |
59 | |
60 | static int getScore(Grid g) { |
61 | int errors = 0; |
62 | for (int i = 0; i < numbers-1; i++) |
63 | if (g.get(i) > g.get(i+1)) |
64 | ++errors; |
65 | ret errors; |
66 | } |
67 | |
68 | // makeData |
69 | |
70 | static int[] makeData() { |
71 | int[] data = new int[numbers]; |
72 | for (int i = 0; i < numbers; i++) |
73 | data[i] = random(65536); |
74 | ret data; |
75 | } |
76 | |
77 | //// CONTESTANTS //// |
78 | |
79 | static O bubblesort_bot; |
80 | |
81 | sclass Bubblesort implements Make { |
82 | public int[] getProgram(int startAddress) { |
83 | if (bubblesort_bot == null) |
84 | bubblesort_bot = hotwire("#1003147"); |
85 | ret (int[]) call(bubblesort_bot, "getProgram", startAddress); |
86 | } |
87 | } |
88 | |
89 | // updatePool |
90 | |
91 | static void updatePool() { |
92 | pool.clear(); |
93 | pool.add(new Bubblesort); |
94 | } |
Began life as a copy of #1003133
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: | #1003138 |
Snippet name: | GenOpt 1 (Sorting) |
Eternal ID of this version: | #1003138/1 |
Text MD5: | 7970f21a1ca7ebc6a19d679b8a7363e5 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-05-15 17:58:09 |
Source code size: | 1996 bytes / 94 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 619 / 712 |
Referenced in: | [show references] |