Advertisement
Guest User

Untitled

a guest
Jan 14th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.87 KB | None | 0 0
  1. ; flatten the list
  2. (defun transform (lst)
  3.     (cond
  4.         ((null lst) nil)
  5.         ((numberp (car lst)) (cons (car lst) (transform (cdr lst))))
  6.         ((atom (car lst)) (transform (cdr lst)))
  7.         (t (append (transform (car lst)) (transform (cdr lst))))
  8.     )
  9. )
  10.  
  11. (defun maxList (lst)
  12.     (cond
  13.         ((atom lst) lst)
  14.         (t (apply 'max (mapcar 'maxList lst)))
  15.     )
  16. )
  17.  
  18. ; Verificam daca elem max din lista e par
  19. (defun verif (lst)
  20.     (cond
  21.         ((null (transform lst)) nil)
  22.         ((= (mod (maxList (transform lst)) 2) 0) T)
  23.         (T nil)
  24.     )
  25. )
  26.  
  27. ; count all sublists having the maximal numeric atom on all odd levels is even
  28. (defun cntSubListe (lst level)
  29.     (cond
  30.         ((atom lst) 0)
  31.         ((and (verif lst) (= (mod level 2) 1)) (+ 1 (apply '+ (mapcar(lambda (a) (cntSubListe a (+ 1 level))) lst))))
  32.         (T (apply '+ (mapcar(lambda (a) (cntSubListe a (+ 1 level))) lst)))
  33.     )
  34. )
  35.  
  36. (defun solveMain (lst) (cntSubListe lst 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement