Advertisement
Nuparu00

testest

Dec 13th, 2021
2,541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.66 KB | None | 0 0
  1. ;;TEST
  2.  
  3. ;;1
  4. (defun triangle-center (tri)
  5.   (point (/ (+ (point-x (v1 tri)) (point-x (v2 tri)) (point-x (v3 tri))) 3)
  6.          (/ (+ (point-y (v1 tri)) (point-y (v2 tri)) (point-y (v3 tri))) 3)))
  7.  
  8. ;;2
  9.  
  10. (defun sum-digits (x)
  11.   (if (< x 10)
  12.       x
  13.     (+ (rem x 10) (sum-digits (floor x 10)))))
  14.  
  15. ;;3
  16. ;;(let ((last (cons 'B 'C))) (cons last (cons last 'A)))
  17.  
  18. ;;4
  19.  
  20. (defun even-elements (list)
  21.   (cond ((null list) nil)
  22.          ((evenp (car list)) (cons (car list) (even-elements (cdr list))))
  23.          (t (even-elements (cdr list)))))
  24.  
  25. ;;5
  26.  
  27. (defun my-set-intersection-2 (a b)
  28.   (cond ((null a) nil)
  29.         ((null b) nil)
  30.         ((contains b (car a)) (cons (car a) (my-set-intersection-2 (cdr a) b)))
  31.         (t (my-set-intersection-2 (cdr a) b))))
  32.  
  33.  
  34. (defun contains (list a)
  35.   (cond ((null list) nil)
  36.         ((= (car list) a) t)
  37.         ((> (car list) a) nil)
  38.         (t (contains (cdr list) a))))
  39.  
  40. ;;6
  41.  
  42. (defun my-set-intersection (a &rest rest)
  43.   (cond ((null rest) a)
  44.         (t (apply #'my-set-intersection (my-set-intersection-2 a (car rest)) (cdr rest)))))
  45.  
  46. ;;7
  47. (defun seq-interleave (a b)
  48.   (lambda (x) (if (evenp x) (funcall a (/ x 2)) (funcall b (floor (/ x 2)) ))))
  49.  
  50. (defun find-path (tree n)
  51.   (cond ((null tree) nil)
  52.         ((eql (car tree) n) (list (car tree)))
  53.         ((null (cdr tree)) nil)
  54.         (t (let ((next (find-path-children (cdr tree) n)))
  55.           (if (eql next nil) nil (cons (car tree) next))))))
  56.  
  57.  
  58. (defun find-path-children (children n)
  59.   (cond ((null children) nil)
  60.         (t (let ((child (find-path (car children) n)))
  61.              (if (eql child nil) (find-path-children (cdr children) n) child)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement