SHARE
TWEET

Untitled

a guest Sep 19th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defun sum-list (a)
  2.     (cond
  3.         ((NULL a) 0)
  4.         (T (+ (CAR a) (sum-list (CDR a))))
  5.     )
  6. )
  7.  
  8. (defun sum-pair (a)
  9.     (cond
  10.         ((NULL a) NIL)
  11.         (T (cons (sum (CAR a)) (sum-pair (CDR a))))
  12.     )
  13. )
  14.  
  15. (defun max-list (a)
  16.     (cond
  17.         ((NULL a) NIL)
  18.         ((NULL (CDR a)) (CAR a))
  19.         ((> (CAR a) (max-list (CDR a))) (CAR a))
  20.         (T (max-list (CDR a)))
  21.     )
  22. )
  23.  
  24. (defun pn-sum (a)
  25.     (cond
  26.         ((NULL a) '(0 0))
  27.         (T
  28.             (LIST
  29.                 (+ (cond ((> (CAAR a) 0) (CAAR a)) (T (CADAR a))) (CAR (pn-sum (CDR a))))
  30.                 (+ (cond ((< (CAAR a) 0) (CAAR a)) (T (CADAR a))) (CADR (pn-sum (CDR a))))
  31.             )
  32.         )
  33.     )
  34. )
  35.  
  36. (print (pn-sum '((1 -1) (3 -2) (-3 6) (0 3))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top