Level: Harvest Time

Ah, you have led me to find a major bug that is probably making lots of CoffeeScript-compiled code not work!

x = _i += 10

The Aether transpiler apparently doesn’t handle this sort of operation properly, instead just doing the _i += 10 part. Interestingly, it does handle x = _i++ and x = ++_i. I’ve opened an issue here.

1 Like

You solution is so mathematically beautiful. especially this i%2. I used only one moveXY too, but used a lot more variables.

for( var dx = 0, y=this.ymin, x = this.xmin, b = false; x <= 53; dx=2, b = !b, y = b ? this.ymax : this.ymin, x += dx ){
this.moveXY(x+dx, y);
}

Maybe we can add another challenge : Find the solution with the shortest max time.
My solution, still with only one for loop and one moveXY takes less than 21s (20.6)
(too bad we can’t compare the number of statements, I’m still waiting the true debugger for all levels)

for (var counter = 0; counter < 10; counter ++){
    this.moveXY(this.xmin + (this.xmax - this.xmin)*(counter % 2),counter* 5.5 + this.ymin);
}

About the spoiler option, I was not able to find it in the txt option, so I copied it from the message above. Do I miss something ? If not, it should be directly available to help people to use it.

about the level itself, I think a problem at first is that the xmin and ymin do not match the position of the first mushroom. Same for the max, not the position of the last. So you can’t deduce from these vars the coordinates of all mushrooms, and make your character move from mushroom to mushroom.

Nice idea @Vettax,
I’ve tried, and I’ve got 19s (18.5)

for (var i=0; i<9; i++) {
this.moveXY(this.xmin+(i+0.5)this.xmax/9, this.ymax(i % 2)+this.ymin*((i+1)%2));
}

Spoiler option is also not present on my side.

This can get all of them in 12s :

for (var counter = 0; counter < 10; counter ++){
this.moveXY(this.xmin + 5 + (this.xmax - this.xmin-52)(((counter+1)-(counter+1)%2)/2 %2),
((counter-counter%2)/2)* 5*2 + this.ymin + 5/2);
}
Code is not very clean, I can’t find round or floor fonction to divide by 2 and remove fractionnal part. I replace it by something like (counter-coutner%2)/2 to get number like : 0,0,1,1,2,2,3,3…
I also replace (this.xmax-this.xmin/10) by the value 5 directly to simplify

Maybe the var NumberOfRow and NumberOfColumn are missing to get a code without predefined values.

OK, lets try something fancier (duration just slightly better).
I used your idea about getting this nice sequence with increasing segments of (k) repeating numbers (counter-coutner%k)/k @Vettax, to build more complicated structure in just one line of code, but it’s getting to be hard to read. Not-integer constants are there just to help the collector not to waste time.

for (var i=4; i<14; i++) {
this.moveXY((this.xmin-2) + ((i-i%2)/2)%2*(this.xmax+4.1) + (i-i%4)/4 * (((i-i%2)/2+1)%28.6+((i-i%2)/2)%2(-8.6)), (this.ymin-6.0) + (((i-1)-(i-1)%2)/2+1)%2*(this.ymax-this.ymin+3/26) + 5/3((i-1)-(i-1)%4)/4 * ((((i-1)-(i-1)%2)/2)%26+(((i-1)-(i-1)%2)/2+1)%2(-6.0)));
}

:slight_smile:

Well done

I still have one idea to test, if I found the time…

Edit : before that, I just clean my code and abandon the two line of code limit to make it more readable. I just add a light optimisation to make him turn sooner… 11.8 :

var row = (this.xmax - this.xmin)/10;
var column = (this.ymax - this.ymin)/10;
var optimisation = 1;
for (var counter = 0; counter < 10; counter ++){
// replace floor method to get 0,0,1,1,2,2,3,3…
var halfCounter = ((counter-counter%2)/2);
// replace floor method to get 0,1,1,2,2,3,3…
var halfCouterPlusOne = ((counter+1)-(counter+1)%2)/2;
// Use it to get 0,1,1,0,0,1,1,0,0…
var leftRight = halfCouterPlusOne%2;
this.moveXY(this.xmin + row + optimisation + (this.xmax - this.xmin - row * 2 - optimisation) * leftRight,
this.ymin + column/2 + halfCounter * column * 2);
}

Nice, that’s how I wrote it before making it compact. Maybe I’ll also clean it a little bit.

Something like this is probably not going to beat 14s, but making it in 2 lines of code should be challenging enough.

var xs = [0,0,1,2,0,0,3,4,0,1,4,4,2,3,4,4];
var ys = [0,1,0,0,2,3,0,0,4,4,1,2,4,4,3,4];
for (var i=0; i<16; i++) {
this.moveXY(6 + xs[i]*50/5, this.ymin+4 + ys[i]*50/5);
}

A last try, just for fun : 11.5.
But I have to increase the number of lines as Tech did:

var xs = [ 7, 5,16 ,21 ,25 ,31 ,36 ,41 ,44,44, 5, 5,11 , 16 ,20 ,25 ,31 ,36 ,41,44,44,5];
var ys = [27,32,31.7,29.5,31.7,29.5,31.7,29.5,29,45,45,57,54.5,56.7,54.5,57,54.5,56.7,54.5,54,69,69];
for (var i=0; i < xs.length; i++)
this.moveXY(xs[i], ys[i]);