Scripting challenges!

Started by ., Jun 10, 2015, 10:13 AM

Previous topic - Next topic

EK.IceFlake

#90
Your challenge is to make a function that accepts an array and returns a sorted array. You have to assume that every element in the array is an integer. You can't use the default array.sort method.
It will be given an antiscore using this formula: time * bytes where time is measured in milliseconds. It will be tested with this array: [960, 659, 528, 42, 562, 252, 453, 874, 682, 263, 172, 919, 388, 784, 205, 736] which I got off random.org, however, you are in no way to be optimizing your code for this particular list or sequence. It will be tested with 10000 iterations.
The one with the lowest antiscore wins.

EK.IceFlake

#91
Here's mine, 125 bytes.
Performance testing at the end.

[spoiler]function a(b){c<-[(1<<63)-1];b.map(function(d){foreach(e,f in c)if(f>=d){c.insert(e,d);break}});c.remove(c.len()-1);return c}[/spoiler]

Note that this only works on a 64-bit build of Squirrel. To deal with 32-bit builds, change 1<<63 to 1<<31.

EK.IceFlake

This post has been buried.
I have successfully unburied it.

(this, if you didn't realize, is just a bump)

Sebastian

Chill out, I'm not here for the challenges :D
I just made @EK.IceFlake 's post more visible, if anyone's ready to try.

function a( b )
{
          c <- [ ( 1 << 63 ) - 1 ];
          b.map( function( d )
          {
                    foreach( e, f in c )
                             if( f >= d )
                             {
                                        c.insert( e, d );
                              break
                              }
          } );
c.remove( c.len() - 1 );
return c
}