RosettaCodeData/Task/Polynomial-long-division/Sidef/polynomial-long-division-1.sidef
2017-09-25 22:28:19 +02:00

20 lines
407 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

func poly_long_div(rn, rd) {
 
var n = rn.map{_}
var gd = rd.len
 
if (n.len >= gd) {
return(gather {
while (n.len >= gd) {
var piv = n[0]/rd[0]
take(piv)
{ |i|
n[i] -= (rd[i] * piv)
} << ^(n.len `min` gd)
n.shift
}
}, n)
}
 
return([0], rn)
}