[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

More on Fun Programs



Now that you've seen the instructional version of the second puzzle
function, here's the slightly bummed (15% faster) version:

(defun f (i)
 (labels ((g (i)
           (cond ((zerop i) (values 1 0))
		 ((= i 1) (values 1 1))
		 ((evenp i)
		  (multiple-value-bind (n n-1)
                   (g (/ i 2))
		   (values (+ (* n n) (* n-1 n-1))
			   (+ (* n n-1) (* n-1 (- n n-1))))))
		 (t
		  (multiple-value-bind (n n-1)
		   (g (- i 1))
		   (values (+ n n-1) n))))))
	 (values (g i))))

			-rpg-