Derivative by nn

System.in.eachLine{o=''
it.eachMatch(/(-?\d*)x(\^(.[^-+]*))?/){p,a,q,b->int c=b?b.toFloat()*10:10
c=c-76?c:77
a=(int)(a-'+'?a-'-'?a.toFloat()*c:-c:c)/10
c/=10
o+=o&&a>0?'+':''
o+=--c?(a-1?a+1?a:'-':'')+(c-1?'x^'+c:'x'):a}
println o?:0}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page