Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun bajar-atomos (L)
- (labels ((flat (l acc)
- (cond ((null l) acc)
- ((atom l) (cons l acc))
- (t (flat (car l)
- (flat (cdr l) acc)))))
- (depth (l)
- (cond ((null l) 0)
- ((atom (car l)) (depth (cdr l)))
- (t (max (1+ (depth (car l)))
- (1+ (depth (cdr l)))))))
- (rec (l target &optional (depth 1))
- (cond ((null l) nil)
- ((= target depth) (flat l nil))
- ((atom (car l)) (cons (car l)
- (rec (cdr l) target depth)))
- (t (cons (rec (car l) target (1+ depth))
- (rec (cdr l) target depth))))))
- (rec L (1- (depth L)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement