Given the following problem:
;3.3 Tabulate the function k = 2^n for n = 1..50.
;Do this for the fewest possible multiplications.[3]
I wrote this answer:
(defun k (n) (ash 2 (1- n)))
(loop for n from 1 to 50 do
(format t "k(~a) = ~a ~%" n (k n)))
What do you think?
EDIT: based on feedback received, (ash 2 (1- n)) has been simplified to (ash 1 n):
(defun k (n) (ash 1 n))
(loop for n from 1 to 50 do
(format t "k(~a) = ~a ~%" n (k n)))
ashdo? – Omnifarious Mar 22 '11 at 17:57