Scripting challenges!

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

Previous topic - Next topic

.

Quote from: EK.IceFlake on Apr 12, 2017, 05:12 PMNot too fast.
Your script depends on you adjusting for length.
In which case:
function PrintRowz(num)
{
    switch (num)
    {
        case 0: break;
        case 1: print("*"); break;
        case 2: print("*.\n**"); break;
        case 3: print("*..\n**.\n***"); break;
    }
}
And so on

Read my update: (I had to move it to paste-bin because the forum script is too retarded and collapses series of dots down to 3)
.

.

I just realized that this challenge had no winning factors. No performance, statement count, line count etc. Basically as long as you did what was asked everyone is a winner. So how are we going to decide who won here? I'm curious.

And what's the next challenge? Because these are fun.
.

vito

Quote from: happymint on Apr 12, 2017, 06:19 PMAnd what's the next challenge? Because these are fun.
fast json bridge server <-> client side, at least it will be useful

.

Quote from: vito on Apr 12, 2017, 06:43 PM
Quote from: happymint on Apr 12, 2017, 06:19 PMAnd what's the next challenge? Because these are fun.
fast json bridge server <-> client side, at least it will be useful

Huh? Can you be more specific? And you must post one too. We're not here to do your work. What you're looking for is probably serialization.
.

vito

serialization + splitting to packages its it above stream limit

.

Quote from: vito on Apr 12, 2017, 06:43 PM... at least it will be useful

Also, that isn't the goal of the topic. But to be fun and probably learn some new/different techniques for doing something.
.

DizzasTeR

#66
@happymint, A small favor to test this one and the results
const STARTMASK = "****************************************************************";
const DOTMASK = "................................................................";

function dgen( num ) {
    local counter = num;
    do {
        local sz = DOTMASK.slice( 0, counter ) + STARTMASK.slice( 0, num - counter );
        kprint( sz );
        counter--;
    } while( counter > 0 )
}

.

#67
My plugin x32:
[USR] Flake: 2.77
[USR] Doom: 3.11
[USR] SLC1: 3.122
[USR] SLC2: 0.348
[USR] Doom2: 0.370

My plugin x64:
[USR] Flake: 2.287
[USR] Doom: 2.77
[USR] SLC1: 2.664
[USR] SLC2: 0.284
[USR] Doom2: 0.290


After you updated your code while I was doing my first test.

My plugin x32
[USR] Flake: 2.728
[USR] Doom: 3.083
[USR] SLC1: 3.127
[USR] SLC2: 0.333
[USR] Doom2: 0.342

My plugin x64:
[USR] Flake: 2.271
[USR] Doom: 2.759
[USR] SLC1: 2.651
[USR] SLC2: 0.282
[USR] Doom2: 0.292
.

.

#68
Here is my third version with pre-computed tables of strings to reduce the heap memory allocations: https://pastebin.com/sSZJMnG6

My plugin x32:
[USR] SLC3: 0.146
My plugin x64:
[USR] SLC3: 0.123
I'm trying something else now to see if I can take it even further. Seems this is as far as you can take it on the official plugin.
.

DizzasTeR

I'm not surprised to be second now heh.

Anik

@S.L.C can you test the benchmark of it.

[spoiler]
function anik( num )
{
local dotstr = "", starstr = "";
for( local i = 0; i < num; ++i ) dotstr += ".";
for( local i = 0; i <= num; ++i ) print( dotstr.slice( 0, num - i ) + ( starstr += "*" ) );
}
[/spoiler]

Shadow



There's really no other way of getting a better time than using constant tables and loops as @S.L.C mentioned above. Recursion is not a solution either (even though it has logarithmic complexion, you still need other instructions to ensure the function return which might not be as easy to optimize as for-loops)
QuotePS:is trash is ur home language??

EK.IceFlake

Quote from: Shadow on Apr 13, 2017, 10:53 AMThere's really no other way of getting a better time than using constant tables and loops as @S.L.C mentioned above.
Are you sure?
https://www.solidfiles.com/v/q6YqYPvxMWzxB
[USR] Total iterations: 1000
[USR] Average for Flake: 15 us
[USR] Average for Doom: 81 us
[USR] Average for SLC: 32 us
(where:
Flake's method is given a special download link as it is 342 MB
Doom's method is:
function dum( maxStars ) {
 if( maxStars ) {
 for( local mainRun = 0; mainRun <= maxStars-1; mainRun++ ) {
 local string = "";
 for( local j = 1; j <= maxStars; j++ ) {
 if( maxStars - j > mainRun ) {
 string += ".";
 }
 else {
 string += "*";
 }
 }
 kprint( string );
 }
 }
}
and SLC's method is:
const G_PERIOD_CONST = "...";
const G_ASTERIX_CONST = "********************************************************************************************************************************";
function Generate(l) for (local p = 1; p <= l; ++p) kprint(G_PERIOD_CONST.slice(0, l-p) + G_ASTERIX_CONST.slice(0, p));
)

DizzasTeR

You used the old method of mine @EK.IceFlake but nevermind :D The main thing is that the task got accomplished though in more than expected ways haha, way to go.

Shadow

Quote from: EK.IceFlake on Apr 13, 2017, 12:58 PM...

On the same note, I could also make a C++ plugin which would destroy squirrel at the execution time. The simple fact that your solution consists of 150 cases inside a switch renders it useless.
QuotePS:is trash is ur home language??