Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Modify Lists scheme

Name: Anonymous 2012-02-27 17:30

how would I write a function in scheme that takes a nested list as an argument and returns a list of lists. For example if I gave it ( ((1 2 3) (2 3 4) (3 4 5)) (4 5 6) (5 6 7) (8 9 10)) ) it would return  ( (1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7) (8 9 10)  )

Name: Anonymous 2012-02-27 17:43

It takes a certain special flavor of stupid to ask /prog/ to do your homework.

Name: Anonymous 2012-02-27 17:51

This isnt homework, im a working on a project Euler question and need this to find a solution

Name: Anonymous 2012-02-27 18:00

(define (tree->alist tree)
  (cond ((null? tree) '())
        ((alist? (car tree))
         (append (car tree) (tree->alist (cdr tree))))
        (else (cons (car tree) (tree->alist (cdr tree))))))

(define (alist? obj)
  (cond ((null? obj) #t)
        ((not (list? (car obj))) #f)
        (else (alist? (cdr obj)))))

Name: Anonymous 2012-02-28 1:35

car

Don't change these.
Name: Email:
Entire Thread Thread List