;; build an html string from list of coeffs
(define (linear->html coeffs)
(define plus #f)
(or*
(for/fold (html "") ((a coeffs) (i (in-naturals 1)))
(unless (zero? a)
(set! plus (if plus "+" "")))
(string-append html
(cond
((= a 1) (format "%a e%d " plus i))
((= a -1) (format "- e%d " i))
((> a 0) (format "%a %d*e%d " plus a i))
((< a 0) (format "- %d*e%d " (abs a) i))
(else ""))))
"0"))
(define linears '((1 2 3)
(0 1 2 3)
(1 0 3 4)
(1 2 0)
(0 0 0)
(0)
(1 1 1)
(-1 -1 -1)
(-1 -2 0 -3)
(-1)))
(define (task linears)
(html-print ;; send string to stdout
(for/string ((linear linears))
(format "%a -> %a
" linear (linear->html linear)))))