PROBLEM SCHEME

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

Re: PROBLEM SCHEME

Postby Goheeca » Tue Oct 13, 2015 3:30 am

I would decompose it to two problems.
  1. filling in to the rectangle
  2. 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:
  1. condition of termination -- e.g. null?
  2. tail value/elementar operation -- e.g. '()
  3. recursive computation itself (processing of an element + compounding of the results)
  4. -- e.g. (cons (process ...) ...)
During the construction of an recursive function try to ask how these parts look like and then it should be easy.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
User avatar
Goheeca
 
Posts: 271
Joined: Thu May 10, 2012 12:54 pm

Previous

Return to Homework

Who is online

Users browsing this forum: No registered users and 2 guests