Polynomial long division: Difference between revisions

Content added Content deleted
(→‎E: new example)
m (→‎{{header|E}}: simplify printing, fix bug with zero polynomial)
Line 250: Line 250:
if (i < 0) { -Infinity } else { i }
if (i < 0) { -Infinity } else { i }
}
}
def coeffs := initCoeffs(0, degree + 1)
def coeffs := initCoeffs(0, if (degree == -Infinity) { [] } else { degree + 1 })
def polynomial {
def polynomial {
/** Print the polynomial (not necessary for the task) */
/** Print the polynomial (not necessary for the task) */
to __printOn(out) {
to __printOn(out) {
out.print("(λx. ")
out.print("(λx.")
var first := true
var first := true
for i in (0..!(coeffs.size())).descending() {
for i in (0..!(coeffs.size())).descending() {
def coeff := coeffs[i]
def coeff := coeffs[i]
if (coeff <=> 0) { continue }
if (coeff <=> 0) { continue }
if (!first) { out.print(" ") }
out.print(" ")
if (coeff <=> 1 && !(i <=> 0)) {
if (coeff <=> 1 && !(i <=> 0)) {
# no coefficient written if it's 1 and not the constant term
# no coefficient written if it's 1 and not the constant term