- filling in to the rectangle
- transposing
Code: Select all
(define (repeat n elem)
(if (= n 0)
'()
(cons elem (repeat (- n 1) elem))))
(define (fill-list lst len elem)
(if (>= (length lst) len)
lst
(append lst (repeat (- len (length lst)) elem))))
(define (make-rectangle data with)
(map (lambda (row)
(fill-list row (apply max (map length data)) with))
data))
Code: Select all
(define (transpose data)
(apply map list data))
Code: Select all
(define (solution data)
(transpose (make-rectangle data '())))
What concerns recursive thinking, there are three main parts in a simple recursion:
- condition of termination -- e.g. null?
- tail value/elementar operation -- e.g. '()
- recursive computation itself (processing of an element + compounding of the results) -- e.g. [i](cons (process ...) ...)[/i]