Created
October 30, 2012 07:45
-
-
Save aoeuidht/3978843 to your computer and use it in GitHub Desktop.
SICP Exercise 1.17 -- fast-times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Now suppose we include, together with addition, | |
; operations double, which doubles an integer, | |
; and halve, which divides an (even) integer by 2. | |
; Using these, design a multiplication procedure analogous to | |
; fast-expt that uses a logarithmic number of steps. | |
(defun fast_times (multiplicand multiplier) | |
(cond ((= multiplier 0) 0) | |
((even? multiplier) | |
(double (fast_times multiplicand (half multiplier)))) | |
(else | |
(+ multiplicand (fast_times multiplicand (- multiplier 1)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My solution: