Added my solutions so far

This commit is contained in:
Emin Arslan
2025-01-02 17:49:30 +03:00
commit 442238a0d5
12 changed files with 716 additions and 0 deletions

17
ex-1-17.rkt Normal file
View File

@ -0,0 +1,17 @@
#lang racket
;; we are told to assume these are already defined.
(define (double x)
(+ x x))
(define (halve x)
(/ x 2))
;; multiplication. defined in terms of addition, double and halve.
;; logarithmic time, constant space.
(define (mult x y)
(define (recc x y a)
(cond
((= y 0) a)
((even? y) (recc (double x) (halve y) a))
(else (recc x (- y 1) (+ a x)))))
(recc x y 0))