solutions/Structure and Interpretatio.../sicp-ex-1.16.rkt

19 lines
501 B
Racket
Executable File

#! /usr/bin/racket
#lang racket/base
(define (sqr n)
(* n n))
(define (fast-ext-iter number power product)
(cond ((= power 0) product)
((even? power) (fast-ext-iter (sqr number)
(/ power 2)
product))
(else (fast-ext-iter number
(- power 1)
(* number product)))))
(define (fast-ext number power)
(fast-ext-iter number power 1))
(fast-ext 2 5)