You are viewing a single comment's thread. Return to all comments →
Common Lisp (SBCL):
(defun distance (p1 p2) (sqrt (+ (expt (- (first p1) (first p2)) 2) (expt (- (second p1) (second p2)) 2)))) (defun f2 (l) (if (cdr l) ; if this list has more than one element left (let ((p1 (first l)) (p2 (second l))) (+ (distance p1 p2) (f2 (cdr l)))) 0)) (defun f (l) ; Appends the first element to the end of the list and calls f2 (f2 (append l (list (car l))))) (defun read-pairs (n) (if (eq n 0) () (cons (list (read *standard-input*) (read *standard-input*)) (read-pairs (- n 1 ))))) (defun solve-case () (f (read-pairs (read)))) (princ (solve-case))
Seems like cookies are disabled on this browser, please enable them to open this website
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
Common Lisp (SBCL):