TI-BASIC program - Need suggestions.
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
TI-BASIC program - Need suggestions.
I'm not sure if TI-BASIC questions are allowed on the forum, but here it goes.
I recently made a program to generate random numbers that would never repeat.
Here is the dreadfully slow (not mine) version.
Notes: > specifies a STORE function, not GREATER THAN
<> specifies the TI-BASIC Is Not Equal To
These are both using minimal eye-candy
LGROUP and LGRPB are lists.
I can't use code tags...
Input A
{0}>LGROUP
0>D
0>F
While dim(LGROUP) <> A
int(rand*A)+1>B
For(C,1,dim(LGROUP)
IF B=LGROUP(C)
1>D
END
IF D <> 1
THEN
F+1>F
B>LGROUP(F)
END
Output(8,1,dim(LGROUP))
0>D
END
Output(1,1,LGROUP)
And my new (faster) version.
Input A
{0}>LGROUP
seq(B,B,1,A)>LGRPB
For(C,1,A)
int(rand*dim(LGRPB)+1>D
LGRPB(D)>LGROUP(C)
0>LGRPB
SortD(LGRPB)
dim(LGRPB)-1>dim(LGRPB)
End
DelVar LGRPB
Output(1,1,LGROUP)
Anyone have any tips for it? Speed or memory leak tips? (I already have muchos eye-candy, but didn't want to post it.) (if you can't use TI-BASIC then these programs are pretty useless)
I recently made a program to generate random numbers that would never repeat.
Here is the dreadfully slow (not mine) version.
Notes: > specifies a STORE function, not GREATER THAN
<> specifies the TI-BASIC Is Not Equal To
These are both using minimal eye-candy
LGROUP and LGRPB are lists.
I can't use code tags...
Input A
{0}>LGROUP
0>D
0>F
While dim(LGROUP) <> A
int(rand*A)+1>B
For(C,1,dim(LGROUP)
IF B=LGROUP(C)
1>D
END
IF D <> 1
THEN
F+1>F
B>LGROUP(F)
END
Output(8,1,dim(LGROUP))
0>D
END
Output(1,1,LGROUP)
And my new (faster) version.
Input A
{0}>LGROUP
seq(B,B,1,A)>LGRPB
For(C,1,A)
int(rand*dim(LGRPB)+1>D
LGRPB(D)>LGROUP(C)
0>LGRPB
SortD(LGRPB)
dim(LGRPB)-1>dim(LGRPB)
End
DelVar LGRPB
Output(1,1,LGROUP)
Anyone have any tips for it? Speed or memory leak tips? (I already have muchos eye-candy, but didn't want to post it.) (if you can't use TI-BASIC then these programs are pretty useless)
This is really interesting. Could you explain a bit about what this code is supposed to do and how it does it? Also, why is your code better (faster?) than the other code. One question in particular, where does the value of B come from?
I do a little programming in TI-BASIC. I own a TI-83+ SE and my son owns a TI-84+ SE. We use TI-83+'s in the classroom and many of the students have their own calculator.
I do a little programming in TI-BASIC. I own a TI-83+ SE and my son owns a TI-84+ SE. We use TI-83+'s in the classroom and many of the students have their own calculator.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Re: TI-BASIC program - Need suggestions.
A quick overview:
Both codes generate random numbers in a random order and store them in LGROUP. However, none of the numbers ever repeat.
Differences:
First code: Generates a random number, checks if it exists in the list already. If it doesn't, it adds the number to the list.
Second code: I'll do a walkthrough.
Input A - Prompts for your maximum number
{0}>LGROUP - Clears whatever may already be in the list already
seq(B,B,1,A)>LGRPB -Generates a second list of numbers from 1 to A. (B is used as a counter.)
For(C,1,A) - The ever wonderful FOR loop!
int(rand*dim(LGRPB)+1>D -Generates a random location in the second list to use that number
LGRPB(D)>LGROUP(C) -Stores the number in position C (used in the FOR loop)
0>LGRPB -Replaces the value you just used with a 0
SortD(LGRPB) - Sorts the list in descending order. (0 is put in the last spot)
dim(LGRPB)-1>dim(LGRPB) -Remove the last number in the list. (Always going to be the 0)
End -End the FOR loop.
DelVar LGRPB -Delete the (blank) second list tom save RAM
Output(1,1,LGROUP) - Shows the list.
The reason my code is faster is because it is guarenteed to never generate the same number, so it doesn't have to check if the number exists.
Quick $$$:
To group 28: Old program-30 seconds. New program-3 seconds.
To group 400: Old program-Close to 4 hours. New program-23 minutes.
The syntax of seq() (where the B is used) is as follows:
Pattern: The pattern to follow. An equation usually goes in this spot
Counter: The variable that changes.
Start: Where to start counting.
End: Where to end counting.
So, seq(B,B,1,A) generates a list that increases in size by 1 for every entry, until it reaches the number you gave it (where Input A is).
Too long of an explanation If I'm unclear about something just tell me.
Both codes generate random numbers in a random order and store them in LGROUP. However, none of the numbers ever repeat.
Differences:
First code: Generates a random number, checks if it exists in the list already. If it doesn't, it adds the number to the list.
Second code: I'll do a walkthrough.
Input A - Prompts for your maximum number
{0}>LGROUP - Clears whatever may already be in the list already
seq(B,B,1,A)>LGRPB -Generates a second list of numbers from 1 to A. (B is used as a counter.)
For(C,1,A) - The ever wonderful FOR loop!
int(rand*dim(LGRPB)+1>D -Generates a random location in the second list to use that number
LGRPB(D)>LGROUP(C) -Stores the number in position C (used in the FOR loop)
0>LGRPB -Replaces the value you just used with a 0
SortD(LGRPB) - Sorts the list in descending order. (0 is put in the last spot)
dim(LGRPB)-1>dim(LGRPB) -Remove the last number in the list. (Always going to be the 0)
End -End the FOR loop.
DelVar LGRPB -Delete the (blank) second list tom save RAM
Output(1,1,LGROUP) - Shows the list.
The reason my code is faster is because it is guarenteed to never generate the same number, so it doesn't have to check if the number exists.
Quick $$$:
To group 28: Old program-30 seconds. New program-3 seconds.
To group 400: Old program-Close to 4 hours. New program-23 minutes.
The syntax of seq() (where the B is used) is as follows:
Code: Select all
seq(pattern,counter,start,end)
Counter: The variable that changes.
Start: Where to start counting.
End: Where to end counting.
So, seq(B,B,1,A) generates a list that increases in size by 1 for every entry, until it reaches the number you gave it (where Input A is).
Too long of an explanation If I'm unclear about something just tell me.
Ok... so this could be useful for modeling what they call "Sampling Without Replacement" such as in drawing numbers (or names) out of a hat where you don't want the same number (name) called twice.
Very useful! I'll have to give it a look.
Very useful! I'll have to give it a look.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
In fact, that analogy is very close. Here is an example using it.
FIRST CODE:
1. Draws a random number.
2. Asks 'Have I used this number before?'
3. If not, add it to the list.
4. Put the number back in the hat. (every time)
5. Repeat.
SECOND CODE:
1. Get 2 hats. (One with numbers, one empty)
2. Draw a random number out of the first hat.
3. Records that number.
4. Puts it into the second hat. (so it will not be drawn again.)
5. Repeat.
Hopefully that shows you how my code is more efficient.
PATZ
FIRST CODE:
1. Draws a random number.
2. Asks 'Have I used this number before?'
3. If not, add it to the list.
4. Put the number back in the hat. (every time)
5. Repeat.
SECOND CODE:
1. Get 2 hats. (One with numbers, one empty)
2. Draw a random number out of the first hat.
3. Records that number.
4. Puts it into the second hat. (so it will not be drawn again.)
5. Repeat.
Hopefully that shows you how my code is more efficient.
PATZ
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
You young whippersnappers and your speedy code! Why in my day, we used code that let us come back a couple of days later to see if it was done or not, and we liked it!
Now, GET OFF MY LAWN!!!
Now, GET OFF MY LAWN!!!
Daniel "Theophage" Clark
theophage (at) geocities (dot) com
"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
theophage (at) geocities (dot) com
"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Get into the 21st century. People don't keep track of who's on who's lawn... Oh, you mean the code...Theophage wrote:You young whippersnappers and your speedy code! Why in my day, we used code that let us come back a couple of days later to see if it was done or not, and we liked it!
Now, GET OFF MY LAWN!!!
Fear the Lawn!
It is the true and original source of the Almighty Grass Tile!
(besides, we're so off topic now, I'm sure we're on somebody's lawn...)
It is the true and original source of the Almighty Grass Tile!
(besides, we're so off topic now, I'm sure we're on somebody's lawn...)
Daniel "Theophage" Clark
theophage (at) geocities (dot) com
"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
theophage (at) geocities (dot) com
"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Re: TI-BASIC program - Need suggestions.
I feel like an idiot.
NEW SOURCE: (It's also got a smaler file size! I feel sooo accomplished!)
Input A
{0}>LGROUP
seq(B,B,1,A)>LGRPB
For(C,1,A)
int(rand*dim(LGRPB)+1>D
LGRPB(D)>LGROUP(C)
LGRPB(dim(LGRPB))>LGRPB(D)
dim(LGRPB)-1>dim(LGRPB)
End
DelVar LGRPB
Output(1,1,LGROUP)
Well, it's faster. Anyone care to take a guess at the logic?
Well, I first wanted to speed it up more. So, I thought "Hey, the SortD( is the slowest part, right? Since all I was using it for was getting rid of a single number, I could just move the last number in the list and replace the number that had just been used with it. Now, it doesn't have to go through a sloooowwww... sorting proccess.
Newest: 80 seconds (thats roughly 1500x faster than the old, and 135x faster than the 'new'An idiot once wrote:To group 800 the old program took 32 hours. See how mine's better?
New: 3 hours
Old: 32 hours
NEW SOURCE: (It's also got a smaler file size! I feel sooo accomplished!)
Input A
{0}>LGROUP
seq(B,B,1,A)>LGRPB
For(C,1,A)
int(rand*dim(LGRPB)+1>D
LGRPB(D)>LGROUP(C)
LGRPB(dim(LGRPB))>LGRPB(D)
dim(LGRPB)-1>dim(LGRPB)
End
DelVar LGRPB
Output(1,1,LGROUP)
Well, it's faster. Anyone care to take a guess at the logic?
Well, I first wanted to speed it up more. So, I thought "Hey, the SortD( is the slowest part, right? Since all I was using it for was getting rid of a single number, I could just move the last number in the list and replace the number that had just been used with it. Now, it doesn't have to go through a sloooowwww... sorting proccess.
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Aight, here we go, 84+ n00b...
http://detachedsolutions.com/omnicalc/
http://www.ticalc.org/archives/news/art ... 39572.html
(it's fairly new)
2 solutions: Since the 84SE comes with a ton of apps, erase the ones you'll never use. Download OMNICALC from Detached Soultions and activate the Fast App Menu option. It's LIGHTNING fast!Nathan1993 wrote:I also noticed that the scrolling on the APPS menu is MUCH slower than on the 83+/84+.
http://detachedsolutions.com/omnicalc/
Press ALPHA+N to go straight to the apps that start with N.Nathan1993 wrote:It kinda annoys me when scrolling to NoteFolio to write down my homework
Pffffftt... I can use a flash drive on an 84+.Nathan1993 wrote:but the 1 megabyte of flash memory is worth it.
http://www.ticalc.org/archives/news/art ... 39572.html
(it's fairly new)