It is currently August 4th, 2020, 5:30 am

## Lua Algebra Solver help?

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

### Re: Lua Algebra Solver help?

revolt4peace wrote:When I say:

Code: Select all

`` if Coefficients < '10' and Coefficients >= '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) < 10 and tonumber(Coefficients) >= 0 then`` revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

### Re: Lua Algebra Solver help?

Thanks!

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

### Re: Lua Algebra Solver help?

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

### Re: Lua Algebra Solver help?

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

### Re: Lua Algebra Solver help?

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] == '^' and Coefficients[Xlocations+2] == '2' and       Alocations < Elocations and Alocations < Elocations and Xlocations < Elocations then
Solveable = 1
end
if Alocations ~= '0' then
if j == 1 and o == 1 and p == 1 and Alocations > Xlocations and Alocations < Elocations and Xlocations < Elocations            then
Solveable = 2
end
else
if j == 1 and o == 0 and p == 1 and Xlocations < Elocations then
Solveable = 2
end
end
if Alocations ~= '0' then
if j == 1 and o == 1 and p == 1 and Alocations < Xlocations and Alocations < Elocations and Xlocations < Elocations            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 == 'x' then
Numbers = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients == 'x' then
Length = '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 = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == '=' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k)
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
a, b, c = tonumber(Numbers), tonumber(Numbers), (tonumber(Numbers) - tonumber(Numbers))
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 == 'x' then
Numbers = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == '=' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == '=' then
Length = '0'
end
i = i+1
k = i
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
Numbers = Numbers - Numbers
Numbers = Numbers / Numbers
SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers)
SKIN:Bang('!SetVariable', 'Res2', '')
else
if Solveable == 3 then
k=1
i=1
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Alocations
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == 'x' then
Numbers = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == 'x' or tonumber(Coefficients[i]) < 0 or tonumber(Coefficients[i]) >= 10
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '=' then
i = i+1
end
k = i
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
Numbers = Numbers - Numbers
Numbers = Numbers / Numbers
SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers)
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!)
Click Me! - My Algebra Solver for Rainmeter! balala
Rainmeter Sage
Posts: 11145
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Lua Algebra Solver help?

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. revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

### Re: Lua Algebra Solver help?

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

### Re: Lua Algebra Solver help?

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!
Click Me! - My Algebra Solver for Rainmeter! balala
Rainmeter Sage
Posts: 11145
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Lua Algebra Solver help?

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. revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

### Re: Lua Algebra Solver help?

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 == '-' then
if j == 2 and (o == 2 or o == 3 or o == 4) and p == 1 and Coefficients[Xlocations+1] == '^' and Coefficients[Xlocations+2] ==          '2' and Alocations < Elocations and Xlocations < Elocations then
Solveable = 1
end
else
if j == 2 and (o == 1 or o == 2 or o == 3) and p ==1 and Coefficients[Xlocations+1] == '^' and Coefficients[Xlocations+2] == '2'       and Alocations < Elocations and Xlocations < Elocations then
Solveable = 1
end
end
if Alocations ~= '0' then
if Coefficients ~= '-' and Coefficients ~= 'x' then
if Alocations ~= '0' then
if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations > Xlocations and Alocations < Elocations and Xlocations                < Elocations then
Solveable = 2
end
else
if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations < Elocations and Xlocations < Elocations then
Solveable = 2
end
end
else
if Alocations ~= '0' then
if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations > Xlocations and Alocations < Elocations and Xlocations                < Elocations then
Solveable = 2
end
else
if j == 1 and (o == 1 or o == 2) and p == 1 and Xlocations < Elocations then
Solveable = 2
end
end
end
else
if j == 1 and (o == 0 or o == 1) and p == 1 and Xlocations < Elocations then
Solveable = 2
end
end
if Alocations ~= '0' then
if j == 1 and (o == 1 or o == 2) and p == 1 and Alocations < Xlocations and Alocations < Elocations and Xlocations <          Elocations 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 == 'x' then
Numbers = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients == 'x' then
Length = '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 = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[i] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Elocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k)
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
a, b, c = tonumber(Numbers), tonumber(Numbers), (tonumber(Numbers) - tonumber(Numbers))
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 == '-' and Coefficients == 'x' then
Numbers = '-1'
i=i+1
else
if Coefficients == 'x' then
Numbers = '1'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
end
Length = i-k
if Coefficients == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Elocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == '=' then
Length = '0'
end
i = i+1
k = i
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
Numbers = Numbers - Numbers
Numbers = Numbers / Numbers
SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers)
SKIN:Bang('!SetVariable', 'Res2', '')
else
if Solveable == 3 then
k=1
i=1
if Coefficients == '-' then
if Coefficients == 'x' and Coefficients == '=' then
Numbers = '-1'
i = i+1
Length = i-k
if Coefficients == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Elocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == '=' then
Length = '0'
end
i = i+1
k = i
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
Numbers = Numbers - Numbers
Numbers = Numbers / Numbers
SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers)
SKIN:Bang('!SetVariable', 'Res2', '')
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
if i ~= Elocations then
i = i+1
end
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '=' then
i = i+1
end
k = i
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
Numbers = Numbers - Numbers
Numbers = Numbers / Numbers
SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers)
SKIN:Bang('!SetVariable', 'Res2', '')
end
else
if Alocations ~= '1' then
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Alocations
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
end
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
i = i+1
if Coefficients[i] == '+' then
i = i+1
end
k = i
if Coefficients[k] == 'x' then
Numbers = '1'
else
if Coefficients[k] == '=' then
Numbers = '0'
else
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until i == Xlocations
Numbers = string.sub(Numbers, 2, i-k+1)
end
end
Length = i-k
if Coefficients[k] == 'x' then
Length = '1'
end
i = i+1
if Coefficients[i] == '=' then
i = i+1
end
k = i
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until Coefficients[i] == nil
Numbers = string.sub(Numbers, 2, i-k+1)
Length = i-k
Numbers = Numbers - Numbers
Numbers = Numbers / Numbers
SKIN:Bang('!SetVariable', 'Res1', 'x='..Numbers)
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
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

DynamicVariables=1
Meter=String
X=5
Y=1R
H=19
W=210
FontFace=Seqoe UI
FontSize=11
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 '^'."

DynamicVariables=1
Meter=String
X=5
Y=1R
H=19
W=210
FontFace=Seqoe UI
FontSize=11
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 '^'.``````
"