;;;; from http://www.frank-buss.de/challenge/index.html (setf *vertices* '(p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10)) (setf *lines* '((p0 p1) (p0 p2 p4 p6) (p0 p3 p7 p9) (p0 p5 p8 p10) (p1 p2 p3 p5) (p1 p4 p7 p8) (p1 p6 p9 p10))) (defun all-in-linep (v-list line) "Returns whether the list of vertices 'v-list' is all in the line 'line'." (subsetp v-list line)) (defun on-same-linep (lines &rest v-list) "Returns whether the list of vertices 'v-list' is in any line of 'lines'." (some #'(lambda (line) (all-in-linep v-list line)) lines)) (defun trianglep (lines v1 v2 v3) "Returns whether v1, v2, v3 make a triangle with area > 0." (and (on-same-linep lines v1 v2) (on-same-linep lines v1 v3) (on-same-linep lines v2 v3) (not (on-same-linep lines v1 v2 v3)))) (defun get-triangles (vertices lines) "Loops over all possible triangles and returns valid ones." (loop for v1-list on vertices append (loop for v2-list on (rest v1-list) append (loop for v3-list on (rest v2-list) for v1 = (first v1-list) for v2 = (first v2-list) for v3 = (first v3-list) when (trianglep lines v1 v2 v3) collect (list v1 v2 v3))))) (let ((triangles (get-triangles *vertices* *lines*))) (print triangles) (print (length triangles)))