It is currently February 19th, 2020, 2:47 pm

Lua Algebra Solver help?

Discuss the use of Lua in Script measures.
User avatar
balala
Rainmeter Sage
Posts: 9712
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Algebra Solver help?

Post by balala »

revolt4peace wrote:When I say:

Code: Select all

 if Coefficients[5] < '10' and Coefficients[5] >= '0' then
It does not read the '10' or '0' as numbers, so you would think I would simply change '10' to 10 and '0' to 0, and it would all work. But when I do remove the '' then the code stops working at all. Why is this, how do I fix it, and is there a better way to check if something is a number, rather than another character?
Because Coefficients are strings, you should use the tonumber function, to transform them into numbers:

Code: Select all

 if tonumber(Coefficients[5]) < 10 and tonumber(Coefficients[5]) >= 0 then
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua Algebra Solver help?

Post by revolt4peace »

Thanks!

Currently, I am working on deciding if the input is even solvable or not.
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
balala
Rainmeter Sage
Posts: 9712
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Algebra Solver help?

Post by balala »

Ok, later you could post your code here (or in the Share your creations thread), maybe it would be useful for us.
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua Algebra Solver help?

Post by revolt4peace »

Will do! :D
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua Algebra Solver help?

Post by revolt4peace »

So... I've been at work on this matter for a good ten hours now, and this is what I have.

Code: Select all

