e41337e3b59b
Accessors
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Wed, 15 Dec 2021 23:10:57 -0500 |
parents | 428c6288f9e9 |
children | 3895878bfe72 |
branches/tags | (none) |
files | src/2021/days/day-15.lisp |
Changes
--- a/src/2021/days/day-15.lisp Wed Dec 15 22:58:47 2021 -0500 +++ b/src/2021/days/day-15.lisp Wed Dec 15 23:10:57 2021 -0500 @@ -2,23 +2,24 @@ (in-package :advent/2021/15) -(defun-inline coord (row col) - (cons row col)) +(defun-inline coord (row col) (cons row col)) +(defun-inline row (coord) (car coord)) +(defun-inline col (coord) (cdr coord)) (defun-inline coord= (a b) - (and (= (car a) (car b)) - (= (cdr a) (cdr b)))) + (and (= (row a) (row b)) + (= (col a) (col b)))) (defun-inline cref (array coord) - (aref array (car coord) (cdr coord))) + (aref array (row coord) (col coord))) (defun-inline (setf cref) (value array coord) - (setf (aref array (car coord) (cdr coord)) value)) + (setf (aref array (row coord) (col coord)) value)) (defun-inline neighbors (array coord) (loop :for δ in '((-1 . 0) (1 . 0) (0 . -1) (0 . 1)) - :for r = (+ (car coord) (car δ)) - :for c = (+ (cdr coord) (cdr δ)) + :for r = (+ (row coord) (row δ)) + :for c = (+ (col coord) (col δ)) :when (array-in-bounds-p array r c) :collect (coord r c)))