For the intermediate, what if the argument is "100a"? Should we return an empty string?
Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
{ MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }
When posting a bug, please post debug! Help us, help you!
I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.
SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.
It's all lies!
I dev'd it natively on Linux first and it gave me a lot of problems, one of which was that it didn't want to let me use Swap on the arrays (not to mention would compile when it shouldn't and generally lie to me.) Afraid I didn't think to switch it out when I switched to wine
Also, what kind of Wizardry is that? for st to hi - 1 with nextSize do? I swear, that's just crazy enough that it might work! Though the syntax is a little odd - why should one need to declare nextSize when, I'm assuming, the for loop doesn't affect it or does it create a loop-local variable or am I missing something else?
As an aside, I hate Wizzup? and co for making me optimise my code like mad. They're very naughty boys and I would smack their bottoms if I could reach!
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.
Please let me know about the problems you're experiencing!
Not sure what your question is, but these are all valid loops:
Simba Code:var
i: Integer;
begin
for i := 0 to 4 do
WriteLn('Hai: ', i);
i := 3;
for i to 4 do
WriteLn('Hey: ', i);
for i := 0 to 4 with 2 do
WriteLn('Hoi: ', i);
end;
This means that the following can be rewritten
toSimba Code:while (st < hi) do
begin
Merger(output, data, st, Min(st + size, len), Min(st + nextSize, len));
st := st + nextSize;
end;
Simba Code:for st to hi - 1 with nextSize do
Merger(output, data, st, Min(st + size, len), Min(st + nextSize, len));
Nice code, Methrend! Good job.
E:Who wouldn't?They're very naughty boys and I would smack their bottoms if I could reach!
But based off of Daniels examples, it can accept strings too
Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
{ MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }
When posting a bug, please post debug! Help us, help you!
I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.
SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.
He needs to update his examples then!
Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
{ MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }
When posting a bug, please post debug! Help us, help you!
I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.
SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.
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 |
I know, but your third example would technically error out at compile time
Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
{ MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }
When posting a bug, please post debug! Help us, help you!
I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.
SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.
Not long before the deadline! I still have no submissions for the Advanced or Beginner problems
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 |
Week #2:
Beginner:Fun With Factorials!Intermediate:
Write a program that programmatically finds the Highest Common Factor of the factorial X and the factorial of Y, otherwise return 0 (zero). Make sure X and Y are defined constants that are placed at the beginning of your script and are more suitably named given their purpose.There were no valid submissions for this entry. Quite disappointing
Example:
X = 5, Y = 6
HCF = 120
ReadInts:Advanced:
Write a program that clones the IntToStr function within Simba. In your solution, you may NOT use Simba’s *ToStr in any way (including Format or any other variant), shape or form, and you must check the validity of the argument given. You must also support integers that are both positive AND negative, and output accordingly.There were three entries for this. Dgby714's submission, however, was the fastest out of all three. [Nathan]'s I couldn't really accept because it didn't work for most of the values tested (48% success rate).
Example #1:
Input = 1000
Output = "1000"
Example #2:
Input = -500
Output = "-500"
Example #3:
Input = "abc"
Output = ""
Dgby714's code:
Simba Code:program new;
function IntToStr_FirstAttempt(I: Int32): string;
var
Neg: boolean = False;
begin
Result := '';
if (I = 0) then Exit('0');
if (I < 0) then
begin
Neg := True;
I := Abs(I);
end;
while (I > 0) do
begin
Result := Chr((I mod 10) + 48) + Result;
I := I div 10;
end;
if (Neg) then
Result := '-' + Result;
end;
begin
WriteLn('1000 = ', IntToStr_FirstAttempt(1000));
WriteLn('-500 = ', IntToStr_FirstAttempt(-500));
end.
Sex's code:
Simba Code:function IntToStr2(i : integer) : string;
const
pows : array of integer = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000];
var
n, x : integer;
begin
if i = 0 then begin result := '0'; exit; end;
if 0 > i then begin result := '-'; i := abs(i); end;
n := Ceil(Log10(i + 1));
for x := n downto 1 do
result := result + chr(Floor(i / pows[x - 1]) mod 10 + 48);
end;
[Nathan]'s code:
Simba Code:program Nathan;
Function IsInteger(ext:extended):Boolean;
begin
result:=false;
if(ext = floor(ext)) then
result:=true;
end;
Function IntToCharArray(ints:Array of Integer):Array of Char;
var len,i:integer;
begin
len:= Length(ints);
SetArrayLength(result, len);
for i:=1 to len-1 do
begin
if(ints[i] = 0) then
result[i]:= '0';
if(ints[i] = 1) then
result[i]:= '1';
if(ints[i] = 2) then
result[i]:= '2';
if(ints[i] = 3) then
result[i]:= '3';
if(ints[i] = 4) then
result[i]:= '4';
if(ints[i] = 5) then
result[i]:= '5';
if(ints[i] = 6) then
result[i]:= '6';
if(ints[i] = 7) then
result[i]:= '7';
if(ints[i] = 8) then
result[i]:= '8';
if(ints[i] = 9) then
result[i]:= '9';
end;
end;
Function NathanIntToStr(input:extended):String;
var temp,current:extended;
var i,len:integer;
var arr:Array of Integer;
var chars:Array of char;
var negative:boolean;
begin
negative:=false;
if(input < 0) then
begin
negative:=true;
input:=input*-1;
end;
if(input > 2147483647) then
begin
writeln('Number is not a valid int');
TerminateScript;
end;
if not(IsInteger(input)) then
begin
writeln('Number is not a valid int');
TerminateScript;
end;
len:= floor(log10(input)) + 1;
SetArrayLength(arr,len+1);
current:= input/Exp((len-1)*Ln(10));
for i := 1 to len do
begin
if(current-floor(current) > 0.9) then
begin
temp:= floor(current)+1;
end else
temp:= floor(current);
arr[i]:= floor(temp);
current:= (current-temp) * 10;
end;
chars:= IntToCharArray(arr);
if(negative) then
begin
result:='-';
end else
result:='';
for i:=1 to Length(chars)-1 do
result:=result+chars[i];
end;
begin
writeln(NathanIntToStr(900708004));
end.
PolyComWrite a program that takes a standard array of points of n-length, which constructs a 2-dimensional polygon shape (arr1 connects to arr2 , arr2 -> arr3 , … , arrn-1 -> arrn , arrn -> arr1)note-1. Create separate appropriately-named methods which:No submissions for this which was quite saddening Dgby714, however, allowed me to show to the public his unfinished submission (which only works for simple polygon's). Quite impressive
- returns TRUE if the argument point (of type TPoint) is inside the polygon,
- returns TRUE if the polygon is complex,
- returns the amount of closed regions of the polygon,
- returns the maximum angle in DEGREES (minimum precision of 3 floating point numbers) of ALL intersections IF the polygon is complex. You are to sort this array so that it is ordered in a top-down, left-right order.note-2
NOTE #1: You must connect the provided points to each other via straight lines, these will not be given.
NOTE #2: An intersection is defined if TWO lines intersect and continue past that point.
Example #1:
array = [(0, 0), (5,5), (5, 0)]
Result_PointInside(2, 1) = True
Result_IsComplex = False
Result_RegionCount = 1
Result_Angles = [ [] ]
Example #2:
array = [(0, 0), (5, 0), (0, 5), (5, 5)]
Result_PointInside(6, 1) = False
Result_IsComplex = True
Result_RegionCount = 2
Result_Angles = [ x.xxx ]
No points were awarded.
Dgby's unfinished submission:
Simba Code:program PolyCom;
type
TInt32Arr = array of Int32;
TDPoint = record
x, y: Double;
end;
TDPointArr = array of TDPoint;
TPolygon = record
_: TDPointArr;
end;
TPolygonArr = array of TPolygon;
TPolyCom = record
Regions: TPolygonArr;
end;
TLine = record
S, E: TDPoint;
end;
function DPoint(x, y: double): TDPoint;
begin
Result.x := x;
Result.y := y;
end;
function Line(const x1, y1, x2, y2: Double): TLine;
begin
Result.S := DPoint(x1, y1);
Result.E := DPoint(x2, y2);
end;
procedure TPolygon.Init(const Arr: TDPointArr);
var
I, H: Int32;
begin
H := High(Arr);
SetLength(_, H + 1);
for I := 0 to H do
_[I] := DPoint(Arr[I].x, Arr[I].y);
end;
function TPolygon.isInside(const Point: TDPoint): boolean;
var
H, I, J: Int32;
begin
Result := False;
H := High(_);
I := 0; J := H;
while (I < H) do
begin
if (((_[I].y > Point.y) <> (_[J].y > Point.y)) and
(Point.x < (_[J].x - _[I].x) * (Point.y - _[I].y) / (_[J].y - _[I].y) + _[I].x)) then
Result := (not (Result));
J := I;
Inc(I);
end;
end;
function doIntersect(const L1, L2: TLine; out O: TDPoint): boolean;
var
I1, I2: Double;
begin
I1 := (((L2.E.y - L2.S.y) * (L1.E.x - L1.S.x)) -
((L2.E.x - L2.S.x) * (L1.E.y - L1.S.y)));
I2 := (((L2.E.y - L2.S.y) * (L1.E.x - L1.S.x)) -
((L2.E.x - L2.S.x) * (L1.E.y - L1.S.y)));
if ((I1 = 0) and (I2 = 0)) then
begin
Result := False;
Exit;
end;
I1 := (((L2.E.x - L2.S.x) * (L1.S.y - L2.S.y)) -
((L2.E.y - L2.S.y) * (L1.S.x - L2.S.x))) / I1;
I2 := (((L1.E.x - L1.S.x) * (L1.S.y - L2.S.y)) -
((L1.E.y - L1.S.y) * (L1.S.x - L2.S.x))) / I2;
Result := ((I1 >= 0) and (I1 <= 1) and
(I2 >= 0) and (I2 <= 1));
if (Result) then
begin
O.x := L1.S.x + I1 * (L1.E.x - L1.S.x);
O.y := L1.S.y + I1 * (L1.E.y - L1.S.y);
end;
end;
procedure TPolyCom.Init(Arr: TDPointArr);
var
H, I: Int32;
begin
SetLength(Regions, 1);
H := High(Arr) + 1;
SetLength(Regions[0]._, H + 1);
for I := 0 to H - 1 do
Regions[0]._[I] := Arr[I];
Regions[0]._[H] := Arr[0];
//TODO...
end;
function TPolyCom.isInside(const Point: TDPoint): boolean;
var
I: Int32;
begin
Result := False;
for I := 0 to High(Regions) do
if (Result := Regions[I].isInside(Point)) then
Exit;
end;
function TPolyCom.isComplex(): boolean;
begin
Result := (Length(Regions) <> 1);
end;
function TPolyCom.RegionCount(): Int32;
begin
Result := Length(Regions);
end;
function TPolyCom.Angles(): TInt32Arr;
begin
end;
var
PolyCom: TPolyCom;
begin
with PolyCom do
begin
Init([DPoint(0, 0), DPoint(5, 5), DPoint(5, 0)]);
WriteLn('Inside: ', isInside(DPoint(2, 1)));
WriteLn('Complex: ', isComplex());
WriteLn('RegionCount: ', RegionCount());
WriteLn('Regions: ', Regions);
WriteLn('Angles: ', Angles());
WriteLn('-------------------------------------------');
Init([DPoint(0, 0), DPoint(5, 0), DPoint(0, 5), DPoint(5, 5)]);
WriteLn('Inside: ', isInside(DPoint(6, 1)));
WriteLn('Complex: ', isComplex());
WriteLn('RegionCount: ', RegionCount());
WriteLn('Regions: ', Regions);
WriteLn('Angles: ', Angles());
WriteLn('-------------------------------------------');
Init([DPoint(5, 0), DPoint(5, 5), DPoint(0, 5), DPoint(2.5, 10), DPoint(0, 0)]);
WriteLn('Inside: ', isInside(DPoint(0, 0)));
WriteLn('Complex: ', isComplex());
WriteLn('RegionCount: ', RegionCount());
WriteLn('Regions: ', Regions);
WriteLn('Angles: ', Angles());
end;
end.
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 |
Week #3 problems are 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 |
Just curious, what numbers didn't work, I didn't have anything I tried not work. What didn't I think of?
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"
A few comments:
Dgby714:
- Nice, clean and clear code!
- Methods on types for the advanced submission. Sweet!
Sex:
- You can use a static array for pows.
- You can pass an argument to exit: Exit('0').
[Nathan]:
- Use a case statement to group the if's.
- Why take an extended argument for an integer to string function?
- You can get the maximum int value using High(Integer), instead of hardcoding it.
I'll be honest, the advanced problem looked a bit too advanced for me to quickly whip up a script. Let's hope this week there will be more submissions!
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:const
a = [1..3];
b: array of Integer = [1..3];
c: array[1..3] of Integer = [1..3];
begin
WriteLn(SizeOf(a), ' - ', SizeOf(b), ' - ', SizeOf(c));
end;
In this case, variables a and c are static arrays and b is a dynamic array. The only difference is the way they are stored (as you can seen by their sizes).
You could use the static variant, because you know the size of your array.
Ah, yes. Didn't realize I hadn't set a size.
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"
My word the beginner problem looks difficult...
Simply a GOD beast...
My Tutorials
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"
Simply a GOD beast...
My Tutorials
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)