Skip to content
This repository
tree: 8b4fd0cdb8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 16 lines (12 sloc) 0.333 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#lang racket
(define (x a b)
  (x-iter a b 0))

(define (x-iter a b product)
  (cond ((= b 0) product)
        ((even? b) (x-iter (double a) (halve b) product))
        ((odd? b) (x-iter (double a) (halve (- b 1)) (+ a product)))))

(define (double x)
  (+ x x))

(define (halve x)
  (/ x 2))

;this solves 1.18 as well, accidentally
Something went wrong with that request. Please try again.