diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-16 18:06:07 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-16 18:06:07 +0100 |
commit | da3f2069e60f73fc6c6399537d8fb4b50cbf223c (patch) | |
tree | 1fcd21caaa44a3bcccd35395f8a46567f9af07e6 /AoC2022/14 | |
parent | 7a413a0920e9666b55432006bda4e98d5b586ef7 (diff) | |
download | scratch-da3f2069e60f73fc6c6399537d8fb4b50cbf223c.tar.gz scratch-da3f2069e60f73fc6c6399537d8fb4b50cbf223c.tar.bz2 scratch-da3f2069e60f73fc6c6399537d8fb4b50cbf223c.zip |
cleanup remove stride
Diffstat (limited to 'AoC2022/14')
-rw-r--r-- | AoC2022/14/solver.el | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/AoC2022/14/solver.el b/AoC2022/14/solver.el index c051f98..2b944b4 100644 --- a/AoC2022/14/solver.el +++ b/AoC2022/14/solver.el @@ -37,35 +37,29 @@ bounds x-len y-len - stride grid) +(defun solver-grid-create (bounds x-len y-len) + (solver-grid--create :bounds bounds :x-len x-len :y-len y-len + :grid (make-vector (* x-len y-len) 0))) (defun solver-abyss-grid (bounds) - (let* ((x-len (1+ (- (car bounds) (cadr bounds)))) - (y-len (1+ (elt bounds 2))) - (stride (* 8 (if (= 0 (mod x-len 8)) - (/ x-len 8) - (1+ (/ x-len 8))))) - (grid (make-vector (* stride y-len) 0))) - (solver-grid--create :bounds bounds :x-len x-len :y-len y-len :stride stride :grid grid))) + (let ((x-len (1+ (- (car bounds) (cadr bounds)))) + (y-len (1+ (elt bounds 2)))) + (solver-grid-create bounds x-len y-len))) (defun solver-finite-grid (bounds) (let* ((y-len (+ 3 (elt bounds 2))) - (x-len (* 2 y-len)) - (stride (* 8 (if (= 0 (mod x-len 8)) - (/ x-len 8) - (1+ (/ x-len 8))))) - (grid (make-vector (* stride y-len) 0))) + (x-len (* 2 y-len))) (setcar bounds (+ 500 y-len)) (setf (elt bounds 1) (- 500 y-len)) - (solver-grid--create :bounds bounds :x-len x-len :y-len y-len :stride stride :grid grid))) + (solver-grid-create bounds x-len y-len))) (defun solver-point (x y grid) (let ((x (- x (cadr (grid-bounds grid))))) (when (and (< -1 x (grid-x-len grid)) (< -1 y (grid-y-len grid))) - (+ x (* y (grid-stride grid)))))) + (+ x (* y (grid-x-len grid)))))) (defun solver--wall-line (grid) (let (startx starty) @@ -91,25 +85,13 @@ (solver--wall-line grid) (forward-line))) (when finite-grid - (cl-loop with yrow = (* (grid-stride grid) (1- (grid-y-len grid))) + (cl-loop with yrow = (* (grid-x-len grid) (1- (grid-y-len grid))) for x from 0 below (grid-x-len grid) do (aset (grid-grid grid) (+ x yrow) 1))) grid) -(defun solver-draw-wall (grid) - (let ((array (copy-sequence (grid-grid grid))) - (stride (grid-stride grid))) - (create-image array - 'xbm t - :scale 20 - :stride stride - :width (grid-x-len grid) - :height (grid-y-len grid) - :foreground "#ffffff" - :background "#000000"))) - (defun solver-draw-grid (grid) - (let ((stride (grid-stride grid))) + (let ((stride (grid-x-len grid))) (seq-do-indexed (lambda (elt idx) (let ((slot (mod idx stride))) @@ -153,4 +135,3 @@ (should (= 93 (solver "498,4 -> 498,6 -> 496,6 503,4 -> 502,4 -> 502,9 -> 494,9" #'solver-finite-grid))) (should (= 25434 (solver (find-file-noselect "input") #'solver-finite-grid)))) - |