--Solveable = Help
--0 Y Expression
--1 Y x^2+x+1=0 or x^2+x=1
--2 Y x+1=0 or x=0
--3 Y 1+x=0
--4 N x^2+1=0
--5 N x^2=0
function Initialize()
   Equation = SKIN:GetVariable('Equation')
   if Equation == '0' then
      SKIN:Bang('!SetVariable', 'Res1', 'Error.')
      SKIN:Bang('!SetVariable', 'Res2', '')
   else
      SKIN:Bang('!SetVariable', 'Res1', 'I don\'t understand.')
      SKIN:Bang('!SetVariable', 'Res2', '')
   end
   Solveable = -1
   Coefficients = {}
   Numbers = {}
   Check = {}
   Length = {}
   k=1
   i=1
   j=0
   m=1
   n=0
   o=0
   p=0
   XNumbers = {}
   Xlocations = {} 
   Alocations = {}	
   Elocations = {}
   for i=1,#Equation do
      Coefficients[i] = '0'
   end
   for i=1,#Equation do
      Coefficients[i] = string.sub(Equation, i, i)
   end
   for i=1,#Equation do
      Numbers[i] = '0'
   end
   for i=1,#Equation do
       Numbers[i] = string.sub(Equation, i, i)
   end
   for i=1,#Equation do
       Xlocations[i] = '0'
   end
   for i=1,#Equation do
       Xlocations[i] = string.sub(Equation, i, i)
   end
   for i=1,#Equation do
       Alocations[i] = '0'
   end
   for i=1,#Equation do
       Elocations[i] = '0'
   end
   for i=1,#Equation do
       Elocations[i] = string.sub(Equation, i, i)
   end
   i = 0
   repeat
      repeat
         i = i+1
      until Coefficients[i] == 'x' or Coefficients[i] == nil
      if Coefficients[i] == 'x' then
         j = j+1
      end
      if Coefficients[i] ~= nil then
         Xlocations[j] = i
      end
      i = i+1
   until Coefficients[i] == nil
   i = 0
   repeat
      repeat
         i = i+1
      until Coefficients[i] == '+' or Coefficients[i] == '-' or Coefficients[i] == nil
      if Coefficients[i] == '+' or Coefficients[i] == '-' then
         o = o+1
      end
      if Coefficients[i] ~= nil then
         Alocations[o] = i
      end
      i = i+1
   until Coefficients[i] == nil
   i=0
   repeat
      repeat
         i = i+1
      until Coefficients[i] == '=' or Coefficients[i] == nil
      if Coefficients[i] == '=' then
         p = p+1
      end
      if Coefficients[i] ~= nil then
         Elocations[p] = i
      end
      i = i+1
   until Coefficients[i] == nil
   i=0
   repeat
      n=0
      i = i+1
      if j == 0 and p == 0 and((Coefficients[i-1] == '+' or Coefficients[i-1] == '-' or Coefficients[i-1] == '*' or Coefficients[i-1] ==           '/' or Coefficients[i-1] == '%' or Coefficients[i-1] == '(' or Coefficients[i-1] == ')' or Coefficients[i-1] == '^') or                      (Coefficients[i-1] == '0' or Coefficients[i-1] == '1' or Coefficients[i-1] == '2' or Coefficients[i-1] == '3' or Coefficients[i-1] ==        '4' or Coefficients[i-1] == '5' or Coefficients[i-1] == '6' or Coefficients[i-1] == '7' or Coefficients[i-1] == '8' or Coefficients          [i-1] ==  '9')) then
         Solveable = 0	
      else
         Solveable = -1
      end
   until Coefficients[i] == nil
   if j == 2 and (o == 2 or o ==3) and p ==1 and Coefficients[Xlocations[1]+1] == '^' and Coefficients[Xlocations[1]+2] == '2' and       Alocations[1] < Elocations[1] and Alocations[2] < Elocations[1] and Xlocations[1] < Elocations[1] then
      Solveable = 1 
   end  
   if Alocations[1] ~= '0' then
      if j == 1 and o == 1 and p == 1 and Alocations[1] > Xlocations[1] and Alocations[1] < Elocations[1] and Xlocations[1] < Elocations           [1] then
         Solveable = 2
      end
   else
      if j == 1 and o == 0 and p == 1 and Xlocations[1] < Elocations[1] then
         Solveable = 2
      end
   end
   if Alocations[1] ~= '0' then
      if j == 1 and o == 1 and p == 1 and Alocations[1] < Xlocations[1] and Alocations[1] < Elocations[1] and Xlocations[1] < Elocations           [1] then
         Solveable = 3
      end
   end
   if Solveable == 0 then
      if Equation == '0' then
         SKIN:Bang('!SetVariable', 'Res1', 'Enter an equation above.')
         SKIN:Bang('!SetVariable', 'Res2', '')
      else
         SKIN:Bang('!SetVariable', 'Res1', Equation)
         SKIN:Bang('!SetVariable', 'Res2', 'Reset before next input.')
      end
   else
      if Solveable == 1 then
         i=1
         if Coefficients[1] == 'x' then
            Numbers[1] = '1'
         else
            repeat
               Check[i] = Coefficients[i]
               Numbers[1] = Numbers[1]..Check[i]
               i = i+1
            until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
            Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
         end
         Length[1] = i-k
         if Coefficients[1] == 'x' then
            Length[1] = '1'
         end
         i = i+1	
         if Coefficients[i] == '^' then
            i = i+1
            if Coefficients[i] == '2' then
               i = i+1
               if Coefficients[i] == '+' then
                 i = i+1
               end
            end
         end
         k = i
         if Coefficients[k] == 'x' then
            Numbers[2] = '1'
         else
            repeat
               Check[i] = Coefficients[i]
               Numbers[2] = Numbers[2]..Check[i]
               i = i+1
            until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
            Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
         end
         Length[2] = i-k
         if Coefficients[k] == 'x' then
            Length[2] = '1'
         end
         i = i+1	
         if Coefficients[i] == '+' then
            i = i+1
         end
         k = i
         if Coefficients[k] == '=' then
            Numbers[3] = '0'	
         else
            repeat
               Check[i] = Coefficients[i]
               Numbers[3] = Numbers[3]..Check[i]
               i = i+1
            until Coefficients[i] == '=' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
            Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
         end
         Length[3] = i-k
         if Coefficients[k] == 'x' then
           Length[3] = '1'
         end
         i = i+1
         repeat
            Check[i] = Coefficients[i]
            Numbers[4] = Numbers[4]..Check[i]
            i = i+1
         until Coefficients[i] == nil
         Numbers[4] = string.sub(Numbers[4], 2, i-k)
         Length[4] = i-k
         if Coefficients[k] == 'x' then
            Length[4] = '1'
         end
         a, b, c = tonumber(Numbers[1]), tonumber(Numbers[2]), (tonumber(Numbers[3]) - tonumber(Numbers[4]))
         n = 0
         i = 0
         if Delta(a, b, c) > 0 then
            SKIN:Bang('!SetVariable', 'Res1', 'x1='..Result1(a, b, c))
            SKIN:Bang('!SetVariable', 'Res2', 'x2='..Result2(a, b, c))
         else
            if Delta(a, b, c) == 0 then
               SKIN:Bang('!SetVariable', 'Res1', 'x='..Result1(a, b, c))
               SKIN:Bang('!SetVariable', 'Res2', '')
            else
               SKIN:Bang('!SetVariable', 'Res1', 'There are no real values of x.')
               SKIN:Bang('!SetVariable', 'Res2', '')
            end
         end 
      else
         if Solveable == 2 then
            k=1
            i=1
            if Coefficients[1] == 'x' then
               Numbers[1] = '1'
            else
               repeat
                  Check[i] = Coefficients[i]
                  Numbers[1] = Numbers[1]..Check[i]
                  i = i+1
               until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
               Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
            end
            Length[1] = i-k
            if Coefficients[1] == 'x' then
               Length[1] = '1'
            end
            i = i+1	
            if Coefficients[i] == '+' then
              i = i+1
            end
            k = i
            if Coefficients[k] == '=' then
               Numbers[2] = '0'
            else
               repeat
                  Check[i] = Coefficients[i]
                  Numbers[2] = Numbers[2]..Check[i]
                  i = i+1
               until Coefficients[i] == '=' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
               Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
            end
            Length[2] = i-k
            if Coefficients[k] == '=' then
               Length[2] = '0'
            end
            i = i+1	
            k = i
            repeat
               Check[i] = Coefficients[i]
               Numbers[3] = Numbers[3]..Check[i]
               i = i+1
            until Coefficients[i] == nil	
            Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
            Length[3] = i-k
            Numbers[3] = Numbers[3] - Numbers[2]
            Numbers[3] = Numbers[3] / Numbers[1]
            SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers[3])
            SKIN:Bang('!SetVariable', 'Res2', '')
         else
            if Solveable == 3 then 
               k=1
               i=1
               repeat
                  Check[i] = Coefficients[i]
                  Numbers[1] = Numbers[1]..Check[i]
                  i = i+1
               until i == Alocations[1]
               Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
               Length[1] = i-k
               i = i+1	
               if Coefficients[i] == '+' then
                 i = i+1
               end
               k = i
               if Coefficients[k] == 'x' then
                  Numbers[2] = '1'
               else
                  repeat
                     Check[i] = Coefficients[i]
                     Numbers[2] = Numbers[2]..Check[i]
                     i = i+1
                  until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
                  Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
               end
               Length[2] = i-k
               if Coefficients[k] == 'x' then
                  Length[2] = '1'
               end
               i = i+1
               if Coefficients[i] == '=' then
                  i = i+1
               end	
               k = i
               repeat
                  Check[i] = Coefficients[i]
                  Numbers[3] = Numbers[3]..Check[i]
                  i = i+1
               until Coefficients[i] == nil	
               Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
               Length[3] = i-k
               Numbers[3] = Numbers[3] - Numbers[1]
               Numbers[3] = Numbers[3] / Numbers[2]
               SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers[3])
               SKIN:Bang('!SetVariable', 'Res2', '')
            else
            end
         end
      end 	
   end
