diff --git a/all-your-base/all-your-base.fasl b/all-your-base/all-your-base.fasl index f474b64..1f9dc5d 100644 Binary files a/all-your-base/all-your-base.fasl and b/all-your-base/all-your-base.fasl differ diff --git a/all-your-base/all-your-base.lisp b/all-your-base/all-your-base.lisp index 3a6b85d..bcf3d60 100644 --- a/all-your-base/all-your-base.lisp +++ b/all-your-base/all-your-base.lisp @@ -4,13 +4,10 @@ (in-package :all-your-base) -; `rebase` needs to return NIL sometimes. For the cases where one bad list -; item yields NIL, we need `conv` to return multiple values: (ok, val). -; Then we can check the ok before proceeding to `unconv`.` (defun conv (l base) - (if (null l) - 0 - (+ (* (first l) (expt base (- (length l) 1))) (conv (rest l) base)))) + (if (null l) + 0 + (+ (* (first l) (expt base (- (length l) 1))) (conv (rest l) base)))) (defun calc-start-exponent (num base x) (if (< num (expt base (1+ x))) @@ -29,4 +26,8 @@ (append (list q) (unconv r base (- x 1))))))) (defun rebase (l source destination) - (unconv (conv l source) destination -1)) + (cond ((< source 2) nil) + ((< destination 2) nil) + ((some #'(lambda (x) (< x 0)) l) nil) + ((some #'(lambda (x) (>= x source)) l) nil) + (t (unconv (conv l source) destination -1))))