This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic Brain Teasers => TI-BASIC
Author Message
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 10 Sep 2008 05:04:54 pm    Post subject:

After seeing some great routines I had an ideia from a little snippet of code and I started to make a new list to frequency list routine. What is it someone could ask...
Example:
{1,87,3,2,3,1,3,3,1} initial list

{1,2,3,87} value list
{3,1,3,1} absolute frequency list, this lists shows how many the correspondent number of the last list is repeated.
This is used in staticts...


The improve is on size.
My routine is already made, it took several hours of my life, during one afternoon. Although I know on internet a not bad routine for this but I always had a strange sensation of insatisfaction for a thought of a more beautiful routine.
Here is the link to see some action of a routine of this kind:
http://tibasicdev.wikidot.com/list-frequency
(Note: the last time I saw it had a little bug and could be slightly optimized, here's the correction:)
{L1(1->L2 //the elements
{1->L3 // their frequencies
For(I,2,dim(L1 //for each element of L1 after the first
If max(L2=L1(I // if L1(I) is already in L2
Then
L3+(L2=L1(I->L2 //increase the appropriate frequency
Else
augment(L2,{L1(I->L2 //add that element
augment(L3,{1->L3 //set its frequency to 1
End
End

(using Ans could gain some size after and as some experience can see it makes repeated steps, very time consumption. In the final I can give my conclusions of test of this routine against mine in speed terms Smile ) It is quite impressive.

My achievement is 61 bytes. I took this value in the computer from Properties ->TI Files Properties -> Size on Device... The initialization code counts too, naturally. And I can advance that is very elegant and fast. Works so well that has no problems with complex lists (I had an alternate and ugly ending list to freq routine that couldn't handle complex lists)

Oh in some strange case of withdraw from different algorithms (I doubt) there are side goals:
- less variables used
- result sorted
- speed
Who have achieved 2 of these side goal is considered better.


Good luck and have fun! hihihihi Quite a challenge I think.

PS: I searched this site and I didn't see a routine like mine. Only like the one I showed above.
PS2: (who guess my first one routine for this, some time ago, was completely mindless brute force of looping over and over)

EDIT: that list->freq routine is around 81 bytes...


Last edited by Guest on 14 Oct 2008 10:03:02 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 10 Sep 2008 11:11:35 pm    Post subject:

Galandros wrote:
I always had a strange sensation of insatisfaction for a thought of a more beautiful routine.
I love that mindset. :)

My first attempt ended up at 68 bytes, yet it only works with positive integers. In the output, the integer part is a value from the list, and the fractional part is the corresponding frequency:

    Ans→A
    SortA(LA
    LAaugment({1},0 xor [font="times new roman"]
    List(LA→B
    SortD(LB
    seq(LB(A)+.1sum(LA=LB(A)),A,1,dim(Ans)-sum(not(Ans


While this code is kind of ugly (or beautiful, depending on how you look at it), it may give you some perspective on how TI-Basic can be exploited differently.


Last edited by Guest on 30 Jul 2010 04:46:33 am; edited 1 time in total
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 11 Sep 2008 03:01:52 am    Post subject:

Weregoose wrote:
My first attempt ended up at 68 bytes, yet it only works with positive integers. In the output, the integer part is a value from the list, and the fractional part is the corresponding frequency:

About the output in a math program it has poor readability in a very large list. Presenting it to the graph isn't a problem.
My also process negative lists, but this is only a preciousness for us. ^^

Weregoose wrote:
While this code is kind of ugly (or beautiful, depending on how you look at it), it may give you some perspective on how TI-Basic can be exploited differently.
[post="126761"]<{POST_SNAPBACK}>[/post]

Quite good. And yes, it does give that perspective.
The routine is subtle because how the heck someone would remember to use the
List combined with xor for this one. (although I had a ideia with xor but it did not work) :S Also it only uses two lists because the seq( command don't modify his variable.

I did not include a first line for storing the input list.
Ans→L1
If that counts my routine is more 4 bytes (using L1) or more 3 if I change it to LA. so it stays at 64 bytes because this is of size. Your is very close in size to me.

I will test that against mine in speed to see if it gives more fight than the other. I do not have a prognostic, it is hard to understand where your is slow.


When is supposed to post the answer?
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 11 Sep 2008 03:59:34 am    Post subject:

The TI Files Properties are wrong :X

When I sent your routine to my calc gave 69 bytes for a program of 1 letter and mine 73 bytes for 1 letter too. But on computer the TI Files Property's says both programs are 61 bytes with a difference of a letter in name.

I tried to make a seq( in the beginning but the increment did not work well and made a expensive For(.
But I have a few ideias and will try to work around it ^^ EDIT: wait a minute you have made a way to work around it. -.- I should pay more attention to your code.

I will post a conclusion of speed tests between the 3 available routine as soon as my calculator has charged batteries. :biggrin:

My code: (highlite to see...)
[quote name='"BASIC Code"']:0→dim(L2
:DelVar L3SortA L1
:For(θ,1,dim(L1
:L1(θ→L2(1+dim(L2
:sum(L1=Ans→L3(dim(L2
:θ-1+Ans→θ
:End
[/quote]

Inputs: L1 with list
Ouput: L2 value list sorted
L3 freq list sorted
θ used
Ans obliterated




Speed tests:
A: DarkLiner prgm
B: Weregoose prgm
C: Galandros prgm
routines use lists L1,L2,L3

Tested in a real TI-OS 2.43, BOOT 1.02
batteries good and 21K free RAM after forced RAM Clear
test using clock timer
repeated 20 times and used same list to all prgm, result in seconds

Lists:
medium size, freq=1
{1,2,3,4,5,6,7,8,9,10,11,12
A: 11
B: 7
C: 14

large list, high freq, not random (I inputed putting many 1,2,3 and dim(L1)=49)
A: 34
B: 19
C: 9

large, random, low variance
randInt(1,10,50
A: 40
B: 23
C: 16

large, random, high variance
randInt(1,200,50
1st 2nd
A: 71 71
B: 58 64
C: 53 56

Unless I made a stupid mistake the results are liable.
Take your conclusions and use what you prefer :)

After try a few things and assimilate that frigging xor with deltaList, next one!


Last edited by Guest on 11 Sep 2008 06:59:25 am; edited 1 time in total
Back to top
alexrudd
pm me if you read this


Bandwidth Hog


Joined: 06 Oct 2004
Posts: 2335

Posted: 11 Sep 2008 01:48:34 pm    Post subject:

Galandros wrote:
Here is the link to see some action of a routine of this kind:
http://tibasicdev.wikidot.com/list-frequency
(Note: the last time I saw it had a little bug and could be slightly optimized, here's the correction:)  [post="126751"]<{POST_SNAPBACK}>[/post]


I'm glad you're using TI|BD for inspiration in your coding efforts. Just wanted to let you know that if you see further mistakes, you can easily join and fix it yourself. It would be cool if you added the results you found here to that page, too.
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 11 Sep 2008 03:09:58 pm    Post subject:

alexrudd wrote:
I'm glad you're using TI|BD for inspiration in your coding efforts.  Just wanted to let you know that if you see further mistakes, you can easily join and fix it yourself.  It would be cool if you added the results you found here to that page, too.
[post="126773"]<{POST_SNAPBACK}>[/post]

Sure. I was planning to register in TI Basic Developer nearly in the future and also Maxcoderz that is back again. And maybe ti8xfreakware site. But I move on at my own rate and based by my time on pc. School is beginning Neutral" here but some minutes in a day surfing on the net and program is relaxing time Razz

Oh I learned sooo much from that site and his archives, a real mine gold of programming BASIC! It was really helpful although when I discovered it I had figured out many of the techniques presented...

First I will make a attempt to fuse the routines (kind of). Also I could use that site to post my large file of TI calculators related sites or at least basic and calc related. (we can discuss that by PM or email if we need)
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 12 Sep 2008 06:58:46 am    Post subject:

I run out of ideas, they were at start desperate but I gave a frustrated try.
Someone could imagine of a very clever way to make the For( of my routine to a seq( giving the same output and the increment pass the repeated values like in my For( loop?

Is that the way seq( is does not allow something like:
SortA(L1
seq(sum(L1=L1(X)),X,1,dim(L1),sum(L1=L1(X

Because in the increment statement it gets the X real variable and not as the running X. And during seq( Ans is obviously not changed. It only gets changed at a new line of code.
The increment is very important to super speed up and avoid repeated values and frequency and a I do not see a work around and we are forced to use a slower, bigger For(. Almost nothing perfect... :hmpf:

But we reached a fast and small and a even smaller, and not slow at all. For math programs is more than enough.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement