;; author: Tayssir John Gabbour ;; Permission is not granted for use in nuclear reactors or defense systems. ;; Contact for permission in these cases and I'll actually test whether this ;; silly code works. If I like you. ;; lines: 37 lines without blank lines. ;; time: 30min +/- 5min for answer. ;; 10min to remove unused code, tediously eyeball whether it actually ;; gave correct triangles, and write these comments. (defconstant +lines+ '((p0 p5 p8 p10) (p0 p1) (p0 p3 p7 p9) (p0 p2 p4 p6) (p1 p2 p3 p5) (p1 p4 p7 p8) (p1 p6 p9 p10))) (defun colinear (blah1 blah2) (loop for i in +lines+ thereis (and (member blah1 i) (member blah2 i)))) (defun forms-triangle? (trip) (let ((n1 (first trip)) (n2 (second trip)) (n3 (third trip))) (and (colinear n1 n2) (colinear n1 n3) (colinear n2 n3) (loop for i in +lines+ never (and (member n1 i) (member n2 i) (member n3 i)))))) (defun all-triples (points) (loop for sublist on points for i = (car sublist) nconc (loop for sublist2 on (cdr sublist) for j = (car sublist2) nconc (loop for sublist3 on (cdr sublist2) for k = (car sublist3) collect (list i j k))))) (defconstant +points+ ;no, I didn't type these out by hand ;) '(p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10)) (defparameter *answers* (loop for i in (all-triples +points+) when (forms-triangle? i) collect i)) (format t "~&Number of triangles: ~A. ~%Triangles: ~{~A ~}" (length *answers*) *answers*) ;;; Unused code. ;; (defun triple= (trip1 trip2) ;; (equal (sort trip1 #'string<) ;; (sort trip2 #'string<))) ;; (colinear 'p4 'p8) ;; (colinear 'p4 'p10) ;; (triple= '(p1 p3 p5) '(p5 p1 p3)) ;; (all-triples +points+) ;; (loop for i from 0 to 10 do (format t "p~S " i))