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

19 lines
501 B
Racket
Raw Normal View History

2024-04-16 19:13:00 -04:00
#! /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)