Advertisement
Guest User

bajar-atomos

a guest
Jun 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. (defun bajar-atomos (L)
  2. (labels ((flat (l acc)
  3. (cond ((null l) acc)
  4. ((atom l) (cons l acc))
  5. (t (flat (car l)
  6. (flat (cdr l) acc)))))
  7. (depth (l)
  8. (cond ((null l) 0)
  9. ((atom (car l)) (depth (cdr l)))
  10. (t (max (1+ (depth (car l)))
  11. (1+ (depth (cdr l)))))))
  12. (rec (l target &optional (depth 1))
  13. (cond ((null l) nil)
  14. ((= target depth) (flat l nil))
  15. ((atom (car l)) (cons (car l)
  16. (rec (cdr l) target depth)))
  17. (t (cons (rec (car l) target (1+ depth))
  18. (rec (cdr l) target depth))))))
  19. (rec L (1- (depth L)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement