num1=1
num2=1
num3=1
num4=0

mon=0

test=-30
test2=1

solver=0

solved = "working"

red = Color.new(255,0,0)
green=Color.new(0,255,0)
blue = Color.new(0,0,255)

var1 = 1
var2 = 1
select1 = red
select2=red
select3 = red
select = 1
oldpad=Controls.read()
while true do
screen:clear()
pad = Controls.read()
screen:print(100,100,"Current Problem:  " .. num1 .. "X^2 + " .. num2 .. " X + " .. num4, green)
screen:print(40,40,"change values then press cross to solve",blue)
screen:print(100,130,"first value:" .. num1,select1)
screen:print(100,150,"second value:" .. num2,select2)
screen:print(100,170,"third value:" .. num3,select3)
screen:print(100,200,"ANSWER:  (" .. num1 .. "X+" .. var1 .. ")(" .. num1 .. "X+" .. var2 .. ")",green)
screen:print(0,20,"please press L or R after clicking solve, or it wont work",blue)
screen:print(100,220,"Solved for 0: " .. solver/num1 .. "," .. mon/num1 .. "   test:" .. solver,green)

if pad:up() and oldpad:up() ~= pad:up() then
	select = select - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
	select = select + 1
end
if select > 3 then
	select = 1
end
if select < 1 then
	select = 3
end
if select == 1 then
	select1 = green
	else
	select1 = red
end
if select == 2 then
	select2 = green
	else
	select2 =red
end
if select == 3 then
	select3 = green
	else
	select3 =red
end

if pad:left() and oldpad:left() ~= pad:left() and select == 1 then
	num1=num1-1
end
if pad:right() and oldpad:right() ~= pad:right() and select == 1 then
	num1=num1+1
end

if pad:left() and oldpad:left() ~= pad:left() and select == 2 then
	num2=num2-1
end
if pad:right() and oldpad:right() ~= pad:right() and select == 2 then
	num2=num2+1
end

if pad:left() and oldpad:left() ~= pad:left() and select == 3 then
	num3=num3-1
end
if pad:right() and oldpad:right() ~= pad:right() and select == 3 then
	num3=num3+1
end
if pad:left() and pad:circle() and select == 1 then
	num1=num1-1
end
if pad:right() and pad:circle() and select == 1 then
	num1=num1+1
end

if pad:left() and pad:circle() and select == 2 then
	num2=num2-1
end
if pad:right() and pad:circle() and select == 2 then
	num2=num2+1
end

if pad:left() and pad:circle() and select == 3 then
	num3=num3-1
end
if pad:right() and pad:circle() and select == 3 then
	num3=num3+1
end


--[[
SOLVE
--]]
if pad:cross() then
	screen:print(30,240,"Solved=" .. solved .. "      Currently testing:" .. test,blue)
	test = test+1
	num4 = num3*num1
	test2 = num4/test
	if num2 == test+test2 then
		var1 = test
		var2 = test2
		var1 = var1
		var2 = var2
	end
end
if not pad:cross() then
test=-100
end
if num2 == var1+var2 then
	solved = "done."
	else
	solved = "working"
end

if test>200 and solved=="working" then
	solved="prime"
end
screen:print(0,260,"Progress....:" .. solved,green)
if pad:l() then
	test = -30
end
if pad:r() then
	test = -100
end
if solved == "done." then
	solver = var2*-1
	solver = solver
mon=var1*-1
mon=mon
end
if pad:start() then
	dofile("./System/poloptions.lua")
	break;
end
screen.waitVblankStart()
screen.flip()
oldpad=pad
end
