Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.3.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp")))))
4 ;;Produces an intenger between n and m-1
6 ;; random-n-m : integer integer -> integer
7 ;; ...
8 ;; Assume: n < m
9 (define (random-n-m n m)
10 (+ (random (- m n)) n))
12 ;Data Definition
13 ;A natural-number is either
14 ;1. 0 or
15 ;2. (add1 n) where n is a natural-number.
16 ;
17 ;A list-of-numbers is either
18 ;1. an empty list or
19 ;2. (cons n lon) where n is a number and
20 ;lon is a list-of-numbers.
21 ;
22 ;tie-dyed : natural-number -> list-of-numbers
23 ;Consumes a natural-number n and produces a list
24 ;with that many randomly numbers between
25 ;20 and 120.
26 ;
27 ;Template
28 ;(define (tie-dyed n)
29 ; (cond
30 ; [(zero? n) ...]
31 ; [(>= n 1) ... (tie-dyed (sub1 n))]
32 ; [else (error 'tie-dyed "Not a natural number")]))
34 ;Examples
35 ;(tie-dyed 0)
36 ;empty
37 ;(tie-dyed 1)
38 ;(cons (random-n-m 20 121) empty)
39 ;(tie-dyed 2)
40 ;(cons (random-n-m 20 121)
41 ; (cons (random-n-m 20 121) empty))
43 (define (tie-dyed n)
44 (cond
45 [(zero? n) empty]
46 [(>= n 1) (cons (random-n-m 20 121) (tie-dyed (sub1 n)))]
47 [else (error 'tie-dyed "Not a natural number")]))
49 ;Contract, Purpose, Header
50 ;draw-circles : posn list-of-numbers -> boolean
51 ;Given p and a-list, draw-circles draws concentric circles centered at p
52 ;with radius given by the elements of a-list. Each circle is drawn
53 ;by calling draw-circle.
54 ;
55 ;Template
57 (define (draw-circles p a-list)
58 (cond
59 [(empty? a-list) true]
60 [(draw-circle p (first a-list) 'red) (draw-circles p (rest a-list))]
61 [else false]))
63 (start 200 200)
64 (draw-circles (make-posn 100 100) (tie-dyed 1000))