Scripting challenges!

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

Previous topic - Next topic

EK.IceFlake

Quote from: Shadow on Apr 13, 2017, 03:41 PM
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.
1024, you mean?

Scripting challenges, not programming challenges.

Shadow

As long as squirrel is an embedded language and you have access to every value from C++, I'd say it's as fair as your solution. Anyways, keeping it real with generalised solutions:



..which isn't too bad
QuotePS:is trash is ur home language??

Anik

#77
Here's another challenge. Just like the previous challenge make a pyramid of "*"

Sample Output:
         *
         * *
        * * *
       * * * *
      * * * * *
     * * * * * *
    * * * * * * *
   * * * * * * * *
  * * * * * * * * *

Shadow

#78
It's getting quite repetitive but

function kprint(v) return; // > dev/null
// warm up to avoid CPU throttling.
for (local n = 0, x = 0; n < 10000000; ++n) x = abs(n - x) % 2 * 2 / 2;

const G_SPACE_CONST = "                                                                                                                                ";
const G_ASTERIX_CONST = "********************************************************************************************************************************";

local G_SPACE_POOL = array(G_SPACE_CONST.len());
local G_ASTERIX_POOL = array(G_SPACE_CONST.len());
for (local i = 0, n = G_SPACE_CONST.len(); i < n; ++i) {
    G_SPACE_POOL[i] = G_SPACE_CONST.slice(0, i);
    G_ASTERIX_POOL[i] = G_ASTERIX_CONST.slice(0, i);
}

function Generate(l) for (local p = 0.5; p <= (l/2); ++p) kprint(G_SPACE_POOL [(l/2) - p] + G_ASTERIX_POOL[p*2] + G_SPACE_POOL [p + (l/2)]);

local tm = clock();

for(local n = 0; n < 10000; ++n) Generate(32);

print("SLC: " + (clock() - tm));

.. just a simple adaptation

QuotePS:is trash is ur home language??

Anik

Quote from: Shadow on Apr 13, 2017, 04:40 PMIt's getting quite repetitive but

function kprint(v) return; // > dev/null
// warm up to avoid CPU throttling.
for (local n = 0, x = 0; n < 10000000; ++n) x = abs(n - x) % 2 * 2 / 2;

const G_SPACE_CONST = "                                                                                                                                ";
const G_ASTERIX_CONST = "********************************************************************************************************************************";

local G_SPACE_POOL = array(G_SPACE_CONST.len());
local G_ASTERIX_POOL = array(G_SPACE_CONST.len());
for (local i = 0, n = G_SPACE_CONST.len(); i < n; ++i) {
    G_SPACE_POOL[i] = G_SPACE_CONST.slice(0, i);
    G_ASTERIX_POOL[i] = G_ASTERIX_CONST.slice(0, i);
}

function Generate(l) for (local p = 0.5; p <= (l/2); ++p) kprint(G_SPACE_POOL [(l/2) - p] + G_ASTERIX_POOL[p*2] + G_SPACE_POOL [p + (l/2)]);

local tm = clock();

for(local n = 0; n < 10000; ++n) Generate(32);

print("SLC: " + (clock() - tm));

.. just a simple adaptation


Why put that much afford!!

function StarPyramid( rows )
{
local star=0, val1 = "", val2 = "";

    for( local i = 1;i <= rows; i++, star = 0, val1 = "", val2 = "")
{
        for(local space = 1; space <= rows-i; space++) val1 += " ";

while(star != i-1)
        {
            val2 += "* ";
            ++star;
        }
        print(val1 + val2);
    }
}
Can you test the benchmark of it?? @Shadow

Shadow

QuotePS:is trash is ur home language??

KAKAN

None of your code printed the desired output. Both of you fail haha!
oh no

Shadow

#82
Quote from: KAKAN on Apr 13, 2017, 05:07 PMNone of your code printed the desired output. Both of you fail haha!

          *
         * *
        * * *
       * * * *
      * * * * *
     * * * * * *
    * * * * * * *
   * * * * * * * *
  * * * * * * * * *

The only difference is the incremental stars. I'd say it does the job.
QuotePS:is trash is ur home language??

aXXo

print("          * ");
print("         * * ");
print("        * * * ");
print("       * * * * ");
print("      * * * * * ");
print("     * * * * * * ");
print("    * * * * * * * ");
print("   * * * * * * * * ");
print("  * * * * * * * * *");

Cool

Quote from: aXXo on Apr 13, 2017, 07:24 PMprint("          * ");
print("         * * ");
print("        * * * ");
print("       * * * * ");
print("      * * * * * ");
print("     * * * * * * ");
print("    * * * * * * * ");
print("   * * * * * * * * ");
print("  * * * * * * * * *");
LOL just LOL

Anik

Quote from: aXXo on Apr 13, 2017, 07:24 PMprint("          * ");
print("         * * ");
print("        * * * ");
print("       * * * * ");
print("      * * * * * ");
print("     * * * * * * ");
print("    * * * * * * * ");
print("   * * * * * * * * ");
print("  * * * * * * * * *");
LMAO.. Btw it works  :P :P

Anik

Quote from: KAKAN on Apr 13, 2017, 05:07 PMNone of your code printed the desired output. Both of you fail haha!
??? It works


KAKAN

Quote from: aXXo on Apr 13, 2017, 07:24 PMprint("          * ");
print("         * * ");
print("        * * * ");
print("       * * * * ");
print("      * * * * * ");
print("     * * * * * * ");
print("    * * * * * * * ");
print("   * * * * * * * * ");
print("  * * * * * * * * *");
Shadow, benchmark this and this:-
print(@"
          *
         * *
        * * *
       * * * *
      * * * * *
     * * * * * *
    * * * * * * *
   * * * * * * * *
  * * * * * * * * *");
oh no

EK.IceFlake

Quote from: Stormeus on Jun 10, 2015, 05:16 PMOne-line delegate abuse (two lines if counting the array).
[spoiler]
local arrayTest = ["test1","test2","test3","test4"];

// .apply replaces each value in an array with the returned value.
//
// This is a cheaty way of printing stuff without loops and we need to
// return the original value to avoid filling the array with nulls.
arrayTest.apply(function(v) { print(v); return v; });
[/spoiler]

One-line delegate abuse featuring lambdas:
[spoiler]
// Squirrel internally clones the array and uses the return value from map to
// fill the cloned array.
//
// If you were to look at the returned array from .map, you'd see a bunch
// of nulls, as we never return anything.
arrayTest.map(@(v) print(v));
[/spoiler]
Sorry for the bump but...
arrayTest.apply(print);???

Stormeus

Quote from: EK.IceFlake on May 23, 2017, 05:19 PM
Quote from: Stormeus on Jun 10, 2015, 05:16 PMOne-line delegate abuse (two lines if counting the array).
[spoiler]
local arrayTest = ["test1","test2","test3","test4"];

// .apply replaces each value in an array with the returned value.
//
// This is a cheaty way of printing stuff without loops and we need to
// return the original value to avoid filling the array with nulls.
arrayTest.apply(function(v) { print(v); return v; });
[/spoiler]

One-line delegate abuse featuring lambdas:
[spoiler]
// Squirrel internally clones the array and uses the return value from map to
// fill the cloned array.
//
// If you were to look at the returned array from .map, you'd see a bunch
// of nulls, as we never return anything.
arrayTest.map(@(v) print(v));
[/spoiler]
Sorry for the bump but...
arrayTest.apply(print);???

Quoteand we need to return the original value to avoid filling the array with nulls.

That one-liner may work with map.