- filling in to the rectangle
- transposing
Rectangularization:
- 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))
Transposing:
- Code: Select all
(define (transpose data)
(apply map list data))
Solution:
- Code: Select all
(define (solution data)
(transpose (make-rectangle data '())))
Here it is on repl.it.
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. (cons (process ...) ...)