(hopefully I haven't made this thread before and then forgotten about it)
Anyways, I'm working on an equation balancer in TI-BASIC. Here's my code so far:

Code:
Ans->Str1
" ->Str2
[[0]]->[A]
{1->|LFMST
{0->|LCPOS
length(Str1->L
1->N
1->C
DelVar P
While L>0
   ~1+inString("0123456789",sub(Str1,L,1
   If Ans!=~1
   Then
      Ans->N
   Else
      sub(Str1,L,1
      If Ans=")
      Then
         N->|LFMST(1+dim(|LFMST
         1->N
      Else
         If Ans="(
         Then
            dim(|LFMST)-1->dim(|LFMST
         Else
            If Ans="+
            Then
               C+1->C
               dim([A])+{0,1->dim([A]
               L+1->|LCPOS(1+dim(|LCPOS
            Else
               If Ans="-" or Ans=">
               Then
                  If not(P
                  Then
                     C->P
                     C+1->C
                     dim([A])+{0,1->dim([A]
                     L+1->|LCPOS(1+dim(|LCPOS
                  End
               Else
                  If Ans!="
                  Then
                     If inString("abcdefghijklmnopqrstuvwxyz",Ans
                     Then
                        L-1->L
                        sub(Str1,L,2->Str3
                     Else
                        Ans+" ->Str3
                     End
                     inString(Str2,Str3)/2
                     If not(Ans
                     Then
                        Str2+Str3->Str2
                        dim([A])+{1,0->dim([A]
                        Ans(1)-1
                     End
                     [A](Ans,C)+Nprod(|LFMST->[A](Ans,C
                     1->N
                  End
               End
            End
         End
      End
   End
   L-1->L
End
Matr>list(rref([A]),C,|LCOEF
abs(|LCOEF->|LCOEF
1->|LCOEF(dim(|LCOEF
"TD: TO INT RATIO
1+length(Str1->|LCPOS(1
1->|LCPOS(1+dim(|LCPOS
"
For(P,1,dim(|LCPOS)-1
   sub(Str1,|LCPOS(P+1),|LCPOS(P)-|LCPOS(P+1))+Ans
   If 1!=|LCOEF(P
   toString(|LCOEF(P))+Ans
End
sub(Ans,1,length(Ans)-1


I'm currently stuck on getting the coefficients into lowest integer ratio. So, the program might produce a coefficient list, {2/3, 3, 1}, which I would need to convert to {2, 9, 3} somehow. I'm not really sure how to do this since there is no command to get the denominator of a fraction, and LCM/GCD only take pairs of integers as input.

Also, I haven't really optimized this yet. I'm waiting until I figure out that part to optimize stuff so that I, and other people, can actually read the code while I am still adding functionality.

also, yay, 400 posts!
Are you talking of a chemical equation balancer

EDIT:
If you want to remove the denominator of the fraction then convert it to a string and remove anything before the division sign


Code:

Sub(str1, inString(str1, “/“), length(str1)


Convert you’re fraction to a string using toString, then you can convert it back using expr

EDIT2:
This is the code.

Code:

Sub(ToString(4/3 >frac), inString(toString(4/3 > frac), “/“), length(toString(4/3>frac

If this isn’t what you want then I have no idea
If your list is in Ans, here is a nice piece of code (That I totally did not develop on the spot) to find the lcm of the list with non-integers (in a short amount of time).

Code:
Ans>F<>D:Ans->L1
seq(expr(sub(toString(Ans(X)),inString(toString(Ans(X)),"n/d")+1,length(toString(Ans(X)))-inString(toString(Ans(X)),"n/d"))),X,1,dim(Ans
L1max(gcd(Ans,prod(Ans

if Ans={2/3, 3, 1}, then this function will return {2, 9, 3}.

I will continue looking for a better solution (partially because I tried to do this a long time ago and failed), but for now this should work.

Hope this helps! Smile

Edit: Wait, this doesn't work… I'm going to keep trying Sad

Edit 2:
For lack of my ability to come up with an alternative, I used a loop… This is still really fast, and I am quite sure it works this time.

Code:
Ans>F<>D:Ans->L1
Disp Ans
seq(expr(sub(toString(Ans(X)),inString(toString(Ans(X)),"n/d")+1,length(toString(Ans(X)))-inString(toString(Ans(X)),"n/d"))),X,1,dim(Ans
Ans-not(Ans-L1)(L1-1->L2
1:For(X,1,dim(L2:lcm(Ans,L2(X:End
AnsL1
  
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
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement