|
| ||
|
|
Start of topic | Skip to actions
How to do your homework
;; COMP 210 HW #01 ;; Christopher Warrington <chrisw@rice.edu> ;; Gregory Malecha <gmalecha@rice.edu>Submitting your homework For submission instructions, please see the SVN Turnin tutorial. Basic form of a function definition: (Chapter 2 onwards)
;; area-of-ring : positive-real-number positive-real-number -> positive-real-number
;; to compute the area of a ring whose radius is
;; outer and whose hole has a radius of inner
;;
;; Examples:
;; (area-of-ring 5 3) => 50.24
;; (area-of-ring 5 0) => 78.5
;;
(define (area-of-ring outer inner)
(- (area-of-disk outer)
(area-of-disk inner)))
"Testing area-of-ring:" ;; This line helps your grader
(equal? (area-of-ring 5 3) 50.24)
(equal? (area-of-ring 5 0) 78.5)
... ;; Provide enough examples and tests to show you tested thoroughly
;; A shape is either
;; * a triangle (make-triangle b h),
;; where b and h are positive-reals
;; * a square (make-square s),
;; where s is a positive-real.
(define-struct triangle (base height))
(define-struct square (side))
;;
;; Examples:
;; (make-triangle 1 2)
;; (make-triangle 2 5)
;; (make-square 4)
;; (make-square 2.5)
;;
;; Template:
#|
;; shape-function : shape -> ...
(define (shape-function ... shape ...)
(cond [(triangle? shape) ... (triangle-base shape) ...
... (triangle-height shape) ...]
[(square? shape) ... (square-side shape) ...]))
|#
;; A list-of-numbers is either
;; empty, or
;; (cons n lon)
;; where n is a number, and lon is a list-of-numbers
;;
;; Examples:
;; empty
;; (cons 1 empty)
;; (cons 1 (cons 4 empty))
;;
;; Template:
#|
;; f : list-of-numbers -> ...
(define (f a-lon)
(cond
[(empty? a-lon) ...]
[(cons? a-lon) ... (first a-lon) ...
... (f (rest a-lon)) ... ]))
|#
;; quick-sort [real] -> [real]
;; Sorts the given list in ascending order.
;;
;; Examples:
;; (quick-sort empty) => empty
;; (quick-sort '(1)) => '(1)
;; (quick-sort '(1 4 3 5)) => '(1 3 4 5)
;; (quick-sort '(1 4 3 4 2 5)) => '(1 2 3 4 4 5)
;;
;; Termination:
;; At each step, quick-sort partitions the list into three
;; sublists using smaller-than, larger-than, and equal-to.
;; The lists produced by smaller-than and larger-than are
;; sorted using recursive applications. Since the lists
;; produced by smaller-than and larger-than are strictly
;; shorter than the given list, eventually quick-sort
;; receives and returns the empty list.
(define (quick-sort alon)
(cond
[(empty? alon) empty]
[else (append (quick-sort (smaller-items alon (first alon)))
(equal-to alon (first alon))
(quick-sort (larger-items alon (first alon))))]))
"Testing quick-sort:"
...
Access Permissions
Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r57 < r56 < r55 < r54 < r53 | More topic actions
Webs: Main | TWiki | Africa | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: | |
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.