How are the submissions coming along? I'm interested in seeing the advanced solutions ^^
How are the submissions coming along? I'm interested in seeing the advanced solutions ^^
You may contact me with any concerns you have.
Are you a victim of harassment? Please notify me or any other staff member.
| SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |
Only thing I can say to this is +1 Daniel
I will try to answer all Runescape related questions!
By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.
Hey guys,
Really sorry! This has to be postponed for about a day due to excessive schoolwork I have to complete. So, unfortunately, you all get an extra day to submit your things
You may contact me with any concerns you have.
Are you a victim of harassment? Please notify me or any other staff member.
| SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |
Pfft, he's taking forever like a little female dog.
Simba Code:program BigNumLibrary;
type
BigNumBase = LongWord;
const
HIGHBIT = High(BigNumBase) xor (High(BigNumBase) shr 1);
HIGHBITS = High(BigNumBase);
function IntToBinary(value: Integer): string;
function BoolToInt(value: Boolean): Integer;
begin
if (value) then
Result := 1
else
Result := 0;
end;
begin
if (value = 0) then
Result := ''
else
Result := IntToBinary(value shr 1) + IntToStr(BoolToInt(value and 1 = 1));
end;
type
PBigNumPart = ^BigNumPart;
BigNumPart = record
data: BigNumBase;
next: PBigNumPart;
end;
BigNum = record
root: PBigNumPart;
sign: Boolean; // false = neg; true = pos
end;
function BigNumNew(value: Integer): BigNum;
begin
New(Result.root);
Result.root^.next := nil;
Result.sign := value >= 0;
Result.root^.data := value;
end;
function BigNumCopyPart(part: BigNumPart): PBigNumPart;
begin
New(Result);
Result^.data := part.data;
Result^.next := nil;
end;
function BigNumCopy(value: BigNum): BigNum;
var
part, position: PBigNumPart;
begin
Result.root := nil;
Result.sign := value.sign;
if (value.root = nil) then Exit;
part := value.root;
Result.root := BigNumCopyPart(part^);
position := Result.root;
while (part^.next <> nil) do
begin
position^.next := BigNumCopyPart(part^);
position := position^.next;
part := part^.next;
end;
end;
procedure BigNumDispose(var value: BigNum);
var
partN, partC: PBigNumPart;
begin
partC := value.root;
while (partC <> nil) do
begin
partN := partC^.next;
Dispose(partC);
partC := partN;
end;
value.root := nil;
value.sign := True;
end;
function BigNumAdd(a, b: BigNum): BigNum; forward;
function BigNumInvert(value: BigNum): BigNum;
var
partN, partR: PBigNumPart;
bigTemp, bigOne: BigNum;
begin
bigTemp.sign := not value.sign;
partN := value.root;
if (partN = nil) then
partR := nil
else
partR := BigNumCopyPart(partN^);
bigTemp.root := partR;
while (partN <> nil) do
begin
partR^.data := partR^.data xor HIGHBITS;
partR^.next := BigNumCopyPart(partN^);
partR := partR^.next;
partN := partN^.next;
end;
partR^.data := partR^.data xor HIGHBITS;
Writeln(IntToBinary(value.root^.data));
Writeln(IntToBinary(partR^.data));
bigOne := BigNumNew(1);
Result := BigNumAdd(bigTemp, bigOne);
BigNumDispose(bigTemp);
BigNumDispose(bigOne);
end;
function BigNumGreaterThan(a, b: BigNum): Integer;
function BigNumPartGreaterThan(a, b: PBigNumPart): Integer;
var
ta, tb: BigNumBase;
begin
if (a = nil) xor (b = nil) then
begin
if (a = nil) then
Exit(-1)
else
Exit(1);
end;
if (a = nil) then
Exit(0);
Result := BigNumPartGreaterThan(a^.next, b^.next);
if (Result = 0) then
begin
ta := a^.data;
tb := b^.data;
repeat
if ((ta xor tb) and HIGHBIT) = HIGHBIT then
begin
if (ta and HIGHBIT) = HIGHBIT then
Exit(1)
else
Exit(-1);
end;
ta := ta shl 1;
tb := tb shl 1;
until((ta = 0) and (tb = 0));
Exit(0);
end;
end;
var
ta, tb: BigNum;
begin
if (a.sign) then
ta := BigNumCopy(a)
else
ta := BigNumInvert(a);
if (b.sign) then
tb := BigNumCopy(b)
else
tb := BigNumInvert(b);
Result := BigNumPartGreaterThan(ta.root, tb.root);
BigNumDispose(ta);
BigNumDispose(tb);
end;
function BigNumAdd(a, b: BigNum): BigNum;
function AddPart(a, b: BigNumPart; out c: Boolean): PBigNumPart;
begin
New(Result);
Result^.data := a.data + b.data;
c := Result^.data < a.data;
Result^.next := nil;
end;
var
carry, carryNext: Boolean;
partA, partB, partR, temp, partOne: PBigNumPart;
begin
partA := a.root;
partB := b.root;
New(partOne);
partOne^.data := 1;
if (partA = nil) then
Exit(BigNumCopy(b))
else if (partB = nil) then
Exit(BigNumCopy(a));
partR := AddPart(partA^, partB^, carryNext);
Result.root := partR;
partA := partA^.next;
partB := partB^.next;
while ((partA <> nil) and (partB <> nil)) do
begin
carry := carry or carryNext;
temp := AddPart(partA^, partB^, carry);
if (carry) then
temp := AddPart(partA^, partOne^, carry)
else
temp := BigNumCopyPart(partA^);
partR^.next := AddPart(temp^, partB^, carryNext);
Dispose(temp);
partR := partR^.next;
partA := partA^.next;
partB := partB^.next;
end;
if (partA = nil) then
partA := partB;
carryNext := carry or carryNext;
while (partA <> nil) do
begin
if (carryNext) then
partR^.next := AddPart(partA^, partOne^, carryNext)
else
partR^.next := BigNumCopyPart(partA^);
partR := partR^.next;
partA := partA^.next;
end;
if (a.sign = b.sign) then
Result.sign := a.sign
else
begin
if (BigNumGreaterThan(a, b) <> -1) then
Result.sign := a.sign
else
Result.sign := b.sign;
end;
if (carryNext and (a.sign = b.sign)) then
begin
partR^.next := partOne;
if (not Result.sign) then
begin
if ((partR^.data and HIGHBIT) <> HIGHBIT) then
partOne^.data := (partOne^.data xor HIGHBITS)
else
begin
Dispose(partOne);
partR^.next := nil;
end;
end;
end
else
Dispose(partOne);
end;
function BigNumToBinary(value: BigNum): string;
var
partC: PBigNumPart;
begin
partC := value.root;
Result := '';
while (partC <> nil) do
begin
Result := PadL(IntToBinary(partC^.data), 32, '0') + Result;
partC := partC^.next;
end;
end;
I can't even remember how well addition works, but I'm pretty sure it nearly works perfectly (I think negative + negative is the failing point that I was working on.) It's also so awesome that it's 32/64bit independent and you can alter its base type to Byte or stuff to make it more fine-grained in its memory usage (though, really, if you care about 3 bytes of memory, you suck.)
Anyone doing this using arrays of booleans should just admit how awesome I am as well, since this method uses integer addition to speed up its processing like a boss. It also has little overhead when expanding or contracting how many longwords it uses since it's linked list based rather than array based, so it's really just all round awesome for a BigNum intense program rather than a silly one that just wants to store some number that's slightly too big for an Int64.
Before I forget, I showed this to a female and she bedded me so quickly I barely had time to get my Promise bracelet off. Just saying, chicks dig epic code.
By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.
Sorry, school work has really picked up this week due to the upcoming holidays. And also when you try out a different OS setup
Might as well further postpone it to this Saturday again, so the timings don't all get screwed up.
You may contact me with any concerns you have.
Are you a victim of harassment? Please notify me or any other staff member.
| SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |
In too late >.>
Last edited by m34tcode; 03-30-2012 at 05:18 PM.
My scripts: LunarPlanker
---
My Utilities: Cross Platform, Open Source, SPS Path Generator
Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.
Wasnt sure if he meant the start of the next one, or the end of this one. My function works perfect lol
My scripts: LunarPlanker
---
My Utilities: Cross Platform, Open Source, SPS Path Generator
Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.
I'm just wondering what is happening with this...
Dan was complaining about real life or something.
By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.
Has school
My scripts: LunarPlanker
---
My Utilities: Cross Platform, Open Source, SPS Path Generator
Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.
Ugh, I can't figure out the syntax for loops in Lape, I had scripts 1 & 2 done otherwise :/
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl"A programmer is just a tool which converts caffeine into code"
Simba Code:for i := 0 to 10 do
writeln(i);
Will work just fine .
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl"A programmer is just a tool which converts caffeine into code"
There are currently 1 users browsing this thread. (0 members and 1 guests)