Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (defun read-input(p)
  3. (cond
  4.    ((null p) nil)
  5.    (T (cons p (read-input (read nil nil))))
  6. )
  7. )
  8.  
  9. (defun readinput(i)
  10.     (cdr (read-input 1))
  11. )
  12.  
  13.  
  14. (defun depth (list maxdepth tmpdepth)  ;nacin1
  15.     (cond
  16.         ((null list) maxdepth)
  17.         ((listp (car list))
  18.             (setq tmp (depth (car list) maxdepth (+ tmpdepth 1)))
  19.             (if (> tmp maxdepth) (depth (cdr list) tmp tmpdepth) (depth (cdr list) maxdepth tmpdepth))
  20.          )
  21.         ((> tmpdepth maxdepth) (depth (cdr list) tmpdepth tmpdepth))
  22.         (t (depth (cdr list) maxdepth tmpdepth))
  23.         )
  24.     )
  25.  
  26.  
  27. (defun depth (lista dep maxdep)    ;nacin2
  28.     (cond
  29.         ((null lista) maxdep)
  30.         ((atom (car lista)) (depth (cdr lista) dep maxdep))
  31.         (T (depth (cdr lista) dep (depth (car lista) (+ 1 dep) (max (+ 1 dep) maxdep))))
  32.         )
  33.     )
  34.  
  35. (defun najvgnezdenipodnizi (lista dep maxdep)
  36.     (cond
  37.         ((null lista) nil)
  38.         ((and (atom (car lista)) (eq dep maxdep))
  39.                (cons (car lista) (najvgnezdenipodnizi (cdr lista) dep maxdep)))
  40.         ((and (listp (car lista)) (eq maxdep (+ 1 dep)))
  41.                (cons (car lista) (najvgnezdenipodnizi (cdr lista) dep maxdep)))
  42.         ((and (listp (car lista)) (not (eq maxdep (+ 1 dep))))
  43.                (append (najvgnezdenipodnizi (car lista) (+ 1 dep) maxdep) (najvgnezdenipodnizi (cdr lista) dep maxdep)))
  44.         (T (najvgnezdenipodnizi (cdr lista) dep maxdep))
  45.         )
  46.     )
  47.  
  48.  
  49. (setq maxdep(depth '(1 2 (3 (4) 5 (6 (7 8)) 9) ((10 (11 12) 13)) 14) 0 0))
  50. (print (najvgnezdenipodnizi '(1 2 (3 (4) 5 (6 (7 8)) 9) ((10 (11 12) 13)) 14) 0 maxdep))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement