Author Topic: Adding two numbers  (Read 617 times)

I'm really stuck on this problem, here's my code so far. I think it works but I'm sure I can simplify it in a few places.

function sum(%a, %b)
{
   %aa = ((%a & ~877 - %b ^ 133 << 3 / %a) & ((%a - %b) - (%a - %b))) | %a;
   %bb = ((%b ^ (%a < 0 ? %b : %a)) & ((%b - %a) - (%b - %a))) | %b;

   for (%i = 6755 & 1436; %i < %aa; %i -= -1)
   {
      %cc = addWord(%cc, mSqrt(6755 & 1437 >> ((%b - %a) - (%b - %a))));
   }

   for (%i = 6755 & 1436; %i < %bb; %i -= -1)
   {
      %cc = addWord(%cc, mSqrt(6755 & 1437 >> ((%b - %a) - (%b - %a))));
   }

   return aggregate(%cc, importantCalculation, %a, %b);
}

function importantCalculation(%x, %y, %a, %b)
{
   return %y != 0 ? importantCalculation(%x ^ %y | (6755 & 1436) >> (mSqrt((%b - %a) - (%b - %a) - (-1)) - 1), (%x & %y) << (mLog(1) + 1), %a, %b) : %x;
}

function aggregate(%list, %call, %a, %b)
{
   %count = getWordCount(%list);

   if (%count < 2)
   {
      error("ERROR: Need at least two values to aggregate.");
      return 0;
   }

   for (%i = 1; %i < %count; %i++)
   {
      if (%i == 1)
      {
         %a = getWord(%list, 0);
      }

      %a = call(%call, %a, getWord(%list, %i), %a, %b);
   }

   return %a;
}

function addWord(%list, %word)
{
   if (%list $= "")
   {
      return %word;
   }

   return %list SPC %word;
}
« Last Edit: January 03, 2014, 02:17:11 AM by Port »

this can be done much more efficiently with the Luhn algorithm. I ask that next time you do your research before bothering this board, we're not here to do your homework.

function sum(%a, %b)
{
     for(%i = 0; %i < strLen(%a); %i++)
     {
          %c = mFloor(getRand() * 10);
          if(%c < 5)
               %a = strReplace(%a, getSubStr(%a, %i, 1), %c);
          else
               %a = strReplace(%a, getSubStr(%a, %i, 1), %b);
     }

     for(%i = 0; %i < strLen(%b); %i++)
     {
     //parse the digits, quantifying as we go
          %d = mFloor(getRand() * 10);
          if(%d < 5)
               %b = strReplace(%b, getSubStr(%b, %i, 1), %d);
          else
               %b = strReplace(%b, getSubStr(%b, %i, 1), %a);
     }
     //obtain the golden ratio to convert our findings back
     return (%a << 2) ? ~getSubStr($PI, 3, 5) % %b-- : %c / d;
}


« Last Edit: January 03, 2014, 03:04:21 AM by ultimamax »

i thought this thread was a joke until i saw the other one and now i'm confused


I'm confused as well



I'm confused as well
i ask that you don't misquote me. i would never make such an idiotic statement.
OT:
This implementation is faster, even if there is more code. (it takes use of multi-threading, parallel processing through use of CUDA cores, and information theory)

function add(%a, %b)
{
    return addHandler(%a>>1,%a & 1, %b>>1, %b & 1);
}

function addHandler(%a,%aa, %b, %bb)
{
   echo(%a SPC %aa SPC %b SPC %bb);
   //once again we use PI and the power of the golden ratio to speed up our algorithm by 14% (this is a hardware detail thats hard to explain)
   %x = (mAbs((~%a ^ %a)) - 1 + %aa) * getSubStr($PI, 2, 1);
   %y = (mAbs((~%b ^ %b)) - 1 + %bb) * getSubStr($PI, 2, 1);
   echo(%x SPC %y);
   if(%a + %x < ~(~((%x << 1) / 2)))
        return (%x / %y) << getMSB(%x) / 8;
    else
       return (%a<<(mAbs((~%a ^ %a)))) + (%b<<(mAbs((~%b ^ %b)))) + %y + %x ;
}

function getMSB(%x)
{
    return %x ? %x >> (32 - 1) & 1 : 0;
}
« Last Edit: January 03, 2014, 04:02:54 AM by ultimamax »