From 31aa0839953395f5998c7ec4350760cfebae6506 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Tue, 24 Jan 2023 22:19:32 +0100 Subject: drop some repetition --- AoC2022/25/solver.lisp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'AoC2022/25/solver.lisp') diff --git a/AoC2022/25/solver.lisp b/AoC2022/25/solver.lisp index 630cd03..9b94956 100644 --- a/AoC2022/25/solver.lisp +++ b/AoC2022/25/solver.lisp @@ -1,20 +1,17 @@ (ql:quickload '(fiveam uiop)) +(defconstant +num-encoding+ + '((2 . #\2) + (1 . #\1) + (0 . #\0) + (-1 . #\-) + (-2 . #\=))) + (defun encode-char (c) - (ecase c - (2 #\2) - (1 #\1) - (0 #\0) - (-1 #\-) - (-2 #\=))) + (cdr (assoc c +num-encoding+))) (defun decode-char (c) - (ecase c - (#\2 2) - (#\1 1) - (#\0 0) - (#\- -1) - (#\= -2))) + (car (rassoc c +num-encoding+))) (defun parse-snafu (num) (loop for a across (reverse num) -- cgit v1.2.3