[TI-BASIC] Let's see your optimizing skills...

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
patz2009
New Member
Posts: 17
Joined: Wed 04 Apr, 2007 10:42 pm

[TI-BASIC] Let's see your optimizing skills...

Post by patz2009 »

I call this "Mach 3", as it's the 3rd (and fastest) version I have made of this program. Perhaps you can do better? Rewrite the thing if you see fit.
For the description of this program, I have wrote:Mach 3 Grouper - Patrick Connor
Purpose: To generate a list of numbers ranging from 1 to the users input, in a random order.
Input: A - Upper bound of numbers generated.
Output: L5 - List containing the numbers in a random order

Requirements:
- Must be written in pure BASIC - no ASM allowed!
- Can only use up to 3 variables. (Real/Complex)
Note: I only used 2.
- Can only use up to 2 lists.

Speed is a greater priority over program size.

Example: If A=5, then the output in a list might be {4,1,5,3,2} or possibly {2,5,4,1,3}.
My code is as follows:

Code: Select all

seq(A,A,1,A->L6
{0->L5
For(A,1,A
randInt(1,dim(L6->B
L6(B->L5(A
L6(dim(L6->L6(B
dim(L6)-1->dim(L6
End
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

Send(9prgmASMCODE
You know your hexadecimal output routine is broken when it displays the character 'G'.
Goplat
New Member
Posts: 12
Joined: Mon 16 Jul, 2007 2:46 pm

Post by Goplat »

Code: Select all

seq(A,A,1,A->L5
rand(A->L6
SortA(L6,L5
User avatar
Super Speler
Regular Member
Posts: 113
Joined: Fri 09 Feb, 2007 2:20 am
Location: Alpha Centuri

Post by Super Speler »

Code: Select all

cumSum(binomcdf(A,0->L5
rand(A->L6
SortA(L6,L5
Faster and slightly smaller then Goplats.

NOTE: I didn't test this and may have made a small mistake.
patz2009
New Member
Posts: 17
Joined: Wed 04 Apr, 2007 10:42 pm

Post by patz2009 »

Goplat wrote:

Code: Select all

seq(A,A,1,A->L5
rand(A->L6
SortA(L6,L5
I really like this one, but once you get to higher numbers (ex. 700), you're bound to get a MEMORY error.
Super Speler wrote:

Code: Select all

cumSum(binomcdf(A,0->L5
rand(A->L6
SortA(L6,L5
Faster and slightly smaller then Goplats.

NOTE: I didn't test this and may have made a small mistake.
If you're going to use cumSum(binomcdf(, then you need to have this:

Code: Select all

cumSum(binomcdf(A-1,0->L5
And, I hate to burst your bubble, but once this code gets fixed, it's actually a byte bigger than Goplat's :P
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

Dwedit wrote:Send(9prgmASMCODE
:lol:
Image
User avatar
Super Speler
Regular Member
Posts: 113
Joined: Fri 09 Feb, 2007 2:20 am
Location: Alpha Centuri

Post by Super Speler »

patz2009, true (oops) but mine's still faster. Also, if this code was to actually be USED, you could just make sure that you subtract one through the normal input initially and mine would be one byte smaller (which isn't true here I suppose, since there is no intention of using the code).
User avatar
DJ_O
Calc King
Posts: 2323
Joined: Mon 20 Dec, 2004 6:47 pm
Location: Quebec (Canada)
Contact:

Post by DJ_O »

kv83 wrote:
Dwedit wrote:Send(9prgmASMCODE
:lol:
He should as well have posted the hex version of the BASIC code with asmprgm at beginning :P
ImageImageImageImage
Post Reply