Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

...Huge Division

Name: n3n7i 2011-08-18 3:00


//----------------------------------


void ThousandFold(int xa[]){
int i=0, Top = xa[RRay];
if(Top==RRay){ printf("\nTF MAX!!\n"); return;}
for(i=Top;i>=0;i--){
    xa[i+1] = xa[i];
    //print()
    }
xa[0]=0;
xa[RRay]++;
}
   

//---------------------------------------------------

void TSDivide(int xa[], int xb[], int xc[]){
int mCount[102],
     VSub[102], VCount[102], TCount[102], OVC[102], OVM[102];

int GetRays=0, ThouLoop=0;

Set(VSub, xa);
Set(VCount, xb);
One(mCount);
Zero(TCount);

while(isLarger(VSub, VCount)>0){   
   
    /*printf("VS");
    Printout(VSub);
    printf("VC");
    Printout(VCount);
    Pause();
    */

    while(isLarger(VSub, VCount)>=0){
        Set(OVC, VCount);
        Set(OVM, mCount);
        ThousandFold(VCount);
        ThousandFold(mCount);
       
        /*//ThouLoop = isLarger(VSub, VCount);
        printf("MC");
        Printout(mCount);
        printf("VC");
        Printout(VCount);
        Pause();
        //GetRays++;
        */
        }
    Set(VCount, OVC);
    Set(mCount, OVM);
   
    //GetRays--;
   
    while(isLarger(VSub, VCount)>=0){
        Set(OVC, VCount);
        Set(OVM, mCount);
        Add(VCount, VCount, VCount);
        Add(mCount, mCount, mCount);

        /*printf("MC");
        Printout(mCount);
        printf("VC");
        Printout(VCount);
        Pause();
        */

        }
   
    /*printf("VS");
    Printout(VSub);
    printf("Minus OVC");
    Printout(OVC);


    printf("TC");
    Printout(TCount);
    printf("Plus OVM");
    Printout(OVM);
    Pause();
    */   

    Sub(VSub, OVC, VSub);
    Add(OVM, TCount, TCount);

    Set(VCount, xb);
    One(mCount);

    /*printf("VS");
    Printout(VSub);
    printf("TC");
    Printout(TCount);
    Pause();

    */
    }


if(isLarger(VSub, VCount)==0){   
    Add(aOne, TCount, TCount);
    Sub(VSub, VCount, VSub);
    }

printf("\n\nDivide ");
Printout(TCount);
printf("Remainder ");
Printout(VSub);

Set(xc, TCount);
}

//---------------------------------------------------

Name: Anonymous 2011-08-18 3:13

>>1
The only moment you should ever use uppercase letters in C identifiers is for types. For everything else, use underscore_separated_lowercase_words. I'm begging you, please abide by this.

Name: Anonymous 2011-08-18 3:35

>>1
Get out.

Name: Anonymous 2011-08-18 3:38

1. What >>2 said
2. Indent your code consistently, faggot

Name: n3n7i 2011-08-18 4:22

>>3,4
Indentation doth not maketh the code

Name: Anonymous 2011-08-18 4:34

Again you, again this shit code, again get out.

Name: Anonymous 2011-08-18 4:55

lol @ PascalCase in C in 2011

Name: n3n7i 2011-08-18 5:31

...I learnt in pascal =)

...Droobs aside, ;)
Anyone wanna do a speedtest on that? It's pretty crude, Easily room to better it.... But i'm thinking it should be pretty darn fast already =)

...Bet knuth didn't show you that one =D

Name: Anonymous 2011-08-18 6:04

Your code is horrible

Name: Anonymous 2011-08-18 6:40

_______________________________________________________

This is the troll line. If you post after this line, you admit to being trolled. Do not post in this thread unless you want to look like a retard.

Thank you!
_______________________________________________________

Name: Anonymous 2011-08-18 6:42

Bump.

Name: Anonymous 2011-08-18 6:45

>>10
I told this guy is serious.

Name: Anonymous 2011-08-18 6:50

>>8
It shows.

Here, I rewrote it in Pascal for you, so you could actually understand it.

unit HugeInt;

interface{-----------------------------------------------------------}

const
  RRay =   102;  { wtf is 'RRay'?  use useful constants at least. }
  IASize = 102;

type
  IntArray = array[1..IASize] of integer;

procedure ThousandFold(xa : IntArray);
procedure TSDivide(xa : IntArray; xb : IntArray; xc : IntArray);

implementation{------------------------------------------------------}

Uses crt;

var aOne : IntArray;  { lol some global }

procedure Set_(dest : IntArray; src : IntArray); forward;
procedure One_(dest : IntArray); forward;
procedure Zero_(dest : IntArray); forward;
procedure Add_(a1 : IntArray; a2 : IntArray; a3 : IntArray); forward;
procedure Sub_(a1 : IntArray; a2 : IntArray; a3 : IntArray); forward;
function isLarger(a : IntArray; b : IntArray) : boolean; forward;
procedure Printout(ia : IntArray); forward;
procedure Pause_; forward;

