Courtesey of s_gamer
Robot robot(a);
while (!robot.is_sorted()) {
if (robot.pos == 0)
robot.go('>');
else if (robot.pos == n-1)
robot.go('<');
else
robot.go("<>"[random(rng)]);
}
return robot.cmd;
map, string> operations = {
{{0,1,2}, "."},
{{0,2,1}, ">><<>."},
{{1,0,2}, "><>."},
{{1,2,0}, ">><<><><."},
{{2,0,1}, "><>><>."},
{{2,1,0}, ">><><<>."},
};
cout << "Case #" << testcase << ": "
<< operations[a] << '\n';
for (int i=0; i<n && !robot.is_sorted(); ++i) {
int to = robot.index(i);
robot.go(repeat(">", to - i));
robot.go(repeat("<><", (to - i)-1));
robot.go("<>");
}
$\Rightarrow 93~\text{points}$
Moving 2 elements by 1 with 3 operations feels optimal
But we waste time walking right, as we don’t carry anything!
We could put elements $n-2$ and $n-1$ directly at the right place.
// Step 1: locate the first occurrence of 8 or 9
int a = robot.index(r-2), b = robot.index(r-1);
robot.go(repeat(">", min(a, b) - robot.pos));
while (robot.pos < r-1)
if (robot.a[robot.pos+1] == r-1 ||
robot.a[robot.pos+1] == r-2)
robot.go("><>"); // Step 2: drag them both with fish
else
robot.go(">"); // Step 3: move the 9 onto the 8
// Step 4: move both at the right place
robot.go("<");
if (robot.a[r-1] == r-2)
robot.go("<>><");
robot.go("<");
Need to optimize a few special cases to get full score.
Courtesey of Erik Klein