Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: joao9856 on June 15, 2013, 04:48:39 pm

Title: from the lower to the higher
Post by: joao9856 on June 15, 2013, 04:48:39 pm
is there any way to organize random numbers from the lowest to the biggest??

TI-Nspire CX calc
Title: Re: from the lower to the higher
Post by: Hooloovoo on June 15, 2013, 05:02:22 pm
Code: [Select]
rand(100)->temp
SortA temp
should do what you want
Title: Re: from the lower to the higher
Post by: joao9856 on June 15, 2013, 05:16:33 pm
can't seem to make it work could you explain it to me like i was a four year old??
Title: Re: from the lower to the higher
Post by: Hooloovoo on June 15, 2013, 05:23:36 pm
Code: [Select]
rand(100)gives a bunch of random numbers. It could be rand(42) or anything else

Code: [Select]
SortA tempsorts temp. Now, temp is something like
Code: [Select]
{0.011,0.0125,0.0151.....0.988}
Title: Re: from the lower to the higher
Post by: joao9856 on June 15, 2013, 06:01:57 pm
i've searched and thats for lists, thinking is there any other way?
Title: Re: from the lower to the higher
Post by: Xeda112358 on June 16, 2013, 09:22:18 am
Well, is there any other way you had in mind? Using lists seems like the most straight-forward way. From this point, you can read list element 1, list element 2, list element 3, and so on.
Title: Re: from the lower to the higher
Post by: TIfanx1999 on June 16, 2013, 05:46:00 pm
^This. I'm not really sure what other way you would want to go about sorting numbers. From your post, I even assumed that you wanted a list.
Title: Re: from the lower to the higher
Post by: joao9856 on June 17, 2013, 07:50:15 am
the only problem is that i don't know how to place variables in a list.

I'm like this,

Code: [Select]
randint(1,50)->n
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn

after this i'm as clueless as what to do as i can get
Title: Re: from the lower to the higher
Post by: Matrefeytontias on June 17, 2013, 07:53:41 am
If it's the same than with z80 basic (TI-Basic for TI-82 to 84+), then you can access each element of a list this way :
Code: [Select]
temp(1)
temp(2)
temp(3)
...
Title: Re: from the lower to the higher
Post by: Xeda112358 on June 17, 2013, 07:54:22 am
I am not sure how it is done on the nSpire, but if it is similar enough to the 68K calcs, then you should be able to do something like this:
Code: [Select]
rand(50)→temp
SortA temp
And then to access a list element, you can do things like this:
Code: [Select]
temp[1]    ;retrieve list element 1
n→temp[1] ; store n to list element 1

I hope this works and helps!
Title: Re: from the lower to the higher
Post by: joao9856 on June 17, 2013, 08:00:53 am
it say "error invalid data type"
Title: Re: from the lower to the higher
Post by: Xeda112358 on June 17, 2013, 08:15:09 am
At what line does it have an error?
Title: Re: from the lower to the higher
Post by: joao9856 on June 17, 2013, 08:29:06 am
at SortA temp line
Title: Re: from the lower to the higher
Post by: Hooloovoo on June 17, 2013, 01:01:42 pm
what does
Code: [Select]
disp tempdisplay?
Title: Re: from the lower to the higher
Post by: TheNlightenedOne on June 17, 2013, 01:17:56 pm
It displays whatever is stored in temp
Title: Re: from the lower to the higher
Post by: Sorunome on June 17, 2013, 01:22:15 pm
it displays the contesnts of temp which is a array (i guess)
Title: Re: from the lower to the higher
Post by: Hooloovoo on June 17, 2013, 01:50:02 pm
it displays the contesnts of temp which is a array (i guess)
It displays whatever is stored in temp
I was asking joao9856 what that displayed for him, I don't think it was clear enough. I am thinking that temp is not an array for some reason.
Title: Re: from the lower to the higher
Post by: joao9856 on June 17, 2013, 01:57:39 pm
my code is

Code: [Select]
randint(1,11)->e
randint(1,11)->ee
randint(1,50)->temp
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
randint(1,50)->nnnnn
disp e
disp ee
disp temp
disp nn
disp nnn
disp nnnn
disp nnnnn
SortA temp
n->temp[1]
Title: Re: from the lower to the higher
Post by: Hooloovoo on June 17, 2013, 02:13:33 pm
Code: [Select]
randint(1,50) makes one random number from 1 to 50. SortA works on a list, which is several numbers in an order. lists are denoted by curly braces, {} and the elements, or members of the list, are separated by commas.
I think what you want is something like this:
Code: [Select]
randint(1,11)->e
randint(1,11)->ee
randint(1,50)->eee
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
randint(1,50)->nnnnn
{e,ee,temp,nn,nnn,nnnn,nnnnn}->temp ;put all of the varibles into a list
disp temp
SortA temp
disp temp
which could be optimized to
Code: [Select]
randint(1,50,7)->temp     ;get 7 random numbers from 1 to 50 and store to temp
disp temp   ;display the initial state of temp
SortA temp
disp temp   ;display the end, sorted state of temp.
Title: Re: from the lower to the higher
Post by: joao9856 on June 17, 2013, 02:15:23 pm
thanks now i can complete my program
Title: Re: from the lower to the higher
Post by: imath on June 30, 2013, 12:46:00 am
you can sort the list.
For example,
local a
randseed 100
a = rand(5)
sortA a
disp a
Title: Re: from the lower to the higher
Post by: imath on June 30, 2013, 12:47:17 am
my code is

Code: [Select]
randint(1,11)->e
randint(1,11)->ee
randint(1,50)->temp
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
randint(1,50)->nnnnn
disp e
disp ee
disp temp
disp nn
disp nnn
disp nnnn
disp nnnnn
SortA temp
n->temp[1]
no,no this use
It's not only rebundant but also complex and ugly.