From a6a5175329cf17a7e126a2d7ffbe0e32270b8194 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Sun, 20 Apr 2025 22:46:10 -0400 Subject: [PATCH] Better indent --- p16/p16.org | 83 ++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/p16/p16.org b/p16/p16.org index bb8e989..80a4ca9 100644 --- a/p16/p16.org +++ b/p16/p16.org @@ -146,49 +146,48 @@ score. Hence at the end we look (recursively) in the discard pile and put the ones that end on the best paths with the same score in the best pile. #+begin_src emacs-lisp - (setq start-vector (list start '(1 0) 0)) ; starting point, direction and score - - (defun next-dirs (dir) - (--filter (>= (dot it dir) 0) '((0 1) (0 -1) (-1 0) (1 0)))) - - (defun acceptable-p (p dir) - (not (eq (thing-at (neighbour p dir)) 'wall))) - - (defun sort-vecs (a b) - (< (caddar a) (caddar b))) - - (defun delta-score (olddir newdir) - (if (equal olddir newdir) 1 1001)) - - (defun explore (start-vects) - (let ((start-vect (car start-vects))) - (if (eq (thing-at (car start-vect)) 'end) (progn (push start-vects scores) nil) - (let* ((p (car start-vect)) - (dir (cadr start-vect)) - (score (caddr start-vect)) - (acceptable-next-dirs (--filter (acceptable-p p it) (next-dirs dir)))) - (if (-contains-p book (list p dir)) (progn (push start-vects discard) nil) - (push (list p dir) book) - (--map (cons (list (neighbour p it) it (+ score (delta-score it dir))) start-vects) acceptable-next-dirs)))))) - - (setq book nil - scores nil - discard nil) - - (setq start-list (list (list start-vector))) - (while (setq start-list (-concat (explore (car start-list)) (cdr start-list))) - (setq start-list (-sort #'sort-vecs start-list))) - (let ((best (list (cadr scores))) - (repechage t)) - (while repechage - (setq repechage (-filter (lambda (candidate) - (--any-p (-contains-p it (car candidate)) best)) - discard)) - (setq best (-union repechage best) - discard (-difference discard repechage))) - (length (-distinct (--mapcat (-map #'car it) best)))) + (setq start-vector (list start '(1 0) 0)) ; starting point, direction and score + + (defun next-dirs (dir) + (--filter (>= (dot it dir) 0) '((0 1) (0 -1) (-1 0) (1 0)))) + + (defun acceptable-p (p dir) + (not (eq (thing-at (neighbour p dir)) 'wall))) + + (defun sort-vecs (a b) + (< (caddar a) (caddar b))) + + (defun delta-score (olddir newdir) + (if (equal olddir newdir) 1 1001)) + + (defun explore (start-vects) + (let ((start-vect (car start-vects))) + (if (eq (thing-at (car start-vect)) 'end) (progn (push start-vects scores) nil) + (let* ((p (car start-vect)) + (dir (cadr start-vect)) + (score (caddr start-vect)) + (acceptable-next-dirs (--filter (acceptable-p p it) (next-dirs dir)))) + (if (-contains-p book (list p dir)) (progn (push start-vects discard) nil) + (push (list p dir) book) + (--map (cons (list (neighbour p it) it (+ score (delta-score it dir))) start-vects) acceptable-next-dirs)))))) + + (setq book nil + scores nil + discard nil) + + (setq start-list (list (list start-vector))) + (while (setq start-list (-concat (explore (car start-list)) (cdr start-list))) + (setq start-list (-sort #'sort-vecs start-list))) + (let ((best (list (cadr scores))) + (repechage t)) + (while repechage + (setq repechage (-filter (lambda (candidate) + (--any-p (-contains-p it (car candidate)) best)) + discard)) + (setq best (-union repechage best) + discard (-difference discard repechage))) + (length (-distinct (--mapcat (-map #'car it) best)))) #+end_src #+results: : 456 -