diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-12-14 18:11:11 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-12-14 18:11:11 +0100 |
commit | fd38e2a07fc97be1d719e46a10b6774b5de53691 (patch) | |
tree | f1f6ff9d5a6860c1d7a3d2aacd6850e198c01257 /2024 | |
parent | d2f7f38ab66c7a112f6cabd0be3db27ff4acb78c (diff) |
Switch from ‘cond’ to ‘case’
Diffstat (limited to '2024')
-rw-r--r-- | 2024/12/puzzles.lisp | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/2024/12/puzzles.lisp b/2024/12/puzzles.lisp index a07575e..9584ea3 100644 --- a/2024/12/puzzles.lisp +++ b/2024/12/puzzles.lisp @@ -62,44 +62,41 @@ ;; figure out which 2 diagonal-neighbors would turn our ‘T’ shape into ;; a rectangle, and use them to determine how many corners we have. (let ((n (length neighbors))) - (cond - ((= n 0) 4) - ((= n 1) 2) - ((= n 2) - (let* ((l (first neighbors)) - (r (second neighbors)) - (li (car l)) (ri (car r)) - (lj (cdr l)) (rj (cdr r))) - (cond - ((or (= li ri i) (= lj rj j)) 0) - ((char= char (try-aref - (if (= li i) ri li) - (if (= lj j) rj lj))) - 1) - (:else 2)))) - ((= n 3) - (let ((wart (loop for n in neighbors - if (/= (car n) i) - collect n into odd-one-out-i - else - collect n into odd-one-out-j - finally (return - (first (if (= 1 (length odd-one-out-i)) - odd-one-out-i - odd-one-out-j)))))) - (loop for n in neighbors - count (not (or (equal n wart) - (char= char (try-aref - (if (= (car n) i) - (car wart) - (car n)) - (if (= (cdr n) j) - (cdr wart) - (cdr n))))))))) - ((= n 4) - (loop for (i . j) in (list (cons (1- i) (1- j)) (cons (1- i) (1+ j)) - (cons (1+ i) (1- j)) (cons (1+ i) (1+ j))) - count (char/= (try-aref i j) char)))))) + (case n + (0 4) + (1 2) + (2 (let* ((l (first neighbors)) + (r (second neighbors)) + (li (car l)) (ri (car r)) + (lj (cdr l)) (rj (cdr r))) + (cond + ((or (= li ri i) (= lj rj j)) 0) + ((char= char (try-aref + (if (= li i) ri li) + (if (= lj j) rj lj))) + 1) + (:else 2)))) + (3 (let ((wart (loop for n in neighbors + if (/= (car n) i) + collect n into odd-one-out-i + else + collect n into odd-one-out-j + finally (return + (first (if (= 1 (length odd-one-out-i)) + odd-one-out-i + odd-one-out-j)))))) + (loop for n in neighbors + count (not (or (equal n wart) + (char= char (try-aref + (if (= (car n) i) + (car wart) + (car n)) + (if (= (cdr n) j) + (cdr wart) + (cdr n))))))))) + (4 (loop for (i . j) in (list (cons (1- i) (1- j)) (cons (1- i) (1+ j)) + (cons (1+ i) (1- j)) (cons (1+ i) (1+ j))) + count (char/= (try-aref i j) char)))))) ;; END PART 2 (defun try-aref (i j) |