(defun idea (tbl &optional (enough 2)) (with-slots (rows left right) tbl (when (> (length rows) enough) (let* ((any (anyv rows)) (west (furthest tbl any rows))) (multiple-value-bind (east c) (furthest tbl west rows) (let* ((all (rows-sorted-along-x tbl rows west east c)) (half (floor (/ (length all) 2))) (above (copy-table tbl)) (below (copy-table tbl))) (setf (table-rows below) (vector! (subseq all 0 half)) (table-rows above) (vector! (subseq all half)) left below right above) (idea left enough) (idea right enough)))) tbl))) (defun rows-sorted-along-x (tbl rows west east c &aux all) (dov (one rows) (let ((place (x (dist tbl one west) (dist tbl one east) c))) (push (cons place one) all))) (mapcar #'cdr (sort all #'< :key #'car))) (defun x (a b c) "Find x of (x,y) that is distance 'a' from (0,0) and 'b' fron (c,0)" (if (zerop c) 0 (/ (+ (* a a) (* c c) (* -1 b b)) (* 2 c)))) (defun y (a x) "Find x of (x,y) that is distance 'a' from (0,0) and 'b' fron (c,0)" (sqrt (+ (* a a) (* -1 x x)))) (defun printt (tbl &optional (depth 0) (prefix "") (str t) (padding "| ") ) (when tbl (dotimes (i depth) (format str "~a" padding)) (format str "~a~a~%" prefix (length (table-rows tbl))) (printt (table-left tbl) (1+ depth) "<" str padding) (printt (table-right tbl) (1+ depth) ">" str padding) t) ) (deftest !idea1 () (dolist (what '(15 10 5 2)) (!idea1-prim "data/autos32.lisp" what))) (defun !idea1-prim (f &optional (enough 30)) (print `(,enough ,(time-it 1 (idea (slurp f) enough)))))