Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-advanced-reader.ss" "lang")((modname |29.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;norm : vector -> number
5 12687dd9 2023-08-04 jrmu ;Produces the square root of the sum of the numbers in avector.
6 12687dd9 2023-08-04 jrmu
7 12687dd9 2023-08-04 jrmu (define (norm avector)
8 12687dd9 2023-08-04 jrmu (sqrt (sum-of-squares avector 0)))
9 12687dd9 2023-08-04 jrmu
10 12687dd9 2023-08-04 jrmu ;sum-of-squares : vector N -> number
11 12687dd9 2023-08-04 jrmu ;Given avector and i, square the element in avector from [i,vector-length) and then sum them
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu (define (sum-of-squares avector i)
14 12687dd9 2023-08-04 jrmu (cond
15 12687dd9 2023-08-04 jrmu [(= (vector-length avector) i) 0]
16 12687dd9 2023-08-04 jrmu [else (+ (sqr (vector-ref avector i))
17 12687dd9 2023-08-04 jrmu (sum-of-squares avector (add1 i)))]))
18 12687dd9 2023-08-04 jrmu
19 12687dd9 2023-08-04 jrmu ;vector-contains-doll? : (vectorof symbols) -> boolean
20 12687dd9 2023-08-04 jrmu ;Given avector, determine if it contains 'doll.
21 12687dd9 2023-08-04 jrmu
22 12687dd9 2023-08-04 jrmu (define (vector-contains-doll? avector)
23 12687dd9 2023-08-04 jrmu (vector-contains-doll?-aux avector 0))
24 12687dd9 2023-08-04 jrmu
25 12687dd9 2023-08-04 jrmu ;vector-contains-doll?-aux : (vectorof symbols) N -> boolean
26 12687dd9 2023-08-04 jrmu ;Given avector and i, determine if avector contains 'doll.
27 12687dd9 2023-08-04 jrmu
28 12687dd9 2023-08-04 jrmu (define (vector-contains-doll?-aux avector i)
29 12687dd9 2023-08-04 jrmu (cond
30 12687dd9 2023-08-04 jrmu [(= (vector-length avector) i) false]
31 12687dd9 2023-08-04 jrmu [else (or (symbol=? (vector-ref avector i) 'doll)
32 12687dd9 2023-08-04 jrmu (vector-contains-doll?-aux avector (add1 i)))]))
33 12687dd9 2023-08-04 jrmu (define vector2 (vector 'robot
34 12687dd9 2023-08-04 jrmu 'car
35 12687dd9 2023-08-04 jrmu 'eraser
36 12687dd9 2023-08-04 jrmu 'pen
37 12687dd9 2023-08-04 jrmu 'motorcycle
38 12687dd9 2023-08-04 jrmu 'bicycle
39 12687dd9 2023-08-04 jrmu 'helmet
40 12687dd9 2023-08-04 jrmu 'monitor
41 12687dd9 2023-08-04 jrmu 'dolly
42 12687dd9 2023-08-04 jrmu 'policeman
43 12687dd9 2023-08-04 jrmu 'diamond))
44 12687dd9 2023-08-04 jrmu (vector-contains-doll? vector2)