Trying out exercises from "Structure and Interpretation of Computer Programs" second edition
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
501 B

#! /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)