end

function Delta(a, b, c)
   return (b*b - 4*a*c)
end

function Result1(a, b, c)
   if (((-b)-math.sqrt(Delta(a, b, c)))/(2*a)) == 0 then
      return 0
   else
      return -(((-b)-math.sqrt(Delta(a, b, c)))/(2*a))
   end
end

function Result2(a, b, c)
   if (((-b)+math.sqrt(Delta(a, b, c)))/(2*a)) == 0 then
      return 0
   else
      return -(((-b)+math.sqrt(Delta(a, b, c)))/(2*a))
   end
end

function Update()
end
It can solve some equations, in the forms listed at the top with a 'Y' next to them. The 'x's can have a coefficient (I don't know the limit of how high said coefficient can go, but I suppose it might be the integer limit?), the '1's can be any number, and the '0's can be any number. I do not have support yet for decimals, and it is limited to these EXACT forms. However, much like jsmorley's "QuickCalc", it can also solve pretty much any expression you would like to evaluate.

Just a little update on how this project is going. (Sorry if this should go in the "Share Creations" thread, I just wanted some continuity to this!)
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
balala
Rainmeter Sage
Posts: 9712
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Algebra Solver help?

Post by balala »

This script would be great, but it has a bug: eg for x1=3 and x2=-4 the equation is x^2+x-12=0, but the script returns x1=4 and x2=-3. Or for the x^2-3x+2=0 equation, it returns x1=-1 and x2=-2, but in fact it should x1=1 and x2=2.
Please take a look to fix that.
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua Algebra Solver help?

Post by revolt4peace »

Thanks for letting me know! I'll fix that.
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua Algebra Solver help?

Post by revolt4peace »

Remember when I said:
Just so you know, balala, there was one error with your code.

I changed

Code: Select all
SKIN:Bang('!SetVariable', 'Res1', 'x1='..(math.floor(Result1(a, b, c))+(math.floor(100*(Result1(a, b, c)-math.floor(Result1(a, b, c)))))/100))
SKIN:Bang('!SetVariable', 'Res2', 'x2='..(math.floor(Result2(a, b, c))+(math.floor(100*(Result2(a, b, c)-math.floor(Result2(a, b, c)))))/100))


to

Code: Select all
SKIN:Bang('!SetVariable', 'Res1', 'x1='..(-(math.floor(Result1(a, b, c))+(math.floor(100*(Result1(a, b, c)-math.floor(Result1(a, b, c)))))/100)))
SKIN:Bang('!SetVariable', 'Res2', 'x2='..(-(math.floor(Result2(a, b, c))+(math.floor(100*(Result2(a, b, c)-math.floor(Result2(a, b, c)))))/100)))


because the results were negative when they were supposed to be positive, and positive when they were meant to be negative.

Thanks again for the (quite large) step in the right direction!
Yeah, that's where that bug comes from, I was mistaken. Sorry about that!
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
balala
Rainmeter Sage
Posts: 9712
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Algebra Solver help?

Post by balala »

revolt4peace wrote:Yeah, that's where that bug comes from, I was mistaken. Sorry about that!
I think it'll be ok if you fix that.
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua Algebra Solver help?

Post by revolt4peace »

UPDATE: I have fixed all quadratics, I have added support for negatives and decimals, as well as finishing all forms listed with a 'Y' under 'Solved'. This is version 11, not released to deviantart yet, but version 09 is available for download. Updates will come rather quite frequently (but not on weekends most likely). Here is the code:

Algebra.lua (474 lines):

Code: Select all

--Solveable# Solved/Negatives/Decimals Type
--0 Y/Y/Y Expression
--1 Y/Y/Y x^2+x+1=0 or x^2+x=1
--2 Y/Y/Y x+1=0 or x=0
--3 Y/Y/Y 1+x=0 
--4 N/N/N x^2+1=0
--5 N/N/N x^2=0
function Initialize()
   Equation = SKIN:GetVariable('Equation')
   Solveable = 2
   Coefficients = {}
   Numbers = {}
   Check = {}
   Length = {}
   k=1
   i=1
   j=0
   m=1
   n=0
   o=0
   p=0
   XNumbers = {}
   Xlocations = {} 
   Alocations = {}	
   Elocations = {}
   for i=1,#Equation do
      Coefficients[i] = '0'
   end
   for i=1,#Equation do
      Coefficients[i] = string.sub(Equation, i, i)
   end
   for i=1,#Equation do
      Numbers[i] = '0'
   end
   for i=1,#Equation do
       Numbers[i] = string.sub(Equation, i, i)
   end
   for i=1,#Equation do
       Xlocations[i] = '0'
   end
   for i=1,#Equation do
       Xlocations[i] = string.sub(Equation, i, i)
   end
   for i=1,#Equation do
       Alocations[i] = '0'
   end
   for i=1,#Equation do
       Elocations[i] = '0'
   end
   for i=1,#Equation do
       Elocations[i] = string.sub(Equation, i, i)
   end
   i = 0
   repeat
      repeat
         i = i+1
      until Coefficients[i] == 'x' or Coefficients[i] == nil
      if Coefficients[i] == 'x' then
         j = j+1
      end
      if Coefficients[i] ~= nil then
         Xlocations[j] = i
      end
      i = i+1
   until Coefficients[i] == nil
   i = 0
   repeat
      repeat
         i = i+1
      until Coefficients[i] == '+' or Coefficients[i] == '-' or Coefficients[i] == nil
      if Coefficients[i] == '+' or Coefficients[i] == '-' then
         o = o+1
      end
      if Coefficients[i] ~= nil then
         Alocations[o] = i
      end
      i = i+1
   until Coefficients[i] == nil
   i=0
   repeat
      repeat
         i = i+1
      until Coefficients[i] == '=' or Coefficients[i] == nil
      if Coefficients[i] == '=' then
         p = p+1
      end
      if Coefficients[i] ~= nil then
         Elocations[p] = i
      end
      i = i+1
   until Coefficients[i] == nil
   i=0
   repeat
      n=0
      i = i+1
      if j == 0 and p == 0 and Solveable ~= -2 then
         Solveable = 0	
      else
         Solveable = -2
      end
   until Coefficients[i] == nil
   if Coefficients[1] == '-' then
      if j == 2 and (o == 2 or o == 3 or o == 4) and p == 1 and Coefficients[Xlocations[1]+1] == '^' and Coefficients[Xlocations[1]+2] ==          '2' and Alocations[2] < Elocations[1] and Xlocations[1] < Elocations[1] then
         Solveable = 1 
      end	
   else
      if j == 2 and (o == 1 or o == 2 or o == 3) and p ==1 and Coefficients[Xlocations[1]+1] == '^' and Coefficients[Xlocations[1]+2] == '2'       and Alocations[1] < Elocations[1] and Xlocations[1] < Elocations[1] then
         Solveable = 1	
      end  
   end 
   if Alocations[1] ~= '0' then
      if Coefficients[1] ~= '-' and Coefficients[2] ~= 'x' then
         if Alocations[2] ~= '0' then
            if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations[1] > Xlocations[1] and Alocations[1] < Elocations[1] and Xlocations               [1] < Elocations[1] then
               Solveable = 2
            end
         else
            if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations[1] < Elocations[1] and Xlocations[1] < Elocations[1] then
               Solveable = 2
            end
         end
      else
         if Alocations[2] ~= '0' then
            if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations[2] > Xlocations[1] and Alocations[2] < Elocations[1] and Xlocations               [1] < Elocations[1] then
               Solveable = 2
            end
         else
            if j == 1 and (o == 1 or o == 2) and p == 1 and Xlocations[1] < Elocations[1] then
               Solveable = 2
            end
         end
      end
   else
      if j == 1 and (o == 0 or o == 1) and p == 1 and Xlocations[1] < Elocations[1] then
         Solveable = 2
      end
   end
   if Alocations[1] ~= '0' then
      if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations[1] < Xlocations[1] and Alocations[1] < Elocations[1] and Xlocations[1] <          Elocations[1] then
         Solveable = 3
      end
   end
   if Equation == '0' then
      SKIN:Bang('!SetVariable', 'Res1', 'Enter an equation above.')
      SKIN:Bang('!SetVariable', 'Res2', '')
   else
      SKIN:Bang('!SetVariable', 'Res1', 'I don\'t understand. Send a')
      SKIN:Bang('!SetVariable', 'Res2', 'request to the developer.')
   end
   if Solveable == 0 then
      if Equation == '0' then
         SKIN:Bang('!SetVariable', 'Res1', 'Enter an equation above.')
         SKIN:Bang('!SetVariable', 'Res2', '')
      else
         SKIN:Bang('!SetVariable', 'Res1', Equation)
         SKIN:Bang('!SetVariable', 'Res2', 'Reset before next input.')
      end
   else
      if Solveable == 1 then
         i=1
         if Coefficients[1] == 'x' then
            Numbers[1] = '1'
         else
            repeat
               Check[i] = Coefficients[i]
               Numbers[1] = Numbers[1]..Check[i]
               i = i+1
            until i == Xlocations[1]
            Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
         end
         Length[1] = i-k
         if Coefficients[1] == 'x' then
            Length[1] = '1'
         end
         i = i+1	
         if Coefficients[i] == '^' then
            i = i+1
            if Coefficients[i] == '2' then
               i = i+1
               if Coefficients[i] == '+' then
                  i = i+1
               end
            end
         end
         k = i
         if Coefficients[k] == 'x' then
            Numbers[2] = '1'
         else
            repeat
               Check[i] = Coefficients[i]
               Numbers[2] = Numbers[2]..Check[i]
               i = i+1
            until i == Xlocations[2]
            Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
         end
         Length[2] = i-k
         if Coefficients[k] == 'x' then
            Length[2] = '1'
         end
         i = i+1	
         if Coefficients[i] == '+' then
            i = i+1
         end
         k = i 
         if Coefficients[i] == '=' then
            Numbers[3] = '0'	
         else
            repeat
               Check[i] = Coefficients[i]
               Numbers[3] = Numbers[3]..Check[i]
               i = i+1
            until i == Elocations[1]
            Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
         end
         Length[3] = i-k
         if Coefficients[k] == 'x' then
           Length[3] = '1'
         end
         i = i+1
         repeat
            Check[i] = Coefficients[i]
            Numbers[4] = Numbers[4]..Check[i]
            i = i+1
         until Coefficients[i] == nil
         Numbers[4] = string.sub(Numbers[4], 2, i-k)
         Length[4] = i-k
         if Coefficients[k] == 'x' then
            Length[4] = '1'
         end
         a, b, c = tonumber(Numbers[1]), tonumber(Numbers[2]), (tonumber(Numbers[3]) - tonumber(Numbers[4]))
         n = 0
         i = 0
         if Delta(a, b, c) > 0 then
            SKIN:Bang('!SetVariable', 'Res1', 'x1='..Result1(a, b, c))
            SKIN:Bang('!SetVariable', 'Res2', 'x2='..Result2(a, b, c))
         else
            if Delta(a, b, c) == 0 then
               SKIN:Bang('!SetVariable', 'Res1', 'x='..Result1(a, b, c))
               SKIN:Bang('!SetVariable', 'Res2', '')
            else
               SKIN:Bang('!SetVariable', 'Res1', 'There are no real values of x.')
               SKIN:Bang('!SetVariable', 'Res2', '')
            end
         end
      else
         if Solveable == 2 then
            k=1
            i=1
            if Coefficients[1] == '-' and Coefficients[2] == 'x' then
               Numbers[1] = '-1'
               i=i+1
            else
               if Coefficients[1] == 'x' then
                  Numbers[1] = '1'
               else
                  repeat
                     Check[i] = Coefficients[i]
                     Numbers[1] = Numbers[1]..Check[i]
                     i = i+1
                  until i == Xlocations[1]
                  Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
               end
            end
            Length[1] = i-k
            if Coefficients[1] == 'x' then
               Length[1] = '1'
            end
            i = i+1	
            if Coefficients[i] == '+' then
              i = i+1
            end
            k = i
            if Coefficients[k] == '=' then
               Numbers[2] = '0'
            else
               repeat
                  Check[i] = Coefficients[i]
                  Numbers[2] = Numbers[2]..Check[i]
                  i = i+1
               until i == Elocations[1]
               Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
            end
            Length[2] = i-k
            if Coefficients[k] == '=' then
               Length[2] = '0'
            end
            i = i+1	
            k = i
            repeat
               Check[i] = Coefficients[i]
               Numbers[3] = Numbers[3]..Check[i]
               i = i+1
            until Coefficients[i] == nil	
            Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
            Length[3] = i-k
            Numbers[3] = Numbers[3] - Numbers[2]
            Numbers[3] = Numbers[3] / Numbers[1]
            SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers[3])
            SKIN:Bang('!SetVariable', 'Res2', '')
         else
            if Solveable == 3 then 
               k=1
               i=1
               if Coefficients[1] == '-' then
                  if Coefficients[2] == 'x' and Coefficients[3] == '=' then
                     Numbers[1] = '-1'
                     i = i+1
                     Length[1] = i-k
                     if Coefficients[1] == 'x' then
                        Length[1] = '1'
                     end
                     i = i+1	
                     if Coefficients[i] == '+' then
                       i = i+1
                     end
                     k = i
                     if Coefficients[k] == '=' then
                        Numbers[2] = '0'
                     else
                        repeat
                           Check[i] = Coefficients[i]
                           Numbers[2] = Numbers[2]..Check[i]
                        i = i+1
                     until i == Elocations[1]
                     Numbers[2] = string.sub(Numbers[2], 2, i-k+1)   
                        end
                     Length[2] = i-k
                     if Coefficients[k] == '=' then
                        Length[2] = '0'
                     end
                     i = i+1	
                     k = i
                     repeat
                        Check[i] = Coefficients[i]
                        Numbers[3] = Numbers[3]..Check[i]
                        i = i+1
                     until Coefficients[i] == nil	
                     Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
                     Length[3] = i-k
                     Numbers[3] = Numbers[3] - Numbers[2]
                     Numbers[3] = Numbers[3] / Numbers[1]
                     SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers[3])
                     SKIN:Bang('!SetVariable', 'Res2', '')
                  else
                     repeat 
                        Check[i] = Coefficients[i]
                        Numbers[1] = Numbers[1]..Check[i]
                        i = i+1
                     until i == Xlocations[1]
                     Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
                     Length[1] = i-k
                     if i ~= Elocations[1] then
                        i = i+1
                     end	
                     if Coefficients[i] == '+' then
                       i = i+1
                     end
                     k = i
                     if Coefficients[k] == '=' then
                        Numbers[2] = '0'
                     else
                        repeat
                           Check[i] = Coefficients[i]
                           Numbers[2] = Numbers[2]..Check[i]
                           i = i+1
                        until i == Xlocations[1]
                        Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
                     end
                     Length[2] = i-k
                     if Coefficients[k] == 'x' then
                        Length[2] = '1'
                     end
                     i = i+1
                     if Coefficients[i] == '=' then
                        i = i+1
                     end	
                     k = i
                     repeat
                        Check[i] = Coefficients[i]
                        Numbers[3] = Numbers[3]..Check[i]
                        i = i+1
                     until Coefficients[i] == nil	
                     Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
                     Length[3] = i-k
                     Numbers[3] = Numbers[3] - Numbers[2]
                     Numbers[3] = Numbers[3] / Numbers[1]
                     SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers[3])
                     SKIN:Bang('!SetVariable', 'Res2', '')
                  end
               else
                  if Alocations[1] ~= '1' then
                     repeat
                        Check[i] = Coefficients[i]
                        Numbers[1] = Numbers[1]..Check[i]
                        i = i+1
                     until i == Alocations[1]
                  else
                     repeat 
                        Check[i] = Coefficients[i]
                        Numbers[1] = Numbers[1]..Check[i]
                        i = i+1
                     until i == Xlocations[1]
                  end
                  Numbers[1] = string.sub(Numbers[1], 2, i-k+1)
                  Length[1] = i-k
                  i = i+1
                  if Coefficients[i] == '+' then
                    i = i+1
                  end
                  k = i
                  if Coefficients[k] == 'x' then
                     Numbers[2] = '1'
                  else
                     if Coefficients[k] == '=' then
                        Numbers[2] = '0'
                     else
                        repeat
                           Check[i] = Coefficients[i]
                           Numbers[2] = Numbers[2]..Check[i]
                           i = i+1
                        until i == Xlocations[1]
                        Numbers[2] = string.sub(Numbers[2], 2, i-k+1)
                     end
                  end
                  Length[2] = i-k
                  if Coefficients[k] == 'x' then
                     Length[2] = '1'
                  end
                  i = i+1
                  if Coefficients[i] == '=' then
                     i = i+1
                  end	
                  k = i
                  repeat
                     Check[i] = Coefficients[i]
                     Numbers[3] = Numbers[3]..Check[i]
                     i = i+1
                  until Coefficients[i] == nil	
                  Numbers[3] = string.sub(Numbers[3], 2, i-k+1)
                  Length[3] = i-k
                  Numbers[3] = Numbers[3] - Numbers[1]
                  Numbers[3] = Numbers[3] / Numbers[2]
                  SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers[3])
                  SKIN:Bang('!SetVariable', 'Res2', '')
               end
            else
            end
         end
      end 	
   end
