From dde69103925d2ed8848cd2549187b46358cf3224 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Sun, 7 Dec 2025 20:49:13 -0500 Subject: [PATCH] [p7] better whitespace and comments --- p7/p7.org | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/p7/p7.org b/p7/p7.org index ee82220..604c3e6 100644 --- a/p7/p7.org +++ b/p7/p7.org @@ -17,15 +17,11 @@ Yay, another 2D problem height (length data-char)) #+end_src -This is for part 1; +This is for part 1; record the splitting points and count them at the end #+begin_src emacs-lisp - - - (defun position-valid-p (pos) - (and (and (>= (car pos) 0) (< (car pos) width)) - (and (>= (cadr pos) 0) (< (cadr pos) height)))) - - (advent/char-at '(-1 0) data-char) + (defun position-valid-p (pos) + (and (>= (car pos) 0) (< (car pos) width) + (>= (cadr pos) 0) (< (cadr pos) height))) (defun tachyon-step (el) (if (not (position-valid-p el)) (list el) @@ -35,27 +31,40 @@ This is for part 1; (list down) (push down splits) (--map (advent/neighbour el it) '((-1 0) (1 0))))))) - (setq tachyons (advent/coordinates-of ?S data-char)) - (setq splits nil) - (length (--fix (-distinct (-mapcat 'tachyon-step it)) tachyons)) + + + (setq tachyons (advent/coordinates-of ?S data-char) + splits nil) + (--fix (-distinct (-mapcat 'tachyon-step it)) tachyons) (length (-distinct splits)) #+end_src #+RESULTS: : 1507 +This is for part 2. At each step record how many beams are at a given +position. Each beam has some multiplicity. ~compress~ merges beams at +the same position in one beam with multiplicity equal to the sum of +the multiplicities of each beam #+begin_src emacs-lisp (defun tachyon-step-freq (el) - (--map (cons it (cdr el)) (tachyon-step (car el)))) + (--map (cons it (cdr el)) + (tachyon-step (car el)))) (setq tachyons (cons (car (advent/coordinates-of ?S data-char)) 1)) (defun compress (li) - (--map (cons it (-sum (-map #'cdr (-filter (lambda (x) (equal it (car x))) li)))) (-distinct (-map #'car li)))) - - (-sum (-map #'cdr (--fix (compress (-mapcat 'tachyon-step-freq it)) (list tachyons)))) + (--map (cons it (-sum (-map #'cdr + (-filter (lambda (x) + (equal it (car x))) + li)))) + (-distinct (-map #'car li)))) + (-sum (-map #'cdr + (--fix (compress (-mapcat 'tachyon-step-freq it)) + (list tachyons)))) #+end_src #+RESULTS: : 1537373473728 +