Tests pass
This commit is contained in:
parent
348a973e26
commit
60ca8969a8
2 changed files with 8 additions and 7 deletions
Binary file not shown.
|
@ -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))))
|
||||
|
|
Loading…
Add table
Reference in a new issue