From da3f2069e60f73fc6c6399537d8fb4b50cbf223c Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Fri, 16 Dec 2022 18:06:07 +0100 Subject: cleanup remove stride --- AoC2022/14/solver.el | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) (limited to 'AoC2022/14/solver.el') 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)))) - -- cgit v1.2.3