Committing before refactor

Committing before refactoring `conv` to return multiple values. I guess
I lied about the pause.
This commit is contained in:
Adam Cooper 2025-01-27 10:33:48 -05:00
parent c0fcf47126
commit 348a973e26
2 changed files with 8 additions and 11 deletions

Binary file not shown.

View file

@ -4,14 +4,13 @@
(in-package :all-your-base)
;- 2025-01-25 Working on all-your-base exercise
; - nvlime plugin is no longer generating `\cc` keymap to connect to server
; - generally lots of problems loading the files
; - the unconv function : I'm handling the division and remainder stuff wrong (easy to work out in online compiler).
; `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)))
@ -25,11 +24,9 @@
exponent)))
(if (eq x 0)
(list num)
; something is not working here; getting fractional values for r
(multiple-value-bind (q r)
(truncate (/ num (expt base x)))
(truncate num (expt base x))
(append (list q) (unconv r base (- x 1)))))))
(defun rebase (l source destination)
(print (list l source destination))
(unconv (conv l source) destination -1))
(unconv (conv l source) destination -1))