procedure ThousandFold(xa : IntArray);
var
  i : integer;
  Top : integer;
begin
  Top := xa[RRay];
  if Top = high(xa) then
  begin
    writeln(#13#10'TF MAX!!');
    exit;
  end;
  for i := Top downto 1 do
    xa[i+1] := xa[i];
  xa[1] := 0;
  inc( xa[high(xa)] );
end;

procedure TSDivide(xa : IntArray; xb : IntArray; xc : IntArray);
const
  GetRays : integer = 0;
  ThouLoop : integer = 0;
var
  mCount : IntArray;
  VSub : IntArray;
  VCount : IntArray;
  TCount : IntArray;
  OVC : IntArray;
  OVM : IntArray;
begin
  Set_(VSub, xa);
  Set_(VCount, xb);
  One_(mCount);
  Zero_(TCount);
  while isLarger(VSub,VCount) do
  begin
    (*
    Printout(VSub);
    write('VC');
    Printout(VCount);
    Pause_;
    *)
    while isLarger(VSub,VCount) do   { lol, O(n^2) }
    begin
      Set_(OVC,VCount);
      Set_(OVM,mCount);
      ThousandFold(VCount);
      ThousandFold(mCount);
      (*
      write('MC');
      Printout(mCount);
      write('VC');
      Printout(VCount);
      Pause_;
      inc(GetRays);
      *)
    end;
    Set_(VCount, OVC);
    Set_(mCount, OVM);
    (*dec(GetRays);*)
    while isLarger(VSub,VCount) do
    begin
      Set_(OVC,VCount);
      Set_(OVM,mCount);
      Add_(VCount, VCount, VCount); { lol }
      Add_(mCount, mCount, mCount); { lol }
      (*
      write('MC');
      Printout(mCount);
      write('VC');
      Printout(VCount);
      Pause_;
      *)
    end;

    (*
    write('VS');
    Printout(VSub);
    write('Minus OVC');
    Printout(OVC);

    write('TC');
    Printout(TCount);
    write('Plus OVM');
    Printout(OVM);
    Pause_;
    *)

    Sub_(VSub, OVC, VSub);
    Add_(OVM, TCount, TCount);

    Set_(VCount,xb);
    One_(mCount);

    (*
    write('VS');
    Printout(VSub);
    write('TC');
    Printout(TCount);
    Pause_;

    *)
  end;

  if isLarger(VSub, VCount) then
  begin
    Add_(aOne, TCount, TCount);  { lol some global }
    Sub_(VSub, VCount, VSub);
  end;

  write(#13#10#13#10'Divide ');
  Printout(TCount);
  write('Remainder ');
  Printout(VSub);

  Set_(xc, TCount);
end;

function isLarger(a : IntArray; b : IntArray) : boolean;
var i : integer;
begin
  isLarger := true;
  for i := 1 to high(a) do
  begin
    if i > high(b) then
      exit;
    if a[i] > b[i] then
      exit;
  end;
  isLarger := false;
end;

procedure Printout(ia : IntArray);
var i : integer;
begin
  for i := 1 to high(ia) do
    write(ia[i], #8);
  writeln;
end;

procedure Pause_;
begin
  readkey;
end;

procedure Set_(dest : IntArray; src : IntArray);
var
  i : integer;
begin
  for i := 1 to high(dest) do
  begin
    if i > high(src) then
      exit;
    dest[i] := src[i];
  end;
end;

procedure One_(dest : IntArray);
var
  i : integer;
begin
  for i := 1 to high(dest) do
    dest[i] := 1;
end;

procedure Zero_(dest : IntArray);
var
  i : integer;
begin
  for i := 1 to high(dest) do
    dest[i] := 0;
end;

procedure Add_(a1 : IntArray; a2 : IntArray; a3 : IntArray);
begin
  { I can't even imagine what the hell this is supposed to do. }
end;

procedure Sub_(a1 : IntArray; a2 : IntArray; a3 : IntArray);
begin
  { Ditto }
end;

end.

Name: n3n7i 2011-08-18 7:19

Really, you shouldn't have... =)

Had to lol @ >> procedure Add... { I can't even imagine what the hell this is supposed to do. }


//----------------------------------------------   
   
void Add(int xa[], int xb[], int xc[]){
//xa = Input1 // xb = Input2 // xc = Output
int i, iCarry=0, raymax=0;
// i = counter// iCarry = Carry the ones // raymax = Largest Element

raymax = xa[RRay];
if(xb[RRay]>raymax) raymax = xb[RRay];
//Get largest array element

xc[RRay] = raymax;
//Output will be at least that many elements

for(i=0;i<=xc[RRay];i++){
// Step
    xc[i] = xa[i] + xb[i] + iCarry;
        //Add lowest pair + Previous carry value

    iCarry=0;
        //Reset Carry

    while(xc[i]>=CutOff){
        iCarry++;
        xc[i]-=CutOff;
        }
                //Keep element to base size / increment Carry per Number of times? Over
 
    if((i==xc[RRay])+(iCarry==1)==2){
         //Need to expand RRay ?

        if (xc[RRay]>RRay-1){
            printf("\n Add OverFlow!");
                        //Full
            } else {
            xc[RRay]++;
                        //Expand
            }
        }
    }
}
//----------------------------------

Name: Anonymous 2011-08-18 7:32

Awesome code. Great size. Looks concise. Efficient. Elegant. Keep us all posted on your continued progress with any new code factoring or compiler optimization. Show us what you got man. Wanna see how freakin' expressive, efficient, concise and elegant you can get. Thanks for the motivation.

Name: n3n7i 2011-08-18 7:33


if((i==xc[RRay])+(iCarry>=2)==2){
         //Need to expand RRay ?

        if (xc[RRay]>RRay-2){
            printf("\n Add OverFlow!");

...Few bugs here and there =D

Name: n3n7i 2011-08-18 7:36

Doh... if((i==xc[RRay])+(iCarry>=1)==2){

...(i==i) = 1 so (i==i) + (i==i) = 2

=)

Name: Anonymous 2011-08-18 7:56

>>2
I use camelCase for variables and words_separated_by_underscores for functions.
How mad are you?

Name: n3n7i 2011-08-18 8:02

Does anybody know what that's called [the Division Alg(above) in some variant?]
...Its Easily kicking the binary-Step's Butt...
(Probably even Faster than the multiply [/w JumpCount ?]) alg...

Should Work Good On a (2^n Base) * n (Element) array [Larger base's Welcome /vs/ Oversize element lengths ? Can be dealt with =) quite well too i suspect..]

Name: Anonymous 2011-08-18 8:28

>>18
I do the same, I find that it is a superior way of writing code.

Name: Anonymous 2011-08-18 8:37

>>18,20
I use two ``$'' characters to emulate namespaces in C.

Name: Anonymous 2011-08-18 9:21

Should Work Good On a (2^n Base)

I Think I Found The Reason Behind His Identifier Naming Scheme: He Thinks Everything Is A Title.

Name: n3n7i 2011-08-18 21:49

...Meanwhile, n3n7i has just stumbled across the holy grail of fast arithmatic =)

...My variables are noble, hence they have titles ;)

Name: Anonymous 2011-08-19 0:11

>>23
O RLY.  Let me guess: calculate the reciprocal of the divisor via Newton's method, then multiply by the dividend?

IIRC, Knuth has another method in TAOCP, but I believe it is roughly on-par in complexity with Newton-Raphson above.

Name: n3n7i 2011-08-19 1:07

>>24 That could work pretty well too, by the sounds of it.... But nope, not doing any recip, Just using a Turbo-Multiply on the divisor =)

Name: Anonymous 2011-08-19 2:55

>>25
Somehow, I am dubious without a formal proof.

Name: n3n7i 2011-08-19 4:47

>>1 with printfs' removed....


void FTSDivide(int xa[], int xb[], int xc[]){
int mCount[102],
     VSub[102], VCount[102], TCount[102], OVC[102], OVM[102];

Set(VSub, xa);
Set(VCount, xb);
One(mCount);
Zero(TCount);
while(isLarger(VSub, VCount)>0){   
    while(isLarger(VSub, VCount)>=0){
        Set(OVC, VCount);
        Set(OVM, mCount);
        ThousandFold(VCount);
        ThousandFold(mCount);
//--Basic-/+Advancement--//
//Thousand-Fold (Or More!) Increment //
// (See >>#1)
        }
    Set(VCount, OVC);
    Set(mCount, OVM);
    while(isLarger(VSub, VCount)>=0){
        Set(OVC, VCount);
        Set(OVM, mCount);
        Add(VCount, VCount, VCount);
        Add(mCount, mCount, mCount);
//--Back to Standard--//
//--Binary / Increments (//Two-Fold //)
        }
    Sub(VSub, OVC, VSub);
    Add(OVM, TCount, TCount);
//Does the Proper Add / Subtraction Here
//Then Resets step Counters
    Set(VCount, xb);
    One(mCount);
    }
if(isLarger(VSub, VCount)==0){   
    Add(aOne, TCount, TCount);
    Sub(VSub, VCount, VSub);
//Final Catch //
    }
printf("\n\nDivide ");
Printout(TCount);
printf("Remainder ");
Printout(VSub);
Set(xc, TCount);
//Show some Output//
}

Name: n3n7i 2011-08-19 7:16

...Really, the main problem is that it's just too simple
Surely this can't have not been built already...

...Not that that makes it any better or worse, just -quite likely- previously discovered....

..Bit like the -Lotus- Hash alg i posted, I have no doubt NASA already has something similar[and Better].... But it's just not public.... thereby useless to most people...

While i'm on that, Should give a big shout-out to Bob Gunn, the ex-NASA man who enlightened me on the topic of Factorials, in the context of Cryptography... =)
I built Lotus myself, but none-the-less it would not have happened without him... and many others =D

Name: Anonymous 2011-08-19 8:26

>>28
Forever alone.

Don't change these.
Name: Email:
Entire Thread Thread List