end

function Delta(a, b, c)
   return (b*b - 4*a*c)
end

function Result1(a, b, c)
   if (((-b)-math.sqrt(Delta(a, b, c)))/(2*a)) == 0 then
      return 0
   else
      return (((-b)-math.sqrt(Delta(a, b, c)))/(2*a))
   end
end

function Result2(a, b, c)
   if (((-b)+math.sqrt(Delta(a, b, c)))/(2*a)) == 0 then
      return 0
   else
      return (((-b)+math.sqrt(Delta(a, b, c)))/(2*a))
   end
end

function Update()
end
Algebra Solver 11.ini (118 lines):

Code: Select all

[Rainmeter]
DynamicWindowSize=1
IfConditionMode=1
Update=100
BackgroundMode=2
SolidColor=80,80,80,220
;Hidden=1
;Group=Left

[Variables]
Equation=0
FontColorQuestion=255,255,255,255
FontColorAnswer=211,255,207,255
FieldColor=100,255,100,255
Res1=-1
Res2=-1

[MeasureCalc]
DynamicVariables=1
Measure=calc
Formula=#Equation#

[MeasureCalc2]
DynamicVariables=1
Measure=calc
Formula=1
IfCondition=(#Res1#=#Equation#)
IfTrueAction=[!SetVariable Res1 [MeasureCalc]]

[MeasureInput]
DynamicVariables=1
Measure=Plugin
Plugin=InputText.dll
X=5
Y=5
H=16
W=210
FontColor=#FontColorQuestion#
SolidColor=#FieldColor#
FontFace=Seqoe UI
StringStyle=Bold
FontSize=10
FocusDismiss=1
DefaultValue=""
UpdateDivider=86400
Command1=[!SetVariable Equation "$UserInput$"][!CommandMeasure "MeasureLuaScript" "Initialize()"]

[MeasureLuaScript]
DynamicVariables=1
Measure=Script
ScriptFile=Algebra.lua

[MeterBack]
DynamicVariables=1
Meter=Image
SolidColor=0,0,0,255
W=220
H=69

[MeterInput]
DynamicVariables=1
Meter=String
X=5
Y=5
H=19
W=210
FontFace=Seqoe UI
FontSize=11
FontColor=#FontColorQuestion#
SolidColor=#FieldColor#
StringStyle=Bold
AntiAlias=1
DynamicVariables=1
Text=#Equation#
ToolTipType=1
ToolTipTitle="Algebra Solver"
ToolTipText="Click and Enter Formula#CRLF#Right Click to Reset"
ClipString=1
LeftMouseUpAction=!RainmeterPluginBang "MeasureInput ExecuteBatch 1"
RightMouseUpAction=!RainmeterRefresh

[MeterAnswer]
DynamicVariables=1
Meter=String
X=5
Y=1R
H=19
W=210
FontFace=Seqoe UI
FontSize=11
FontColor=#FontColorAnswer#
SolidColor=#FieldColor#
StringStyle=Bold
AntiAlias=1
DynamicVariables=1
Text=#Res1#
ToolTipType=1
ToolTipTitle="Algebra Solver"
ToolTipText="Use '**' for '^' when evaluating#CRLF#an expression, for an equation#CRLF#with 'x' use '^'."

[MeterAnswer2]
DynamicVariables=1
Meter=String
X=5
Y=1R
H=19
W=210
FontFace=Seqoe UI
FontSize=11
FontColor=#FontColorAnswer#
SolidColor=#FieldColor#
StringStyle=Bold
AntiAlias=1
DynamicVariables=1
Text=#Res2#
ToolTipType=1
ToolTipTitle="Algebra Solver"
ToolTipText="Use '**' for '^' when evaluating#CRLF#an expression, for an equation#CRLF#with 'x' use '^'.
"

Please feel free to use this program, downloadable here: http://explodingcreeperssss.deviantart.com/art/Algebra-Solver-09-514889290

If you would report any bugs, as well as request euqations/forms, it would be much appreciated!
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!