Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (clone a n)
- (if (eq? n 0) '() (cons a (clone a (- n 1)))
- )
- )
- (define (get-depth lst n)
- (cond
- ((null? lst) '())
- ((list? (car lst)) (cons (get-depth (car lst) (+ n 1)) (get-depth (cdr lst) n)))
- (else (cons n (get-depth (cdr lst) n)))
- )
- )
- (define (traverse lst1 lst2)
- (cond
- ((null? lst1) '())
- (else (cons (clone (car lst2) (car lst1)) (traverse (cdr lst1) (cdr lst2)))
- )
- )
- )
- (define (depth-replicate lst)
- (flatten (traverse (flatten (get-depth lst 1)) (flatten lst)))
- )
- (display (depth-replicate '((((3 2))) ((1)) (1))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement