;;; Attempt the first: (defparameter *l1* '((0 1) (0 2 4 6) (0 3 7 9) (0 5 8 10))) (defparameter *l2* '((1 0) (1 2 3 5) (1 4 7 8) (1 6 9 10))) (defun on-line (p1 p2) "Return which line-type p1 and p2 are on, nil if none" (loop for lines in '(*l1* *l2*) do (loop for l in (symbol-value lines) if (and (member p1 l) (member p2 l)) do (return-from on-line lines)))) (defun find-triangles () (loop for c1 upto 8 nconc (loop for c2 from (1+ c1) upto 9 nconc (loop for c3 from (1+ c2) upto 10 for l = (list (on-line c1 c2) (on-line c2 c3) (on-line c1 c3)) if (and (not (member nil l)) (subsetp '(*l1* *l2*) l)) collect (list c1 c2 c3))))) ;;; Attempt the second: (defun find-tri-gen (rays) "Find triangles from intersection between rays from two points. The baseline between the points is a legal edge. The intersections are numbered by rays, and the intersection between ray r1 from point 0 and ray r2 from point 1 is point (+ 2 r1 (* r2 rays))." ;; There are exactly three legal triangle types: ;; * Those that contain the baseline (both points 0 and 1) and any intersection ;; * Those that contain point 0 and two intersections on a ray from point 1 ;; * Those that contain point 1 and two intersections on a ray from point 0 ;; The three collects below correspond to these types. (loop for r1 below rays nconc (loop for r2 below rays collect (list 0 1 (+ (* r1 rays) r2 2)) nconc (loop for r3 from (1+ r2) below rays collect (list 0 (+ (* r1 rays) r2 2) (+ (* r1 rays) r3 2)) collect (list 1 (+ r1 (* r2 rays) 2) (+ r1 (* r3 rays) 2))))))