Hey everyone, I have just discovered a chemical equation balancer on the CPlua. As the lua for 9860 have been released, shall we think about porting it to 9860? I can't open the .mcs file cause the CP MCS editor program doesn't work on my PC. May be someone give me the source code please?
![Photo](/uploads/av-22050.jpg?_r=0)
Porting A Lua Program From Cp To 9860
Started by
JackZhan
, May 24 2012 01:20 PM
5 replies to this topic
#1
Posted 24 May 2012 - 01:20 PM
#2
Posted 24 May 2012 - 02:18 PM
Here is the source code written by vanhoa extracted from the mcs file.
But make sure to fully read the disscussions in that thread.
But what was wrong with the CP MCS Editor? I saw no problems. :huh: Please tell me in its topic: http://www.casiocalc...?showtopic=6771
But make sure to fully read the disscussions in that thread.
But what was wrong with the CP MCS Editor? I saw no problems. :huh: Please tell me in its topic: http://www.casiocalc...?showtopic=6771
require("string","cas","table") function ucln(a,B) if(b%a==0) then return a else return ucln(b%a,a) end end function del1(a) if(a==1) then return "" else return a end end function duavedangcoban(s) i=1 s=string.gsub(s,"%(%-%)","%(%-1%)") s=string.gsub(s,"%((%-)([0-9]+)%)","Aientich%2") s=string.gsub(s,"%(%+%)","%(%+1%)") s=string.gsub(s,"%((%+)([0-9]+)%)","Dientich%2") s=string.gsub(s,"%+","%)%+%(") s="val_1*("..s s=string.gsub(s,"%+",function (s) i=i+1 return "+val_"..i.."*" end) s=string.gsub(s,"%=","%)%=%(") s=string.gsub(s,"%=",function (s) i=i+1 return "=val_"..i.."*" end) s=string.gsub(s,"(%u%l*)([0-9])","%1*%2") s=string.gsub(s,"(%u)","+%1") s=string.gsub(s,"%(","+%1") s=string.gsub(s,"%(%+","%(") s=string.gsub(s,",%+",",") s=string.gsub(s,"(%))([0-9])","%1*%2") s=string.gsub(s,"%*%+","%*") s=string.gsub(s," ","") s=string.gsub(s,"%(%+","%(") s=tostring(cas.expand(s..")|Dientich=-Aientich")) return s,i end function getval(sf) local val,s,i={},sf,1 for w in string.gmatch(s,"%u%l+") do val[i]=w s=string.gsub(s,val[i],"") i=i+1 end for w in string.gmatch(s,"%u") do val[i]=w i=i+1 end i=1 table.sort(val) while(i<#val) do if(val[i]==val[i+1]) then table.remove(val,i) else i=i+1 end end return(val) end function canbang(ss,pri) local s,numval=duavedangcoban(ss) local gv=getval(s) local strgv="|"..table.concat(gv,"=0|").."=0" local func="solve({" for i=1,#gv,1 do func=func..cas(s.."|"..tostring(gv[i]).."=1"..strgv) if i~=#gv then func=func.."," else func=func.."}," end end func=func.."{" for i=1,#gv,1 do func=func.."val_"..i if i~=#gv then func=func.."," else func=func.."})" end end if(#gv<numval) then for i=#gv+1,numval,1 do func=func.."|val_"..i.."=87297210" end end func=string.gsub(func,"=0","=87297210") local kq=tostring(cas.getright(func)) kq=string.gsub(kq,"val_[0-9]","87297210") kq=string.gsub(kq,"î","%*") local sqk dostring("skq="..kq) local uc=skq[1] for i=2,#skq,1 do uc=ucln(uc,skq[i]) end ss=string.gsub(ss,"%(([%+%-])([0-9]*)%)",function(a,B) a=string.gsub(a,"%+","%Ãú") a=string.gsub(a,"%-","%Ãû") b=string.gsub(b,"1","Ãñ") b=string.gsub(b,"2","Ãò") b=string.gsub(b,"3","Ãó") b=string.gsub(b,"4","Ãô") b=string.gsub(b,"5","Ãõ") b=string.gsub(b,"6","Ãö") b=string.gsub(b,"7","Ã÷") b=string.gsub(b,"8","Ãø") b=string.gsub(b,"9","Ãù") b=string.gsub(b,"0","Ãð") return(b..a) end) ss=string.gsub(ss,"0","ìð") ss=string.gsub(ss,"1","ìñ") ss=string.gsub(ss,"2","ìò") ss=string.gsub(ss,"3","ìó") ss=string.gsub(ss,"4","ìô") ss=string.gsub(ss,"5","ìõ") ss=string.gsub(ss,"6","ìö") ss=string.gsub(ss,"7","ì÷") ss=string.gsub(ss,"8","ìø") ss=string.gsub(ss,"9","ìù") i=1 ss=del1(skq[1]/uc)..ss ss=string.gsub(ss,"%+",function (s) i=i+1 if (i>#skq) then return "+"..del1(87297210/uc) else return "+"..del1(skq[i]/uc) end end ) ss=string.gsub(ss,"%=",function (s) i=i+1 if (i>#skq) then return "="..del1(87297210/uc) else return "="..del1(skq[i]/uc) end end ) ss=string.gsub(ss," ","") if pri then print(ss) end return(ss) end export{cb=canbang}
#3
Posted 24 May 2012 - 03:31 PM
I think it will be difficult to convert it, since some of the functions in this code aren't on fx 9860: there is no cas functions and neither string.gsub
#4
Posted 26 May 2012 - 01:48 AM
maybe we could make some cas functions...
also, why are there no line breaks in any of the CPLua code i have seen? does it make the file size smaller or is it some sort of optimization?
also, why are there no line breaks in any of the CPLua code i have seen? does it make the file size smaller or is it some sort of optimization?
#5
Posted 26 May 2012 - 10:37 AM
You can feel the lack of line breaks in a few of vanhoa's latest programs, and he did it to make smaller programs, but the rest of the programs are formatted and indented.
Open any of them with the CP MCS Editor and watch for yourself. I still don't know why it didn't work for JackZhan?
Open any of them with the CP MCS Editor and watch for yourself. I still don't know why it didn't work for JackZhan?
#6
Posted 26 May 2012 - 12:15 PM
maybe we could make some cas functions...
also, why are there no line breaks in any of the CPLua code i have seen? does it make the file size smaller or is it some sort of optimization?
Probably and optimization added before it is sent to the calc; in an editor, it may have formatting.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users