CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 137 users online: 9 members, 98 guests and 30 bots.
Members: ACagliano, lafferjm, Link, shkaboinka, tifreak8x, xologist.
Bots: VoilaBot (1), Spinn3r (2), MSN/Bing (1), Magpie Crawler (3), VoilaBot (3), Googlebot (18), MSN/Bing (2).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
ACagliano


Super-Expert


Joined: 08 Feb 2010
Posts: 925

Posted: 05 Nov 2011 03:19:29 pm    Post subject: Search a search string for like terms

As part of my Lewis Drawer program, I will obviously, at times, have equations like this: CH3CH2CH2CH3. What I need to do is this...from the input string, parse it for like terms and rewrite the formula with each term listed only one. For instance, in the above sample... C4H10. How would I do this?
_________________
-ACagliano

Current Projects

Legend of Zelda. "Ganon's Rage"
51%
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55769
Location: Earth, Sol, Milky Way

Posted: 06 Nov 2011 08:52:03 am    Post subject:

Well, it seems to me that all chemical formulae of the type you listed follow this (regex) pattern:

/([A-Z][a-z]?[0-9]*)+/

In layman's terms, repeated sequences of the following:
- One uppercase letter
- Zero or one lowercase letter
- Zero or more numbers

It seems to me that you can create a (number of possible elements)-item list, then sweep through the string from left to right, first finding letter sequences, then (if there's a number) adding that number to the corresponding list element, or if there's none, adding one. Does that make sense? Do you need a more precise TI-BASIC example?
_________________


Back to top
arriopolis


New Member


Joined: 29 Mar 2011
Posts: 92

Posted: 06 Nov 2011 02:25:19 pm    Post subject:

let's say it's in Str1, you could do something like this:

Code:
:""-->Str2
{0}->lEleme
0-->Z
:For(X,1,length(Str1))
::For(Y,1,length(Str2))
:::If inString(Str1,X,1)=inString(Str2,Y,1):Then
::::1-->Z
::::If inString(Str1,X+1,1)="1" or inString(Str1,X+1,2)="2" or inString(Str1,X+1,2)="3" or inString(Str1,X+1,2)="4" or inString(Str1,X+1,2)="5" or inString(Str1,X+1,2)="6" or inString(Str1,X+1,2)="7" or inString(Str1,X+1,2)="8" or inString(Str1,X+1,2)="9":Then
:::::expr(inString(Str1,X+1,1))-->A
:::::lEleme(Y)+expr(inString(Str1,X+1,1))-->lEleme(Y)
:::::X+1-->X
::::Else
:::::lEleme(Y)+1-->lEleme(Y)
::::End
:::End
::End
::If Z=0:Then
:::Str2+inString(Str1,X,1)-->Str2
:::If inString(Str1,X+1,1)="1" or inString(Str1,X+1,2)="2" or inString(Str1,X+1,2)="3" or inString(Str1,X+1,2)="4" or inString(Str1,X+1,2)="5" or inString(Str1,X+1,2)="6" or inString(Str1,X+1,2)="7" or inString(Str1,X+1,2)="8" or inString(Str1,X+1,2)="9":Then
::::lEleme(Y)+expr(inString(Str1,X+1,1))-->lEleme(Y)
::::X+1-->X
:::Else
::::lEleme(Y)+1-->lEleme(Y)
:::End
::End
::0-->Z
:End

Note: I didn't test it at all, so see it as something you can use as inspiration. I did this:
X = Current character checked (Str1).
Y = Current character from character database (Str2) checked.
:Go through all characters.
::Go through all characters in stringdatabase.
:::If the checked letter = letter in stringdatabase
::::Indicate we have found the letter (1-->Z)
::::If the next character is a number
:::::Add A to the number of elements in lEleme.
:::::Add 1 to X, to make sure it's not gonna check the number as an element.
::::If the next character is not a number
:::::Add 1 to the number of elements in lEleme.
::Begin again with loop.
::If Z=0
:::"Apperently the character wasn't found in the stringdatabase, so add it.
:::Add the element to the stringdatabase
:::If the next character is a number
::::Add it to the number of elements already defined.
::::Add 1 to X, to make sure it's not gonna check the number as an element.
:::If the next character is not a number
::::Add 1 to the number of elements already defined.
::Reset Z.
:Begin again with loop.
Do note that this only works for numbers smaller than 10, but I guess it's easy to extend that.Smile
Back to top
_player1537


Guru-in-Training


Joined: 25 Nov 2009
Posts: 2958

Posted: 06 Nov 2011 02:45:09 pm    Post subject:

Ouch. Do you use code like that for checking for numbers in your own code? :/ Actually, that wouldn't work. inString(Str1,X+1,1) would need to be sub(Str1,X+1,1). To check if that character is a number, you could do:
Code:
If inString("0123456789",sub(Str1,X+1,1


Edit: Also, a good rule of thumb is: if you are ever copying and pasting code, then you're doing something wrong. I can only assume that you copy-pasted that code and changed the `="0"' part to whatever number you were on.
_________________
http://tanner.myserverathome.com
Back to top
arriopolis


New Member


Joined: 29 Mar 2011
Posts: 92

Posted: 06 Nov 2011 02:49:57 pm    Post subject:

0x5, much easier indeed player. Fact is I'm only using Asm, in which I would ofcourse use de font equates. I just wasn't paying attention to any optimizations Smile
Back to top
_player1537


Guru-in-Training


Joined: 25 Nov 2009
Posts: 2958

Posted: 06 Nov 2011 02:52:12 pm    Post subject:

"de font equates"? What do you mean by that?
_________________
http://tanner.myserverathome.com
Back to top
arriopolis


New Member


Joined: 29 Mar 2011
Posts: 92

Posted: 06 Nov 2011 02:54:09 pm    Post subject:

oh, sorry, "de" is the dutch article, I mean "the".Razz The font equates are the values assigned to the letters. For example: a $30 is assigned to "0", $31 is assigned to "1", etc. I'd use them to check whether it is between $30 and $39.
Back to top
_player1537


Guru-in-Training


Joined: 25 Nov 2009
Posts: 2958

Posted: 06 Nov 2011 02:56:12 pm    Post subject:

Ah, I understand. I'm still surprised, even if you are getting used to ASM, that you would miss such a glaring optimization. Did you not think there was an easier way while you were writing it? (Out of curiosity)
_________________
http://tanner.myserverathome.com
Back to top
arriopolis


New Member


Joined: 29 Mar 2011
Posts: 92

Posted: 06 Nov 2011 02:57:48 pm    Post subject:

Ofcourse I did, I was just too lazy to think of which one. Srsly. Smile
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55769
Location: Earth, Sol, Milky Way

Posted: 15 Nov 2011 09:12:21 am    Post subject:

*bump* How's this going, ACagliano? Do you have any further questions or follow-ups? How did our answers do you for?
_________________


Back to top
ACagliano


Super-Expert


Joined: 08 Feb 2010
Posts: 925

Posted: 15 Nov 2011 09:16:30 am    Post subject:

Thank for the help, however, this project will not succeed because I am trying to accomplish an impossible task. (See topic Angle Calc Help). Both are related to the same project. I have decided to stop this and resume work on another project.
_________________
-ACagliano

Current Projects

Legend of Zelda. "Ganon's Rage"
51%
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 GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.030191 seconds.