diff --git a/p24/p24.org b/p24/p24.org index b67a1b2..03045c6 100644 --- a/p24/p24.org +++ b/p24/p24.org @@ -76,9 +76,23 @@ Create a list of all x, y and z bits Define the functions that implement the code on the wires #+begin_src emacs-lisp :results none + ;; strip all the depth nonsense + + (defun eval-wires () + (-map #'eval wires)) + + :: TODO rewrite by recursion (defun run (fn) - (while (not (-every #'eval (-drop depth used-zzz))) - (funcall fn))) + "Runs fn until the wires stabilize. when they do, return t if all used + output wires are set and nil otherwise" + (let* ((ew (eval-wires)) + (old-ew)) + + (while (not (equal old-ew ew)) + (funcall fn) + (setq old-ew ew + ew (eval-wires)))) + (-every #'eval (-drop depth used-zzz))) (defun reset-var (li) "Set every wire in the list LI to nil" @@ -97,8 +111,8 @@ Define the functions that implement the code on the wires (reset-var wires) (set-var used-xxx x) (set-var used-yyy y) - (run #'step-ng) - (var-value used-zzz)) + (when (run #'step-ng) + (var-value used-zzz))) #+end_src Let us try to reduce the problem; there are two classes of wires @@ -187,59 +201,94 @@ We can "propagate" this information : prune-gates #+begin_src emacs-lisp - (update-function gates) - (setq depth 0) - - ; we check bit by bit - (while (lsb-works) - (message (format "%d" depth)) - ;; supposedly the DEPTH bit is ok; remove all gates that output to it - (prune-gates (list (nth depth used-xxx) - (nth depth used-yyy))) - (update-function gates) - (setq depth (1+ depth))) - - ;; when I get here it is possible that either the depth-th or the - ;; depth+1-th output bit is wrong - - (defun wrong-bit () - (if (and - (eq 1 (run-function 0 1)) - (eq 1 (run-function 1 0))) - (nth (1+ depth) used-zzz) - (nth depth used-zzz))) - - (defun tentative-substitutions () - (let ((gates-need-fixing (gates-outputting-on (wrong-bit))) - (gates gates)) - ;; Now we bruteforce; which ones are the gates that are involved in - ;; the error? - (prune-gates (append (-drop (1+ depth) used-xxx) - (-drop (1+ depth) used-yyy))) - (let ((wires-a (-map #'caddr gates-need-fixing)) - (wires-b (-map #'caddr gates))) - (-mapcat (lambda (wire-a) (--map (cons wire-a it) wires-b)) wires-a)))) - - (defun lsb-works () - (and (eq 1 (run-function 0 1)) - (eq 1 (run-function 1 0)) - (eq 2 (run-function 1 1)))) - - ;; oh, it may end in a loop in fact. So I need to take care of this - ;; possibility too - - (--filter (progn - (update-function (swap-output it gates)) - (lsb-works)) - (tentative-substitutions)) - - (run-function 1 1) + (setq depth 0) + + ; we check bit by bit + (while (lsb-works) + (message (format "%d" depth)) + ;; supposedly the DEPTH bit is ok; remove all gates that output to it + (prune-gates (list (nth depth used-xxx) + (nth depth used-yyy))) + (update-function gates) + (setq depth (1+ depth))) + + ;; when I get here it is possible that either the depth-th or the + ;; depth+1-th output bit is wrong + + (defun wrong-bit () + (if (and + (eq 1 (run-function 0 1)) + (eq 1 (run-function 1 0))) + (nth (1+ depth) used-zzz) + (nth depth used-zzz))) + + (defun tentative-substitutions () + (let ((gates-need-fixing (gates-outputting-on (wrong-bit))) + (gates gates)) + ;; Now we bruteforce; which ones are the gates that are involved in + ;; the errorm + + (prune-gates (append (-drop (1+ depth) used-xxx) + (-drop (1+ depth) used-yyy))) + (jsueje) + (let ((wires-a (-map #'caddr gates-need-fixing)) + (wires-b (-map #'caddr gates))) + (-mapcat (lambda (wire-a) (--map (cons wire-a it) wires-b)) wires-a)))) + + (defun lsb-works () + (and (run-function 0 0) + (eq 1 (run-function 0 1)) + (eq 1 (run-function 1 0)) + (eq 2 (run-function 1 1)))) + + ;; oh, it may end in a loop in fact. So I need to take care of this + ;; possibility too + + (--filter (progn + (update-function (swap-output it gates)) + (lsb-works)) + (tentative-substitutions)) + (let ((gates (swap-output '(z11 . z12) gates))) + (tentative-substitutions)) + + (run-function 1 1) ;; try and fix + (defun create-swaps (li) + (when li + (append (--map (cons (car li) it) (cdr li)) + (create-swaps (cdr li))))) + + ( length gates) + (setq swappers + (let ((gates gates)) + (prune-gates (append (-drop 10 used-xxx) + (-drop 10 used-yyy))) + (create-swaps (-map #'caddr gates)))) + + (length swappers) + (setq working-swappers + (--filter (progn + (message (symbol-name (car it))) + (update-function (swap-output it gates)) + (run-function 0 0)) + swappers)) + + (length working-swappers) + (setq plausible-swappers + (--filter (progn + (message (symbol-name (car it))) + (update-function (swap-output it gates)) + (eq 2048 (run-function 1024 1024))) + working-swappers)) + (setq depth 0) + (run-function 1024 1024) + + (length plausible-swappers) #+end_src ** old stuff