commit - /dev/null
commit + 12687dd954a34abd5498445b00336f835656eeec
blob - /dev/null
blob + 7b992431b8d460ed7f72128a4fc340dc0b3a9045 (mode 644)
--- /dev/null
+++ #22.3.1#1#
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 76 0 1 #"\0"
+0 75 1 #"\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 11 #" Monospace\0"
+0 16 90 -1 90 -1 2 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 41
+#"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 24 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 24 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+24 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 19 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 19 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+19 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1
+ 0 424 0 17 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 66 29 1 #"\n"
+0 0 17 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 66 29 1 #"\n"
+0 0 24 3 7 #"#reader"
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 29 #"\"htdp-intermediate-reader.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"lang\""
+0 0 22 3 3 #")(("
+0 0 14 3 7 #"modname"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"|#22.3|"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"read-case-sensitive"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"teachpacks"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 9 #"\"draw.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 10 #"\"arrow.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 8 #"\"gui.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 3 #")))"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"htdp-settings"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"#("
+0 0 20 3 2 #"#t"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"constructor"
+0 0 66 3 1 #" "
+0 0 14 3 17 #"repeating-decimal"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#f"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"none"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#f"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 9 #"\"draw.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 10 #"\"arrow.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 8 #"\"gui.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 5 #")))))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"change-text"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"event"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"draw-message"
+0 0 66 3 1 #" "
+0 0 14 3 12 #"main-message"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"text-contents"
+0 0 66 3 1 #" "
+0 0 14 3 9 #"main-text"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"change-choice"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"event"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"choice-index"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"draw-message"
+0 0 66 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 66 3 1 #" "
+0 0 19 11 15 #"\"Please make a "
+0 0 19 3 10 #"selection\""
+0 0 22 3 2 #")]"
+0 0 74 29 1 #"\n"
+0 0 74 3 0 #""
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"choice-index"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"draw-message"
+0 0 66 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 66 3 1 #" "
+0 0 19 11 20 #"\"Let's shop another "
+0 0 19 3 5 #"time\""
+0 0 22 3 2 #")]"
+0 0 74 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"choice-index"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"2"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"draw-message"
+0 0 66 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 66 3 1 #" "
+0 0 19 11 17 #"\"There's nothing "
+0 0 19 3 18 #"interesting on TV\""
+0 0 22 3 2 #")]"
+0 0 74 29 1 #"\n"
+0 0 74 3 0 #""
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"choice-index"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"3"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"draw-message"
+0 0 66 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 66 3 1 #" "
+0 0 19 11 13 #"\"Sure, we're "
+0 0 19 3 23 #"programming right now!\""
+0 0 22 3 2 #")]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"choice-index"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"4"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"draw-message"
+0 0 66 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 66 3 1 #" "
+0 0 19 3 19 #"\"Maybe in 2 hours!\""
+0 0 22 3 4 #")]))"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 17 #"close-main-window"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"event"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"hide-window"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-window"
+0 0 22 3 2 #"))"
+0 0 74 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 12 #"main-message"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"make-message"
+0 0 66 3 1 #" "
+0 0 19 3 27 #"\"Hi, nice to meet you too!\""
+0 0 22 3 2 #"))"
+0 0 74 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 74 3 1 #" "
+0 0 14 3 5 #"query"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"make-message"
+0 0 74 3 1 #" "
+0 0 19 3 1 #"\""
+0 0 19 3 4 #"What"
+0 0 19 3 1 #" "
+0 0 19 3 5 #"would"
+0 0 19 3 1 #" "
+0 0 19 3 22 #"you like to do today?\""
+0 0 22 3 2 #"))"
+0 0 74 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 74 3 1 #" "
+0 0 14 3 9 #"main-text"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-text"
+0 0 74 3 1 #" "
+0 0 19 3 11 #"\"Hi Aaron!\""
+0 0 22 3 2 #"))"
+0 0 74 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 74 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"make-message"
+0 0 74 3 1 #" "
+0 0 19 3 2 #"\"\""
+0 0 22 3 2 #"))"
+0 0 74 29 1 #"\n"
+0 0 74 3 0 #""
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 74 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-choice"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 74 3 1 #" "
+0 0 19 3 18 #"\"Make a selection\""
+0 0 74 29 1 #"\n"
+0 0 74 3 39 #" "
+0 0 19 3 13 #"\"Go Shopping\""
+0 0 74 29 1 #"\n"
+0 0 74 3 39 #" "
+0 0 19 3 10 #"\"Watch TV\""
+0 0 74 29 1 #"\n"
+0 0 74 3 39 #" "
+0 0 19 3 16 #"\"Program Scheme\""
+0 0 74 29 1 #"\n"
+0 0 74 3 39 #" "
+0 0 19 3 7 #"\"Sleep\""
+0 0 22 3 3 #")))"
+0 0 74 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"main-window"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"create-window"
+0 0 74 29 1 #"\n"
+0 0 66 3 3 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-button"
+0 0 66 3 1 #" "
+0 0 19 3 14 #"\"Close Window\""
+0 0 66 3 1 #" "
+0 0 14 3 17 #"close-main-window"
+0 0 22 3 2 #"))"
+0 0 74 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 74 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-button"
+0 0 74 3 1 #" "
+0 0 19 3 13 #"\"Change Text\""
+0 0 74 3 1 #" "
+0 0 14 3 11 #"change-text"
+0 0 22 3 1 #")"
+0 0 74 29 1 #"\n"
+0 0 66 3 15 #" "
+0 0 14 3 9 #"main-text"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 66 3 1 #" "
+0 0 14 3 12 #"main-message"
+0 0 22 3 1 #")"
+0 0 74 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 74 3 1 #" "
+0 0 14 3 5 #"query"
+0 0 22 3 1 #")"
+0 0 74 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 74 3 1 #" "
+0 0 14 3 11 #"main-choice"
+0 0 74 29 1 #"\n"
+0 0 66 3 15 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-button"
+0 0 74 3 1 #" "
+0 0 19 3 5 #"\"Go!\""
+0 0 70 3 1 #" "
+0 0 14 3 13 #"change-choice"
+0 0 22 3 2 #"))"
+0 0 70 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 70 3 1 #" "
+0 0 14 3 19 #"main-choice-message"
+0 0 22 3 4 #"))))"
+0 0 70 29 1 #"\n"
+0 0 70 3 0 #""
+0 0 66 3 2 #" "
+0 0 70 29 1 #"\n"
+0 0 70 3 0 #""
+0 0 66 3 2 #" "
+0 0
blob - /dev/null
blob + 77d3becd988f1f23737c1b4e9c60fedc4988d1e4 (mode 644)
--- /dev/null
+++ #27.3.5#1#
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 80 0 1 #"\0"
+0 75 1 #"\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 11 #" Monospace\0"
+0 16 90 -1 90 -1 2 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 41
+#"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 255 255 0 -1 -1 19
+1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 24 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 19 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 24 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 19 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+24 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+0 1 #"\0"
+0 75 11 #" Monospace\0"
+0.0 16 90 -1 90 -1 2 -1 0 1 0 1 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255
+255 255 1 -1 17 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1
+ 0 823 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 393
+(
+ #"#reader(lib \"htdp-intermediate-lambda-reader.ss\" \"lang\")((modnam"
+ #"e |#27.3|) (read-case-sensitive #t) (teachpacks ((lib \"draw.ss\" \""
+ #"teachpack\" \"htdp\") (lib \"arrow.ss\" \"teachpack\" \"htdp\") (lib"
+ #" \"gui.ss\" \"teachpack\" \"htdp\"))) (htdp-settings #(#t constructo"
+ #"r repeating-decimal #f #t none #f ((lib \"draw.ss\" \"teachpack\" \""
+ #"htdp\") (lib \"arrow.ss\" \"teachpack\" \"htdp\") (lib \"gui.ss\" \""
+ #"teachpack\" \"htdp\")))))"
+) 0 0 4 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 1 #"A"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"table"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"is"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"function"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"that"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"consumes"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"only"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"natural"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"numbers"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"between"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 9 #"inclusive"
+0 0 17 3 1 #")"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"VL"
+0 0 17 11 1 #" "
+0 0 17 3 33 #"(exclusive) and returns a number."
+0 0 64 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 64 29 1 #"\n"
+0 0 17 3 32 #";Formally, a table is a function"
+0 0 64 29 1 #"\n"
+0 0 17 3 37 #";g : N[>=0 and <= (- VL 1)] -> number"
+0 0 64 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 64 29 1 #"\n"
+0 0 17 3 72
+(
+ #";The root of a table is the value x such that (g x) is the closest t"
+ #"o 0."
+) 0 0 64 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 64 29 1 #"\n"
+0 0 17 3 40 #";find-root-linear : (N -> number) N -> N"
+0 0 64 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 5 #"Given"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"a-table"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 5 #"table"
+0 0 17 3 2 #") "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"index"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"i"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 4 #"find"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"root"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"table."
+0 0 17 3 2 #" "
+0 0 17 3 16 #"find-root-linear"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"finds"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 11 1 #" "
+0 0 17 3 48 #"root using structural induction (linear search)."
+0 0 64 29 1 #"\n"
+0 0 64 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 16 #"find-root-linear"
+0 0 64 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"i"
+0 0 22 3 1 #")"
+0 0 64 29 1 #"\n"
+0 0 64 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 64 29 1 #"\n"
+0 0 64 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 5 #"zero?"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"i"
+0 0 22 3 1 #")"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"i"
+0 0 22 3 1 #"]"
+0 0 64 29 1 #"\n"
+0 0 64 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 64 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 64 3 1 #" "
+0 0 14 3 9 #"a-table-i"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"i"
+0 0 22 3 2 #"))"
+0 0 64 29 1 #"\n"
+0 0 64 3 18 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 64 3 1 #" "
+0 0 14 3 12 #"root-of-rest"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 16 #"find-root-linear"
+0 0 64 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sub1"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"i"
+0 0 22 3 4 #"))))"
+0 0 64 29 1 #"\n"
+0 0 64 3 12 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 64 29 1 #"\n"
+0 0 64 3 14 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 2 #"<="
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 64 3 1 #" "
+0 0 14 3 9 #"a-table-i"
+0 0 22 3 1 #")"
+0 0 64 29 1 #"\n"
+0 0 64 3 19 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 64 3 1 #" "
+0 0 14 3 12 #"root-of-rest"
+0 0 22 3 3 #")))"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"i"
+0 0 22 3 1 #"]"
+0 0 64 29 1 #"\n"
+0 0 64 3 14 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 64 3 1 #" "
+0 0 14 3 12 #"root-of-rest"
+0 0 22 3 6 #"]))]))"
+0 0 64 29 1 #"\n"
+0 0 64 3 0 #""
+0 0 64 29 1 #"\n"
+0 0 64 3 0 #""
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"t"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 1 #")"
+0 0 64 29 1 #"\n"
+0 0 64 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 64 3 1 #" "
+0 0 20 3 1 #"3"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"sin"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 2 #"))"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 64 3 1 #" "
+0 0 20 3 1 #"5"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 2 #"))"
+0 0 64 29 1 #"\n"
+0 0 64 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 64 3 1 #" "
+0 0 20 3 2 #"-1"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sqrt"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 2 #"))"
+0 0 64 29 1 #"\n"
+0 0 64 3 5 #" "
+0 0 20 3 1 #"3"
+0 0 22 3 2 #"))"
+0 0 64 29 1 #"\n"
+0 0 64 29 1 #"\n"
+0 0 17 3 19 #";find-root-discrete"
+0 0 17 3 25 #" : (N -> number) N N -> N"
+0 0 64 29 1 #"\n"
+0 0 17 3 6 #";Given"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"a-table"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 4 #"left"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"right"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 4 #"find"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"root"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"table"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"using"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"binary"
+0 0 17 3 7 #" search"
+0 0 17 3 1 #" "
+0 0 17 3 10 #"generative"
+0 0 17 11 1 #" "
+0 0 17 3 83
+(
+ #"recursion. If there are multiple roots, only the root closest to ze"
+ #"ro is returned."
+) 0 0 64 29 1 #"\n"
+0 0 17 3 12 #";Termination"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"Argument:"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"The"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"interval"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 18 #"find-root-discrete"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"decreases"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"by"
+0 0 17 3 5 #" half"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"each"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"time"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"until"
+0 0 17 11 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"interval"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"size"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"is"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"only"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"1."
+0 0 17 3 2 #" "
+0 0 17 3 4 #"Once"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"this"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"occurs"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 18 #"find-root-discrete"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"either"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"returns"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"left"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"or"
+0 0 17 11 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 67
+#"right index as the root. Hence, find-root-discrete must terminate."
+0 0 64 29 1 #"\n"
+0 0 17 3 17 #";midpoint : Given"
+0 0 17 3 71
+(
+ #" left and right, determine the midpoint rounded to the nearest integ"
+ #"er."
+) 0 0 64 29 1 #"\n"
+0 0 17 3 44 #";No assumption about a-table being monotonic"
+0 0 64 29 1 #"\n"
+0 0 64 29 1 #"\n"
+0 0 63 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"find-root-discrete2"
+0 0 63 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 1 #")"
+0 0 63 29 1 #"\n"
+0 0 63 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 63 29 1 #"\n"
+0 0 63 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"-"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #")"
+0 0 63 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 1 #")"
+0 0 63 3 1 #" "
+0 0 64 3 1 #" "
+0 0 63 29 1 #"\n"
+0 0 63 3 5 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 63 29 1 #"\n"
+0 0 63 3 7 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 2 #"<="
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 2 #"))"
+0 0 63 29 1 #"\n"
+0 0 63 3 12 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 3 #")))"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #"]"
+0 0 63 29 1 #"\n"
+0 0 63 3 7 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 3 #"])]"
+0 0 63 29 1 #"\n"
+0 0 63 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 63 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 63 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 63 29 1 #"\n"
+0 0 63 3 20 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"round"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 63 29 1 #"\n"
+0 0 63 3 30 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"/"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"-"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #")"
+0 0 63 3 1 #" "
+0 0 20 3 1 #"2"
+0 0 22 3 4 #"))))"
+0 0 63 29 1 #"\n"
+0 0 63 3 18 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 63 3 1 #" "
+0 0 14 3 14 #"left-side-root"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 18 #"find-root-discrete"
+0 0 63 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 63 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 22 3 2 #"))"
+0 0 63 29 1 #"\n"
+0 0 63 3 18 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 63 3 1 #" "
+0 0 14 3 15 #"right-side-root"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 18 #"find-root-discrete"
+0 0 63 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 3 #")))"
+0 0 63 29 1 #"\n"
+0 0 63 3 12 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 63 3 14 #" "
+0 0 63 29 1 #"\n"
+0 0 63 3 14 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 2 #"<="
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 14 #"left-side-root"
+0 0 22 3 2 #"))"
+0 0 63 29 1 #"\n"
+0 0 63 3 19 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 63 3 1 #" "
+0 0 14 3 15 #"right-side-root"
+0 0 22 3 3 #")))"
+0 0 63 3 1 #" "
+0 0 14 3 14 #"left-side-root"
+0 0 22 3 1 #"]"
+0 0 63 29 1 #"\n"
+0 0 63 3 14 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 63 3 1 #" "
+0 0 14 3 15 #"right-side-root"
+0 0 22 3 6 #"]))]))"
+0 0 63 29 1 #"\n"
+0 0 63 29 1 #"\n"
+0 0 77 29 1 #"\n"
+0 0 77 29 1 #"\n"
+0 0 17 3 44 #";find-root-discrete : (N -> number) N N -> N"
+0 0 77 29 1 #"\n"
+0 0 17 3 6 #";Given"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"a-table"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 4 #"left"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"right"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 4 #"find"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"root "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"table"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"using"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"binary"
+0 0 17 3 7 #" search"
+0 0 17 3 1 #" "
+0 0 17 3 10 #"generative"
+0 0 17 11 1 #" "
+0 0 17 3 83
+(
+ #"recursion. If there are multiple roots, only the root closest to ze"
+ #"ro is returned."
+) 0 0 77 29 1 #"\n"
+0 0 17 3 12 #";Termination"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"Argument:"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"The"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"interval"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 18 #"find-root-discrete"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"decreases"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"by"
+0 0 17 3 5 #" half"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"each"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"time"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"until"
+0 0 17 11 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"interval"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"size"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"is"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"only"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"1."
+0 0 17 3 2 #" "
+0 0 17 3 4 #"Once"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"this"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"occurs"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 18 #"find-root-discrete"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"either"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"returns"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"left"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"or"
+0 0 17 11 1 #" "
+0 0 17 3 71
+(
+ #"the right index as the root. Hence, find-root-discrete must termina"
+ #"te."
+) 0 0 77 29 1 #"\n"
+0 0 17 3 88
+(
+ #";midpoint : Given left and right, determine the midpoint rounded to "
+ #"the nearest integer."
+) 0 0 77 29 1 #"\n"
+0 0 17 3 70
+(
+ #";ASSUMPTION : a-table is monotonic increasing or monotonic decreasin"
+ #"g."
+) 0 0 77 29 1 #"\n"
+0 0 77 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 18 #"find-root-discrete"
+0 0 77 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 77 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 1 #")"
+0 0 77 29 1 #"\n"
+0 0 77 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 77 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 77 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 77 29 1 #"\n"
+0 0 77 3 12 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"round"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 77 29 1 #"\n"
+0 0 77 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"/"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"-"
+0 0 77 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #")"
+0 0 77 3 1 #" "
+0 0 20 3 1 #"2"
+0 0 22 3 5 #")))))"
+0 0 77 29 1 #"\n"
+0 0 77 3 4 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 77 29 1 #"\n"
+0 0 77 3 6 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"-"
+0 0 77 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #")"
+0 0 77 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 1 #")"
+0 0 77 3 1 #" "
+0 0 77 29 1 #"\n"
+0 0 77 3 7 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 77 29 1 #"\n"
+0 0 77 3 9 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 2 #"<="
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 2 #"))"
+0 0 77 29 1 #"\n"
+0 0 77 3 14 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"abs"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 3 #")))"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #"]"
+0 0 77 29 1 #"\n"
+0 0 77 3 9 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 77 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 3 #"])]"
+0 0 77 29 1 #"\n"
+0 0 77 3 6 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 2 #"or"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 2 #"<="
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 1 #")"
+0 0 77 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 22 3 2 #"))"
+0 0 77 29 1 #"\n"
+0 0 77 3 11 #" "
+0 0 22 3 1 #"("
+0 0 14 3 2 #"<="
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 22 3 1 #")"
+0 0 77 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"a-table"
+0 0 77 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 22 3 3 #")))"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 18 #"find-root-discrete"
+0 0 64 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 64 3 1 #" "
+0 0 14 3 4 #"left"
+0 0 64 11 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 22 3 2 #")]"
+0 0 77 29 1 #"\n"
+0 0 77 3 6 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 77 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 18 #"find-root-discrete"
+0 0 64 3 1 #" "
+0 0 14 3 7 #"a-table"
+0 0 64 3 1 #" "
+0 0 14 3 8 #"midpoint"
+0 0 64 3 1 #" "
+0 0 14 3 5 #"right"
+0 0 22 3 5 #")])))"
+0 0 64 29 1 #"\n"
+0 0 64 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 4 #"time"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 16 #"find-root-linear"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"t"
+0 0 64 3 1 #" "
+0 0 20 3 5 #"30000"
+0 0 22 3 2 #"))"
+0 0 64 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 4 #"time"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"find-root-discrete2"
+0 0 63 3 1 #" "
+0 0 14 3 1 #"t"
+0 0 63 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 63 3 1 #" "
+0 0 20 3 5 #"30000"
+0 0 22 3 2 #"))"
+0 0 64 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 4 #"time"
+0 0 64 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 18 #"find-root-discrete"
+0 0 64 3 1 #" "
+0 0 14 3 1 #"t"
+0 0 64 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 64 3 1 #" "
+0 0 20 3 5 #"30000"
+0 0 22 3 2 #"))"
+0 0
blob - /dev/null
blob + 0e50021428632694a575798a4bc6ad8fc447c23b (mode 644)
--- /dev/null
+++ #30.1.1#1#
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 69 0 1 #"\0"
+0 75 1 #"\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 11 #" Monospace\0"
+0 16 90 -1 90 -1 2 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 41
+#"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1
+ 0 138 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 382
+(
+ #"#reader(lib \"htdp-advanced-reader.ss\" \"lang\")((modname |#30.1|) "
+ #"(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\") (li"
+ #"b \"arrow.ss\" \"teachpack\" \"htdp\") (lib \"gui.ss\" \"teachpack\""
+ #" \"htdp\")))))"
+) 0 0 4 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 19 #"relative-2-absolute"
+0 0 17 3 1 #" "
+0 0 17 3 1 #":"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 35 #"listof numbers) -> (listof numbers)"
+0 0 63 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 7 #"Convert"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"alon"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"into"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"absolute"
+0 0 17 3 1 #" "
+0 0 17 3 10 #"distances."
+0 0 17 3 2 #" "
+0 0 17 3 3 #"The"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"first"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"element"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"is"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 33 #"first alon) away from the origin."
+0 0 63 29 1 #"\n"
+0 0 63 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"relative-2-absolute"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 63 29 1 #"\n"
+0 0 63 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 63 29 1 #"\n"
+0 0 63 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 63 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 63 29 1 #"\n"
+0 0 63 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 63 29 1 #"\n"
+0 0 63 3 16 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"add-to-each"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"relative-2-absolute"
+0 0 63 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 63 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 7 #"))))]))"
+0 0 63 29 1 #"\n"
+0 0 63 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 62 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"add-to-each"
+0 0 62 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 62 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 63 29 1 #"\n"
+0 0 62 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"map"
+0 0 62 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 62 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"x"
+0 0 22 3 1 #")"
+0 0 62 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 62 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 62 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 2 #"))"
+0 0 62 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #"))"
+0 0 63 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 14 3 2 #"On"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"the"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"order"
+0 0 4 3 1 #" "
+0 0 14 3 2 #"of"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"N^2"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0
blob - /dev/null
blob + d22d95ccefce0b1d56334860ee130e1b287820dd (mode 644)
--- /dev/null
+++ #32.3.1 Test Suite#1#
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 72 0 1 #"\0"
+0 75 1 #"\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 11 #" Monospace\0"
+0 16 90 -1 90 -1 2 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 41
+#"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+ 0 3271 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 382
+(
+ #"#reader(lib \"htdp-advanced-reader.ss\" \"lang\")((modname |#32.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\") (li"
+ #"b \"arrow.ss\" \"teachpack\" \"htdp\") (lib \"gui.ss\" \"teachpack\""
+ #" \"htdp\")))))"
+) 0 0 4 29 1 #"\n"
+0 0 17 3 37 #";jump : board posn -> (listof boards)"
+0 0 4 29 1 #"\n"
+0 0 17 3 25 #";Given aboard and aposn, "
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 9 #"trueboard"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 24 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 32 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"falseboard"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"trueboard2"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"trueboard3"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"trueboard4"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 25 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 33 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 11 #"falseboard2"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 14 3 11 #"falseboard3"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 2 #"))"
+0 0 4 29 1 #"\n"
+0 0 4 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 34 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"vector"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 4 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 4 #"))))"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"3"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"5"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 2 #"))"
+0 0 4 3 1 #" "
+0 0 14 3 9 #"trueboard"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"not"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"3"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"5"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 3 #")))"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"falseboard"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"7"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"7"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 2 #"))"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"trueboard2"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 2 #"))"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"trueboard3"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"7"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 2 #"))"
+0 0 4 3 1 #" "
+0 0 14 3 10 #"trueboard4"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"not"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"7"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"7"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 3 #")))"
+0 0 4 3 1 #" "
+0 0 14 3 11 #"falseboard2"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 6 #"andmap"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"lambda"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"b"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 3 #"not"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"enabled?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"make-posn"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"7"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"b"
+0 0 22 3 3 #")))"
+0 0 4 3 1 #" "
+0 0 14 3 11 #"falseboard3"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0
blob - /dev/null
blob + b4f86c82d595a3321afcdfcecf9fb17d543fdd59 (mode 644)
--- /dev/null
+++ #33.2.1#2#
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 77 0 1 #"\0"
+0 75 1 #"\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 11 #" Monospace\0"
+0 16 90 -1 90 -1 2 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 41
+#"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+24 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+19 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 19 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 19 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 255 255 0 -1 -1
+ 0 159 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 382
+(
+ #"#reader(lib \"htdp-advanced-reader.ss\" \"lang\")((modname |#33.2|) "
+ #"(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\") (li"
+ #"b \"arrow.ss\" \"teachpack\" \"htdp\") (lib \"gui.ss\" \"teachpack\""
+ #" \"htdp\")))))"
+) 0 0 4 29 1 #"\n"
+0 0 17 3 12 #";overflow-n?"
+0 0 17 3 1 #" "
+0 0 17 3 1 #":"
+0 0 17 3 7 #" N -> N"
+0 0 68 29 1 #"\n"
+0 0 17 3 10 #";Searches "
+0 0 17 3 4 #"for "
+0 0 17 3 2 #"a "
+0 0 17 3 6 #"value "
+0 0 17 11 69
+(
+ #"from [n,+inf.0) such that the number returned is the largest natural"
+ #" "
+) 0 0 17 3 7 #"number "
+0 0 17 3 6 #"where "
+0 0 17 3 6 #"(expt "
+0 0 17 3 6 #"#i10. "
+0 0 17 3 51 #"n) is still an inexact number rather than infinity."
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"overflow-n?"
+0 0 68 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"<"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"expt"
+0 0 68 3 1 #" "
+0 0 20 3 5 #"#i10."
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 68 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 2 #"))"
+0 0 68 3 1 #" "
+0 0 20 3 6 #"+inf.0"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"overflow-n?"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"add1"
+0 0 68 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 3 #"))]"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 3 #"]))"
+0 0 68 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 11 #"overflow-n?"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 17 3 13 #";underflow-n?"
+0 0 17 3 1 #" "
+0 0 17 3 1 #":"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"integer"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"->"
+0 0 17 3 8 #" integer"
+0 0 4 29 1 #"\n"
+0 0 17 3 9 #";Searches"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"for"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"value"
+0 0 17 3 5 #" from"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 6 #"-inf.0"
+0 0 17 11 58
+#",n] such that the number returned is the smallest integer "
+0 0 17 3 72
+(
+ #"possible where (expt #i10. n) is still an inexact number rather than"
+ #" #i0"
+) 0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"underflow-n?"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 4 29 1 #"\n"
+0 0 4 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #">"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"expt"
+0 0 4 3 1 #" "
+0 0 20 3 5 #"#i10."
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"-"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 2 #"))"
+0 0 4 3 1 #" "
+0 0 20 3 3 #"#i0"
+0 0 22 3 1 #")"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"underflow-n?"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sub1"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 3 #"))]"
+0 0 4 29 1 #"\n"
+0 0 4 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 4 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 3 #"]))"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 12 #"underflow-n?"
+0 0 4 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 22 3 1 #")"
+0 0
blob - /dev/null
blob + 9b22d8d250231d62f33b40a66e12989f28150a7c (mode 644)
--- /dev/null
+++ 10.1.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 10.1.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(define PAYPERHOUR 12)
+
+Data Definition
+A list-of-numbers is either
+1. an empty list or
+2. (cons n lon) where n is a number and lon is a list-of-numbers.
+
+Contract, Purpose, Header
+wage : number -> number
+Computes the wage given hours.
+
+(define (wage hours)
+ (* PAYPERHOUR hours))
+
+Contract, Purpose, Header
+hours->wages : list-of-numbers -> list-of-numbers
+Computes the wages (list-of-numbers) from alon.
+
+Template
+
+(define (hours->wages alon)
+ (cond
+ [(empty?) ...]
+ [else ... (first alon) (rest alon) ...]))
\ No newline at end of file
blob - /dev/null
blob + a7b4c440b42e8cb029a4bda61e3c383ab8d2056b (mode 644)
--- /dev/null
+++ 10.1.1.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 10.1.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp") (lib "sound.ss" "installed-teachpacks"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp") (lib "sound.ss" "installed-teachpacks")))))
+(define PAYPERHOUR 14)
+;
+;Data Definition
+;A list-of-numbers is either
+;1. an empty list or
+;2. (cons n lon) where n is a number and lon is a list-of-numbers.
+;
+;Contract, Purpose, Header
+;wage : number -> number
+;Computes the wage given hours.
+
+(define (wage hours)
+ (* PAYPERHOUR hours))
+;
+;Contract, Purpose, Header
+;hours->wages : list-of-numbers -> list-of-numbers
+;Computes the wages (list-of-numbers) from alon.
+;
+;Template
+
+(define (hours->wages alon)
+ (cond
+ [(empty? alon) empty]
+ [(> (first alon) 100) (error 'hours->wages "too many hours")]
+ [else (cons (wage (first alon)) (hours->wages (rest alon)))]))
+
+(define list1 (cons 5 (cons 8 (cons 12 (cons 9 (cons 200 empty))))))
+
+;Contract, Purpose, Header
+;fahrenheit->celsius : number -> number
+
+(define (fahrenheit->celsius fahr)
+ (* 5/9 (- fahr 32)))
+
+;Contract, Purpose, Header
+;convertFC : list-of-numbers -> list-of-numbers
+;Converts alon (in Fahrenheit) to Celsius.
+
+(define (convertFC alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (fahrenheit->celsius (first alon)) (convertFC (rest alon)))]))
+
+;Contract, Purpose, Header
+;usd->euro : number -> number
+;Converts usd to euros.
+
+(define (usd->euro usd)
+ (* usd EXCHRATE))
+
+(define EXCHRATE 1.22)
+
+;Contract, Purpose, Header
+;convert-euro-1 : list-of-numbers -> list-of-numbers
+;Converts alon (a list-of-numbers in US dollars) to euros.
+
+(define (convert-euro-1 alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (usd->euro (first alon)) (convert-euro-1 (rest alon)))]))
+
+;Contract, Purpose, Header
+;eliminate-exp : list-of-numbers number -> list-of-numbers
+;Eliminates all toys within lotp that exceed the price of ua and returns
+;the remaining list.
+;
+;Template
+;
+;(define (eliminate-exp lotp ua)
+; (cond
+; [(empty? lotp) empty]
+; [(> (first lotp) ua) ... (first lotp) (eliminate-exp (rest lotp)) ...]
+; [else (first lotp) (eliminate-exp (rest lotp))...]))
+
+(define (eliminate-exp lotp ua)
+ (cond
+ [(empty? lotp) empty]
+ [(> (first lotp) ua) (eliminate-exp (rest lotp) ua)]
+ [(<= (first lotp) ua) (cons (first lotp) (eliminate-exp (rest lotp) ua))]))
+
+(define list2 (cons 4.5 (cons 4.6 (cons 4.7 (cons 4.9 (cons 5.2 (cons 3.8 (cons 2.9 (cons 3.4 (cons 6.1 empty))))))))))
+;
+;Data Definition
+;
+;A list-of-symbols is either
+;1. an empty list or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+;
+;Contract, Purpose, Header
+;substitute : symbol symbol list-of-symbols -> list-of-symbols
+;Replace old with new (numbers) in alos (list-of-symbols).
+;
+;Template
+(define (substitute new old alos)
+ (cond
+ [(empty? alos) empty]
+ [(symbol=? (first alos) old) (cons new (substitute new old (rest alos)))]
+ [else (cons (first alos) (substitute new old (rest alos)))]))
+;
+;Contract, Purpose, Header
+;recall : symbol list-of-symbols -> list-of-symbols
+;Removes ty from lon (list of names, data type: list-of-symbols).
+
+(define (recall ty lon)
+ (cond
+ [(empty? lon) empty]
+ [(symbol=? (first lon) ty) (recall ty (rest lon)) ]
+ [else (cons (first lon) (recall ty (rest lon)))]))
+
+(define list3 (cons 'firetruck (cons 'playstation (cons 'xbox (cons 'racecar (cons 'doll (cons 'bicycle empty)))))))
+
+;; how-many : number number number -> number
+;; Determines how many solutions a given quadratic equation has given
+;; coefficients a, b, and c.
+
+(define (how-many a b c)
+ (cond
+ [(= a 0) 'degenerate]
+ [(> (sqr b) (* 4 a c)) 2]
+ [(= (sqr b) (* 4 a c)) 1]
+ [(< (sqr b) (* 4 a c)) 0]))
+;
+;Contract, Purpose, Header
+;quadratic-roots : number number number -> Scheme-value
+;Given a, b, and c (numbers), it returns either a symbol ('none), a number (if there is one root to the eqn), or a list of 2 numbers by calling on two-roots (if there are two solutions).
+
+(define (quadratic-roots a b c)
+ (cond
+ [(= (how-many a b c) 0) 'none]
+ [(= (how-many a b c) 1) (/ b -2 a)]
+ [(= (how-many a b c) 2) (two-roots a b c)]))
+
+;two-roots : number number number -> list-of-numbers
+;Given a, b, and c, computes the two roots of the
+;quadratic equation and returns the 2 roots
+;as a list-of-numbers.
+
+(define (two-roots a b c)
+ (cons (/
+ (+ (* -1 b)
+ (sqrt (- (sqr b)
+ (* 4 a c))))
+ 2 a)
+ (cons (/
+ (- (* -1 b)
+ (sqrt (- (sqr b)
+ (* 4 a c))))
+ 2 a) empty)))
+;
+;Data Definition
+;A mixed-list is either
+;1. an empty list or
+;2. (cons mixed list) where mixed is either a symbol or a number
+; and list is a mixed-list.
+;
+;Contract, Purpose, Header
+;controller : number -> mixed-list
+;Controller takes in cents and returns a list with the following elements:
+;1. the dollar amount (number),
+;2. 'dollar or 'dollars,
+;3. 'and,
+;4. the cent amount (number),
+;5. 'cent or 'cents.
+;
+;Whether singular or plural is used for elements 2 and 5 is
+;determined using plural?.
+;
+;Template
+(define (controller cents)
+ (cons (quotient cents 100)
+ (cons (cond
+ [(plural? (quotient cents 100)) 'dollars]
+ [else 'dollar])
+ (cons 'and
+ (cons (remainder cents 100)
+ (cons (cond
+ [(plural? (remainder cents 100)) 'cents]
+ [else 'cent]) empty))))))
+
+;Contract, Purpose, Header
+;plural? : number -> boolean
+;Determines if a number needs to be considered plural
+;for grammar purposes.
+
+(define (plural? num)
+ (cond
+ [(= num 1) false]
+ [(not (= num 1)) true]))
\ No newline at end of file
blob - /dev/null
blob + ce9c4c8d1b2a1b9e72b1aec18c96fc007de0c7ef (mode 644)
--- /dev/null
+++ 10.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 10.2.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+(define PAYPERHOUR 14)
+;
+;Data Definition
+;A list-of-numbers is either
+;1. an empty list or
+;2. (cons n lon) where n is a number and lon is a list-of-numbers.
+;
+;Contract, Purpose, Header
+;wage : number -> number
+;Computes the wage given hours.
+
+(define (wage hours)
+ (* PAYPERHOUR hours))
+;
+;Contract, Purpose, Header
+;hours->wages : list-of-numbers -> list-of-numbers
+;Computes the wages (list-of-numbers) from alon.
+;
+;Template
+
+(define (hours->wages alon)
+ (cond
+ [(empty? alon) empty]
+ [(> (first alon) 100) (error 'hours->wages "too many hours")]
+ [else (cons (wage (first alon)) (hours->wages (rest alon)))]))
+
+(define list1 (cons 5 (cons 8 (cons 12 (cons 9 (cons 200 empty))))))
+
+;Contract, Purpose, Header
+;fahrenheit->celsius : number -> number
+
+(define (fahrenheit->celsius fahr)
+ (* 5/9 (- fahr 32)))
+
+;Contract, Purpose, Header
+;convertFC : list-of-numbers -> list-of-numbers
+;Converts alon (in Fahrenheit) to Celsius.
+
+(define (convertFC alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (fahrenheit->celsius (first alon)) (convertFC (rest alon)))]))
+
+;Contract, Purpose, Header
+;usd->euro : number -> number
+;Converts usd to euros.
+
+(define (usd->euro usd)
+ (* usd EXCHRATE))
+
+(define EXCHRATE 1.22)
+
+;Contract, Purpose, Header
+;convert-euro-1 : list-of-numbers -> list-of-numbers
+;Converts alon (a list-of-numbers in US dollars) to euros.
+
+(define (convert-euro-1 alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (usd->euro (first alon)) (convert-euro-1 (rest alon)))]))
+
+;Contract, Purpose, Header
+;eliminate-exp : list-of-numbers number -> list-of-numbers
+;Eliminates all toys within lotp that exceed the price of ua and returns
+;the remaining list.
+;
+;Template
+;
+;(define (eliminate-exp lotp ua)
+; (cond
+; [(empty? lotp) empty]
+; [(> (first lotp) ua) ... (first lotp) (eliminate-exp (rest lotp)) ...]
+; [else (first lotp) (eliminate-exp (rest lotp))...]))
+
+(define (eliminate-exp lotp ua)
+ (cond
+ [(empty? lotp) empty]
+ [(> (first lotp) ua) (eliminate-exp (rest lotp) ua)]
+ [(<= (first lotp) ua) (cons (first lotp) (eliminate-exp (rest lotp) ua))]))
+
+(define list2 (cons 4.5 (cons 4.6 (cons 4.7 (cons 4.9 (cons 5.2 (cons 3.8 (cons 2.9 (cons 3.4 (cons 6.1 empty))))))))))
+;
+;Data Definition
+;
+;A list-of-symbols is either
+;1. an empty list or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+;
+;Contract, Purpose, Header
+;substitute : symbol symbol list-of-symbols -> list-of-symbols
+;Replace old with new (numbers) in alos (list-of-symbols).
+;
+;Template
+(define (substitute new old alos)
+ (cond
+ [(empty? alos) empty]
+ [(symbol=? (first alos) old) (cons new (substitute new old (rest alos)))]
+ [else (cons (first alos) (substitute new old (rest alos)))]))
+;
+;Contract, Purpose, Header
+;recall : symbol list-of-symbols -> list-of-symbols
+;Removes ty from lon (list of names, data type: list-of-symbols).
+
+(define (recall ty lon)
+ (cond
+ [(empty? lon) empty]
+ [(symbol=? (first lon) ty) (recall ty (rest lon)) ]
+ [else (cons (first lon) (recall ty (rest lon)))]))
+
+(define list3 (cons 'firetruck (cons 'playstation (cons 'xbox (cons 'racecar (cons 'doll (cons 'bicycle empty)))))))
+
+;; how-many : number number number -> number
+;; Determines how many solutions a given quadratic equation has given
+;; coefficients a, b, and c.
+
+(define (how-many a b c)
+ (cond
+ [(= a 0) 'degenerate]
+ [(> (sqr b) (* 4 a c)) 2]
+ [(= (sqr b) (* 4 a c)) 1]
+ [(< (sqr b) (* 4 a c)) 0]))
+;
+;Contract, Purpose, Header
+;quadratic-roots : number number number -> Scheme-value
+;Given a, b, and c (numbers), it returns either a symbol ('none), a number (if there is one root to the eqn), or a list of 2 numbers by calling on two-roots (if there are two solutions).
+
+(define (quadratic-roots a b c)
+ (cond
+ [(= (how-many a b c) 0) 'none]
+ [(= (how-many a b c) 1) (/ b -2 a)]
+ [(= (how-many a b c) 2) (two-roots a b c)]))
+
+;two-roots : number number number -> list-of-numbers
+;Given a, b, and c, computes the two roots of the
+;quadratic equation and returns the 2 roots
+;as a list-of-numbers.
+
+(define (two-roots a b c)
+ (cons (/
+ (+ (* -1 b)
+ (sqrt (- (sqr b)
+ (* 4 a c))))
+ 2 a)
+ (cons (/
+ (- (* -1 b)
+ (sqrt (- (sqr b)
+ (* 4 a c))))
+ 2 a) empty)))
+;
+;Data Definition
+;A mixed-list is either
+;1. an empty list or
+;2. (cons mixed list) where mixed is either a symbol or a number
+; and list is a mixed-list.
+;
+;Contract, Purpose, Header
+;controller : number -> mixed-list
+;Controller takes in cents and returns a list with the following elements:
+;1. the dollar amount (number),
+;2. 'dollar or 'dollars,
+;3. 'and,
+;4. the cent amount (number),
+;5. 'cent or 'cents.
+;
+;Whether singular or plural is used for elements 2 and 5 is
+;determined using plural?.
+;
+;Template
+(define (controller cents)
+ (cons (quotient cents 100)
+ (cons (cond
+ [(plural? (quotient cents 100)) 'dollars]
+ [else 'dollar])
+ (cons 'and
+ (cons (remainder cents 100)
+ (cons (cond
+ [(plural? (remainder cents 100)) 'cents]
+ [else 'cent]) empty))))))
+
+;Contract, Purpose, Header
+;plural? : number -> boolean
+;Determines if a number needs to be considered plural
+;for grammar purposes.
+
+(define (plural? num)
+ (cond
+ [(= num 1) false]
+ [(not (= num 1)) true]))
blob - /dev/null
blob + f9519f32a6da005b92ea9f579ba33e1e0690b2ed (mode 644)
--- /dev/null
+++ 10.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 10.2.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+;Data Definition
+;An ir (inventory record) is a structure
+;(make-ir s n) where s is a symbol and n is a number.
+
+(define-struct ir (name price))
+
+;Data definition
+;An inventory is either
+;1. an empty list or
+;2. (cons ir inv) where ir is an inventory record (structure)
+;and inv is an inventory.
+
+;Contract, Purpose, Header
+;contains-doll? : inventory -> boolean
+;Takes in an-inv (inventory) and searches to see if
+;it contains 'doll. Return true or false.
+;
+;Template
+;
+;(define (contains-doll? an-inv)
+; (cond
+; [() ...]
+; [() (first an-inv) (contains-doll? (rest an-inv))]))
+
+(define (contains-doll? an-inv)
+ (cond
+ [(empty? an-inv) false]
+ [(symbol=? (ir-name (first an-inv)) 'doll) true]
+ [else (contains-doll? (rest an-inv))]))
+
+(define list1 (cons (make-ir 'hat 55)
+ (cons (make-ir 'match 25)
+ (cons (make-ir 'tricycle 1840)
+ (cons (make-ir 'jumprope 400)
+ (cons (make-ir 'doll 150) empty))))))
+
+;Contract, Purpose, Header
+;contains? : inventory symbol -> boolean
+;Takes in an-inv (inventory) and searches to see if
+;it contains keyword. Return true or false.
+
+(define (contains? an-inv keyword)
+ (cond
+ [(empty? an-inv) false]
+ [(symbol=? (ir-name (first an-inv)) keyword) true]
+ [else (contains? (rest an-inv) keyword)]))
+
blob - /dev/null
blob + 2f034e804f2301d968cae84cd6b4863d164dba09 (mode 644)
--- /dev/null
+++ 10.2.2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 10.2.2) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+;Data Definition
+;An ir (inventory record) is a structure
+;(make-ir s n) where s is a symbol and n is a number.
+
+(define-struct ir (name price))
+
+;Data definition
+;An inventory is either
+;1. an empty list or
+;2. (cons ir inv) where ir is an inventory record (structure)
+;and inv is an inventory.
+
+;Contract, Purpose, Header
+;contains-doll? : inventory -> boolean
+;Takes in an-inv (inventory) and searches to see if
+;it contains 'doll. Return true or false.
+;
+;Template
+;
+;(define (contains-doll? an-inv)
+; (cond
+; [() ...]
+; [() (first an-inv) (contains-doll? (rest an-inv))]))
+
+(define (contains-doll? an-inv)
+ (cond
+ [(empty? an-inv) false]
+ [(symbol=? (ir-name (first an-inv)) 'doll) true]
+ [else (contains-doll? (rest an-inv))]))
+
+(define list1 (cons (make-ir 'hat 55)
+ (cons (make-ir 'match 25)
+ (cons (make-ir 'tricycle 1840)
+ (cons (make-ir 'jumprope 400)
+ (cons (make-ir 'doll 150) empty))))))
+
+;Contract, Purpose, Header
+;contains? : inventory symbol -> boolean
+;Takes in an-inv (inventory) and searches to see if
+;it contains keyword. Return true or false.
+
+(define (contains? an-inv keyword)
+ (cond
+ [(empty? an-inv) false]
+ [(symbol=? (ir-name (first an-inv)) keyword) true]
+ [else (contains? (rest an-inv) keyword)]))
\ No newline at end of file
blob - /dev/null
blob + 130a4d981a887dd2d7084fe658a2541773eea5f7 (mode 644)
--- /dev/null
+++ 10.2.2.ss
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 73 0 1 #"\0"
+0 75 1 #"\0"
+0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 12 #"Courier New\0"
+0 18 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 150 0 150 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 175 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 37 #"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 38 #"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 37 #"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 39 #"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 132 60 36 0
+0 0 -1 -1 2 42 #"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 132 60 36 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 36 #"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 36 #"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 81 112 203 0
+0 0 -1 -1 2 38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 81 112 203 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 68 0 203 0 0
+0 -1 -1 2 31 #"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 68 0 203 0 0
+0 -1 -1 2 41 #"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 2 37 #"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 2 38 #"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 34 #"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 35 #"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 37 #"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 35 #"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 4 1 #"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 0 1 #"\0"
+0 75 12 #"Courier New\0"
+0.0 18 90 -1 90 -1 3 -1 0 1 0 1 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255
+255 255 1 -1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1
+ 0 1156 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 173
+(
+ #"#reader(lib \"htdp-beginner-reader.ss\" \"lang\")((modname 10.2.2) ("
+ #"read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t construc"
+ #"tor repeating-decimal #f #t none #f ())))"
+) 0 0 4 29 1 #"\n"
+0 0 17 3 16 #";Data Definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";An ir (inventory record) is a structure"
+0 0 66 29 1 #"\n"
+0 0 17 3 52 #";(make-ir s n i) where s is a symbol, n is a number,"
+0 0 66 29 1 #"\n"
+0 0 17 3 19 #";and i is an image."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 13 #"define-struct"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ir"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"image"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 23 #";An inventory is either"
+0 0 66 29 1 #"\n"
+0 0 17 3 20 #";1. an empty list or"
+0 0 66 29 1 #"\n"
+0 0 17 3 61
+#";2. (cons ir inv) where ir is an inventory record (structure)"
+0 0 66 29 1 #"\n"
+0 0 17 3 25 #";and inv is an inventory."
+0 0 66 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #";Contract, Purpose, Header"
+0 0 66 29 1 #"\n"
+0 0 17 3 38 #";contains-doll? : inventory -> boolean"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";Takes in an-inv (inventory) and searches to see if"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";it contains 'doll. Return true or false."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 32 #";(define (contains-doll? an-inv)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 13 #"; [() ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 57 #"; [() (first an-inv) (contains-doll? (rest an-inv))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 14 #"contains-doll?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 4 #"doll"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 14 #"contains-doll?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #";Contract, Purpose, Header"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";contains? : inventory symbol -> boolean"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";Takes in an-inv (inventory) and searches to see if"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";it contains keyword. Return true or false."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"contains?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"keyword"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"keyword"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"contains?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"keyword"
+0 0 22 3 4 #")]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"list1"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 5 #"robot"
+0 0 66 3 1 #" "
+0 0 20 3 5 #"29.95"
+0 0 66 3 1 #" "
+0 3 23 66 1 #"\0"
+2 -1.0 -1.0 0.0 0.0 0 6 500
+(
+ #"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\09\0\0\0u\b\2\0\0\0{\340\336\305\0"
+ #"\0\n\341IDATx\234\345\\}LM\377\37\177\237n\17\267\242\334\362\34B4"
+ #"\222\321\242\31\e\252\371F3$k\306<\305\230\247YFT\2141\305D\331\210)"
+ #"\263\306jhL\211\262!\326\252MC\321\246\247\215<w\251[\327\275J\267"
+ #"\373\371\375\361\351{\234\316\303\347|\316\271'\337?~\257\277\3169"
+ #"\357\367\347\375~\235\367\375<\274?\17\347\2r\0\277~\375r\2448\306"
+ #"\346\315\233)5\301AOYYY\16Z\0\0ooo*MG\334\324\326\326\28d\341\375"
+ #"\373\367\b\241\232\232\232I\223&\311*\253\367\344\353\353\v\0[\267nU"
+ #"m\201\305\314\2313i\336\331\t\324\342\373\367\357\b\241\372\372z\325"
+ #"\26\316\236=\3130\f\3030\257^\275\242\321g\20B\252\235a\264\267\267"
+ #"\e\f\6EE\354v\273N\247\3\0E\336\325\307\225\205\301`\b\f\fTT\4\23U\n"
+ #"\r\270\2@CC\303\247O\237(\225\31\206\301\27K\227.U\346\306\361\226"
+ #"\2011o\336<JM\325\256\265\211+\0l\330\260!<<\334\323\323\223a\30\275"
+ #"^\357\343\343\23\30\30x\350\320\241\242\242\242\246\246&\236\362\344"
+ #"\311\223\221\212v\242\364\345\310\241rvv&\273suu]\276|\271J/\332r\5"
+ #"\00077\267\261c\307\32\f\6\17\17\17\2i''\247\314\314\314\277\3155??"
+ #"\37S$\253577\27\24\24\254Y\263\206\313\330f\263\321;\322\200+\0\254"
+ #"\\\271RE\301s\347\316)\252\204\332\264\255k\327\256\251(E\337\315ah"
+ #"\303\225\\5\245\360\376\375{E\372\232\365Y\\\364\366\366J\211\20\247"
+ #"!~\370\360A\221Y\r\362\1\206\351g\4\17KRf\271\312^^^f\263"
+) 500
+(
+ #"\231\236\200\366q%\373\346J\273\272\272\24%\6\3R\a(C\325\323\323\243"
+ #"\327\353\351\315\16\bWz\f\e6\214^\371?\346\32\31\31I\257\374\37sU\4"
+ #"\355\271\326\325\325\5\5\0051\2\b5E\37\22 \223\26\251@pp0\245\346"
+ #"\344\311\223\333\332\332\350-k\20Wax\"\"\"n\334\270a2\231\254V\253"
+ #"\311djll\274t\351\222\260`HH\210\262\341@E\316\301\303\335\273wU\224"
+ #"\2324i\222R\2\32pU\264R\364\366\355[^\260ZZZ\26-Zt\373\366m\331\262"
+ #"\232\315\267d\261`\301\2\a\177\341\1\344j6\233\203\202\202\350k\243"
+ #"\335n\37@\256\356\356\356\nZ\206\30\302\303\303\337\275{\207\20Z\261"
+ #"b\205lh\35\352\a\314f\263\272\202\36\36\36\a\17\36D\b=~\374\330\337"
+ #"\337\37\0\2\2\2dK)\350_\273\273\273\277~\375ZZZ\372\345\313\227\246"
+ #"\246\246\353\327\257+\342\267j\325\252\177\376\371'>>^4\267b\273\5"
+ #"\22h~\353A\203\6)\242\305\242\250\250\250\247\247\207\306\305\203\a"
+ #"\17d\311\320\326\327\254\254,.\t\235N\267q\343\306\214\214\214\262"
+ #"\2622\234/;\210\327\257_\3\200\311d\322\200kWWWww7{\233\220\220\340"
+ #"\0205\1ZZZp\24\202\203\203+**Dud\332\226\237\237\37\316<\364z\275"
+ #"\233\233\e\3030c\306\214\1\0\27\27\27u\265B\n\b!\0())\251\255\255MKK"
+ #"c\30\346\316\235;<\35I\256\376\376\376\f\303|\376\374\31_\263\357"
+ #"\372\361\343GmYbtvv\2@GG\a\3030\205\205\205mmm\a\17\36d\30&,,\214"
+ #"\325\21\357\a\330t\244\247\247Gt\211j\330\260aIIIiiiZq\345%\\\6\203"
+ #"\1\257\230s\23#\21\36\335\335\335\370\2IO\233\364z\375\233"
+) 500
+(
+ #"7o\264\241\t\0\0\337\276}\223\325\21\251\3eee 7\277\323\353\365\332V"
+ #"\6\\\331\274\275\275\t:\"\\\355v;\215\365\236\236\36u\264D\321\336"
+ #"\336\16\0\236\236\236\4\35\21\256K\226,\2215\355\345\345\245\232\226"
+ #"(\236<y\2\0\323\247O'\350\250\317\aF\215\32\245\272\254\20\270%)\256"
+ #"\0034\360\360\360P\272OD\306\217\37?duTrmmmU\272OD\206\315f\223\325"
+ #"\21_{\343-\247\t\341\345\345\365\343\307\17\rG/\251\25;.\23\225\\e"
+ #"\25\224\202\206\353\377\367\272\213\n|\377\376\235FM\204+\36B\b\320v"
+ #"\24\0\200\322\322R\0\2308q\242\214\2360M\2342e\212\350s\26\231\231"
+ #"\231d\5\245\300m4==](\342:\22q)\365\16,\206\17\37\256-W\354\261\276"
+ #"\276^T\364\347Z\252\244\250\321\23'N\20~\20\325 \30\344>\247\235\307"
+ #"\272\272\272j^Me\301\333\317\341\267-QB\f\303\260\317\253\253\253"
+ #"\265%\204g\205\242\340\rf|\256x\226\23\32\32*Z\30!\324\320\320\3400"
+ #"\275~HMM\225\22\311p\305+\24\341\341\341\302\2228\t\222\355\321\224"
+ #"\342\376\375\373R\"\31\256xf\262h\321\"a\311\2337o\202\3\353BR\300"
+ #"\263BQ\360\23\32\232&\t\0\353\326\255\303\327{\367\356\25\325q\260"
+ #"\23\210\210\210\20\212pUfoi\307\330\213\27/\342\213\301\203\a\323"
+ #"\307\214\36\261\261\261\302\207\274\337\220\226+;\23\322|\366\2021m"
+ #"\3324\341C\324?\355R\234\273h\313\225\255\254\v\27.\24JIq\315\315"
+ #"\315\5\0\336\344\4\37pd1a\302\4-H\366!##\203 5\231L\334\333~\\kjj@p"
+ #"\304\253\274\274\234{\353\370Z6\27\35\35\35\4)o7\252\37\327+W\256\0@"
+ #"tt4\367\341\356\335\273\271"
+) 500
+(
+ #"\323v\37\37\37\r8\376\v\362\224\2207\210\366\343\212k\317\2349s\330'"
+ #"\305\305\305v\273}\307\216\35\354\23u\307E\244@^\274\371\365\353W"
+ #"\277{\251\316\225]\325\342\351\260uH\223\316\225\373\346Bivv6H\365"
+ #"\257x\307\21/\270\272\271\2719\0220JX\255V\202\224\267\264\341\f\0"
+ #"6\233m\320\240A\334@r\301\353\244\310\255A[\360\332\261S\\\\\234\213"
+ #"\213\213\24Q\0\350\354\354\344\276\37a\370\326\34\274\250;\345\345"
+ #"\345\2617\302\235\273\352\352\352\223'Ovvv2\f3\177\376|P~\250\212\6)"
+ #"))\242\317\277|\371\322\357~\317\236=aaa\344\26p\367\356]\254\214\20"
+ #"\332\266m\e{\335\332\332J\263\250\210\21\20\20\20\23\23s\354\330\261"
+ #"\364\364\364-[\266pE\b\241\254\254,\235N\347\344$2\216\2624@\247\323"
+ #"%&&\222\271\262\355\fq\366\322\265\202N\247\353\243\"\201?\375@oo"
+ #"\257\354\20\217k3\36E\204\ao1\30\206\211\214\214|\372\364\251\325jMJ"
+ #"JZ\265jUNN\16\353\306b\261Hu\314l\222\212\20\32;v,\276\346*\377\376"
+ #"\375\273\357\312\331\331\371\350\321\243\344\270b\315S\247NI\275}KK"
+ #"\213h\301\252\252\252\303\207\17\357\332\265+!!\341\305\213\27F\243"
+ #"\261\245\245\5\2175\301\301\301\253W\257\226u\212q\346\314\31\204P"
+ #"\337\330@(SRR\2\0\215\215\215<Cqqq\3447\354\352\352\"H]\\\\\306\215"
+ #"\e\307{gww\367\3\a\16\30\215F\241\221\321\243G\3B\210\320\266\216\34"
+ #"9\302\376@<\2348q\202\314\265\267\267\227 \345\366\203K\226,\251\251"
+ #"\251![\333\277\177?`\243R1\300\266\356\335\273'\24=|\370\220l\35!TYY"
+ #")%b\203\352\344\344$k\a!\224\222\222\322\27\2605"
+) 500
+(
+ #"k\326\3606\244\361\242\225TP\21B?\177\376\224u@\250]\270\267\6\0///"
+ #"\32\256s\347\316\355g\v\347\332,\2\2\2h\254\220\271\376\376\375[Tt"
+ #"\372\364i\354\345\302\205\v\224\246\372\365\275\353\327\257G\bUUU]"
+ #"\276|\271\255\255M\252{R\4)#\354\n&\315\361\307\364\364t\0M\227\320D"
+ #"\203\221\232\232**b\307\352g\317\236\221\215\334\272u\253\217\362\0"
+ #"0\374\3\0000\30\f\4)\0\224\224\224\310\32\371K\\\261\v\321\263\e\0"
+ #"\220\227\2277u\352T\204\220\325j\335\267o\337\214\0313\244\16D\32"
+ #"\215\306\277\3045))ITz\376\374y\362d\323\325\325\365\217\376\337\341"
+ #"\212\203\307\203N\247\v\t\tA\b%$$\0\0\3030~~~\261\261\261\307\216\35"
+ #"\23\267\366w\270\212V\266\331\263g\263I\26\2255u$\36=zDe\235\310\265"
+ #"\265\265UQ\203Q\271\277\245\311\241\fE\a\313A\365^\234\242\325m\2556"
+ #"\32Tr\2459\236\302B\263-\6\372\352\302\205\257\257/\215\32\0\214\349"
+ #"\22'\371R\n\271\271\271\224NUruqq\241\262\16\260s\347NBP\0\0w[4PY\a"
+ #"\350\253\240\354\261\370\227/_R\232\32\360}n\362\21\26E\30p\256\25"
+ #"\25\25Z\231\32p\256x\277\35\237\230\24b\331\262e\364\246\6\234\353"
+ #"\317\237?\1`\356\334\271\242R| \253\253\253\213\306\324\200s\265X,\0"
+ #"0k\326,Q\351\376\375\373\341\337]>Y\f8W\274\256\350\347\347'*\305-Ox"
+ #"\324U\34\264=j\177p\323J\2X/\345\345\345d\35\32k*\343:t\350PE\372J?"
+ #"\177\22\205J\256\362\347h\6\0*\271\322\177<\202\367o5\331\35W\306u"
+ #"\361\342\305\f\303\214\e7.&&\206\240f2\231\330\377\374(,,\4\200\347"
+ #"\317\237"
+) 342
+(
+ #"\253\246\370\a\264\255\t!\274\242\30\32\32j4\32\267o\337\3165\22\32"
+ #"\32\32\37\37\177\372\364\351\374\374|L\216k\37\244\27\202\270j\351"
+ #"\351\351W\257^%\20P\362\251\227\222w\343\222\300\211\271P'11\221\367"
+ #"J\0p\374\370qG\271\262\25\216R\337f\263\231\315\346\250\250(\350?"
+ #"\337\262\331l\211\211\211\274\3566::\32!\324\334\334<b\304\bB\266I"
+ #"\353{\310\220!\0000b\304\bJ}\26\354v\5\315\337\"l\332\264\t\0:::\304"
+ #"MQVk\234\260\342\277pP\4v\345\237\346\323m\34\221\312\312JQ)-W\354I"
+ #"\352,\24\18w\241<y\202\2671\244>\356\244\345\212O&)\335\244e\207+"
+ #"\312\357\0\212\213\213\201\260\371\255\250\362\361\364-\26KNN\316"
+ #"\332\265ki\16\226\310\32gO)dgg\213{W\304\325h4\322\204\207\305\370"
+ #"\361\343\353\352\352\310\\-\26KAA\1w\252\363\371\363g\r\270\"\2123"
+ #"\332111W\256\\\261X,X_x\336\340\366\355\333\311\311\311\370\224\255"
+ #"\20\311\311\311\222\256\225r\305\260\333\355&\223\311l6\323\364D\224"
+ #"?BTT\24\371\263\323\377\1\250\227\355f\254\315s9\0\0\0\0IEND\256B`"
+ #"\202"
+) 0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 20 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 4 #"doll"
+0 0 66 3 1 #" "
+0 0 20 3 4 #"9.95"
+0 0 66 3 1 #" "
+0 3 21 66 1 #"\0"
+2 -1.0 -1.0 0.0 0.0 0 5 500
+(
+ #"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\0T\0\0\0u\b\2\0\0\0_\371Q\5\0\0\baI"
+ #"DATx\234\325\\_HS\357\e\177\217\231\332\\[h\00313m\264j!\254\314V"
+ #"\220F--\252\v#\f\242\302\274\20\262\b\212\f\274H\"\"\250 \272\311"
+ #"\253\376\b\321E\27%\366\207B\363b\375!\212\32\264\213\246i\323L\233"
+ #"\2469k\233f\233\353\375^\274\277\316\357\264\271\355l\347y\316\231"
+ #"\237\253\355\374\371<\317s\236\347}\337\347\375\313QJI2!??\177``\200"
+ #"\20\242\321h~\376\374\211*+\5\225=\0010\313\t!\36\217'==\375\375\373"
+ #"\367x\262\270d\363<\307q!WV\256\\\351p80d%\235\347\351_tww\263+\235"
+ #"\235\235{\367\356\305\220\225t\236\17A\177\177\177AA\1!\4CO%=\237"
+ #"\225\225\305\t0\3433K\226,\241\224>x\360\0E\3\252\20\334n7!\204\343"
+ #"\270\246\246\246\307\217\37\23B\32\32\32d\326A\261\260\337\272ukff"
+ #"\346\375\373\367\371+Z\255\26\273m\vA\252\234\302\204\350\352\352\32"
+ #"\34\34\24^)++\223Y\a\305<\177\352\324\251\214\214\214s\347\316)\""
+ #"\235A\311\332\236\343\270\17\37>\30\215F\245\24P\270\235_\265j\325"
+ #"\263g\317\224\222\256\244\347m6\333\332\265k\211\2106\234\343P\364T"
+ #"\254\302#\204\24\27\0273\223\204\215\274\320H\376:R;\237\24\31^\244"
+ #"\f\207\a\222\222I\221\333SJ].\327\262e\313\302o\231L&D\367\310\234T"
+ #"\305DEEEJJ\n!d\371\362\345\330\262\222\"\354\225BR\204\275R\230\255"
+ #"\306\373\375\376\232\232\32.2\366\355\333\347p8\376\374\371\23\215\5"
+ #"\273\\a \336/u\372\364\351\231yd\326;\34\323\323\323\337\276}\23\363"
+) 500
+(
+ #"\344\376\375\373\2311\375\375\375\"\311\207\206\206v\354\330!\374\20"
+ #"\255\255\255\374]e\214\267\331l\221\274\364\365\353\327Ho\2358q\342"
+ #"\356\335\273\211I\274z\365jFF\6/\245\242\242\202\312o\374\372\365"
+ #"\353\305\4\352\272u\353\220\24\370G\f\222\214\230\202\315f\263\325j"
+ #"\25\336u\273\335\365\365\3652\350f\265Ze5\236\rZ\361\350\350\350\210"
+ #"\364dss3\377\330\355\333\267\221\364\31\36\36&2\344\366|\336^ZZ\372"
+ #"\374\371\363\304\336ER\22\267\235W\253\325\354\a\2454^\313\331[\26"
+ #"\213\205\210\350\371$\b\244\270\242\224\356\332\265\vD\4\236\236X"
+ #"\375y\255V\353\361x\bD\304RJ\221<\17\37\366>\237\217\3438\217\307#"
+ #"\364\233D0\373\323\322\322@\330x\300Wx\314K\340\264\32\215\306\353"
+ #"\365\302\322\2{\36\311rB\b+D\327\257_\a\344\204\364<\263<//\217\237c"
+ #"\a\a\354H&X\205\207\347s!\366\354\331\3I\a\322f\234<y\22\212*&>}\372"
+ #"\4E\5P\346_\277~}\371\362e*\327p\30\340$\207T\343\17\37>\274a\303\6"
+ #"\20UD\342\325\253WPT\222\312<+\347\273w\357nii\1\322'6\276\177\377"
+ #"\16E%\265\302{\364\350\321\316\235;AT\21\t\266J\5\6\t\327\26g\316"
+ #"\234)//\207\252{\304\243\275\275\35\212*\361f\23i\3620&\6\6\6\26/^\f"
+ #"B\225H\330\263\242\16\233l\211\27\r\370\305\343\346JOO\367\373\375\6"
+ #"\203\341\343\307\217PJ\304%\375\367\357\337Plq\e/O&7#jjjrss\317\237?"
+ #"\17E\230\210\361\212X\336\336\336\276m\3336X\321qX\242\240\317\t\316"
+ #"G\27\233\3411\313KJJ`\305\213Dee\345\347\317\237\341y\305\264\207l"
+ #"\205\344\2349s\240\32\330\270\300j8"
+) 500
+(
+ #"\ffQ\261\244`\300\367\365\365-]\272\24Iz\354v\376\332\265kH\262c\202"
+ #"\37\267\34\37\37G\21\20=0\304<\223\0~\375\372\25\345\256\313\345\312"
+ #"\313\313c\242C\246\264`\21\315\363\354\303o\331\262\5\374\213[\255"
+ #"\326\355\333\267G\21\312@\261\303-\322Waw5\32\r\322W'\204TUU\365\366"
+ #"\366\216\214\214\\\272t)33S\250Unn.\222\334\177t\230\361\352\255["
+ #"\267\br\365\36\311\31\t\317\300'\200\320\332\336h4vvv\22\345\222\319"
+ #"\221b2\2318\216+...**\3428\216Y\16\233\314\0vE\320\361\344\311\23"
+ #"\330\350\312\311\311\241\224\366\366\366\212\17\351`0\350t:a\325\b\a"
+ #"\311\316\316F\265\234RJ\376V\253\204\220\2337oFyrllL\245R\2058\303"
+ #"\345r\201\253\364?}\220x\205hkk\23\376\235;wn\244\240+))\231\232\232"
+ #"\22>\334\323\323\303na(\246\330\362\323\356\356\356\276\276\276\224"
+ #"\224\24\275^\317\22\330(P\253\325>\237\17\\\at\343\3\201@\24W+\v\364"
+ #"\345\247\251\2510\323\201~\277\37\204G\210Y\263\352Z\311\301\f)\300"
+ #"\352\223I\206\34\306\267\266\266J'ihhp:\235\322y\376\1F\23\22\2\220"
+ #"\211\35\257\327{\364\350Q\351<B\310Q\346\215F#\310\356\177\330A{\"O"
+ #"\330\257Y\263\6\204\207_\330\a\59\214\327\353\365 <G\216\34\1\341"
+ #"\341!\207\361\205\205\205 <\26\213\345\335\273w T\fr\30?\177\376|("
+ #"\252\3\a\16@Q\221Y\267\301htt\24\220M\16\343GFF\240\250ZZZ\0g\207"
+ #"\345\330H\374\345\313\27(\252M\2336\31\f\6\376\24\31\211\220\303\363"
+ #"?~\374\0d\343{\370\322!G\222\223\223\223\303\266u\200`zz\32\252\2478"
+ #"\313j{\2\327G"
+) 500
+(
+ #"&\362\30\37s\240&^@\305\221\34\306WVV\302\22\212\334\234\27\e\260"
+ #"\375\244p`\214\275^\270p\301\357\367K\347A\367\374\275{\367\3009\217"
+ #"\35;\326\324\324$\235\a\275\266\317\316\316\36\e\e\3\247\5\31\325"
+ #"\222cS!\206\b\220\301l\364\260GZ\220\355\363\371\216\37?.\221d\326"
+ #"\214\336\206CzL\315\262^\235\20\v\26,\220\310\200k|[[\e\36\371\215\e"
+ #"7\244RHo-\243\0\233\277\252\252J\312\353\210e\336\343\361\224\226"
+ #"\226\332\355v$~\"\271\330#\366\347W\254X\321\325\325\205\307O$\257 A"
+ #",\363CCC\32\215\6\217\237\20r\350\320!)\257c\205}ZZ\332\2337oV\257^"
+ #"\215A\16\5\24\317766\6\2\201$\267\234 y\236\343\270\262\2622\31\316w"
+ #"\2248\252\203U\346\37>|\210\304,\204\324\357\v\321\334\206\342\342"
+ #"\305\213\30\264\341HMM\225\364:\220\17\376\217\362\362\362\247O\237"
+ #"\202\323\206C\257\327_\271rE\n\3\312\261\21\340\234H\202\340\313\374"
+ #"\302\205\v\3019\303\1r~\n\274\361\330Y\35\371k9;EC\22\17l\210NNN\206"
+ #"\257\37\5\304\324\324\324\274y\363\b\320\242p`\317\253T*vv)\0066o"
+ #"\336\fh9\301\350\330 \325v|!\257\253\253\3#\225\334\326\206\242\260"
+ #"\260\360\355\333\267\200\204g\317\236\345\265\35\37\37\adFIr\230\242"
+ #"\215\215\215RHB\346\341\241t\23\2\205TX\347\305\373\256\333\355\326"
+ #"\351tB\263\233\233\233\21t\244\24i\306fbb\202_9\304q\234\230\223}"
+ #"\202\301`GG\207V\253\315\312\312\342\327\236\214\216\216RJ\27-Z\204"
+ #"\241$!\230cl!3J\6\203\201\235\354%D \20\350\351\351\231\361\2703v"
+ #"\3047\245\264\276\276\36IC,\343\371#\341(\245/^\274\210\231"
+) 202
+(
+ #"\220\251T\252\203\a\17\316\270\323rbb\302\351t\n\347\271\241\224D\31"
+ #"\303\v\6\203w\356\334\251\255\255e\1777n\334\310\216]\366x<6\233\315"
+ #"\341p\f\17\17\27\24\24\30\f\206\242\242\242\230\303\357:\235nrr\222"
+ #"\377\v\271\32\r\352+\na\267\333\a\a\a\241\330\230\236\371\371\371"
+ #"\265\265\265!;p\2442\3r\361\250\256\256\6d\253\253\253\3d\23\2 \267"
+ #"\177\371\362\245\305b\t\337\6\"\235\31\e\222\312\274\335n7\231L\302+"
+ #":\235\256\272\272\332l6\233\315fi\212\311\1I\236\347\353p\265Z\355"
+ #"\365z\201T\222\17\211'9\314r\266\3s6ZN\b\371\17\24\274S\2\f\350I\266"
+ #"\0\0\0\0IEND\256B`\202"
+) 0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"rocket"
+0 0 66 3 1 #" "
+0 0 20 3 5 #"59.95"
+0 0 66 3 1 #" "
+0 3 21 66 1 #"\0"
+2 -1.0 -1.0 0.0 0.0 0 5 500
+(
+ #"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\0003\0\0\0u\b\2\0\0\0l\302N\f\0\0\b"
+ #"9IDATx\234\315\233[H\24_\34\307\177\353\256m\333n\332\305Z\273mIX"
+ #"\202\31\226\255\21E\322B\241ADR\30X`\5BDB/A\21R\21\24\4\322\205\324"
+ #"\207\350\16\25\21t\243\202B\"\272\240\17=\264eXRY\232!\262\233i\271"
+ #"\272\332\371?\374\326\343\354\354\\\31693\343\376\277/;s.\277\363"
+ #"\231\337\271\314\271\314\332\b!`\231\334n\367\237?\177\304\362\246"
+ #"\230\213\"Uii\351\337\277\177\205\263;LD\221\312f\263\31\264`\211"
+ #"\317\244X\302\210\26\326&\312\351t^\271rE$'1U2\17\345\346\346b\17"
+ #"\313\316\316\3465e&\331\266m\333\244Xyyy\30\276u\353V\1\27\230F\326"
+ #"\321\321!\305\272x\361b\\1\0~\277?9d3f\314\320h$\225\225\225\274n"
+ #"\263\21\223FZi\vS\264i\263\361\225eN\337\334\276};\275^\273v\255b"
+ #"\232\23'Np\3314\301gCCC\251\251\251\364V\315`ss\263\317\347\363x<"
+ #"\254v\215\2670Y=j\250\274\274\234\335\254Q2\256\207\4\200\262\2622V"
+ #"\313\306\300F\3116o\336\314\222x\362\344\311\254\226\215`\235;w\216"
+ #"\253Up\265\37C=@w\244\220\311\341p\f\17\17wvvfff\352&\266\374\215."
+ #"\325\223'O\0 ++\213)\265pUJ\235t\373\366m\256,L)\205\261B\241\20\26S"
+ #"XX\310\236\353\300\201\3\0\320\325\325e!\331\316\235;\221\254\273"
+ #"\273\233=\327\347\317\237\1\340\310\221#V\221\235={\26\261\262\262"
+ #"\262x\3632V\250 \231\327\353\305\2\232\233\233y\363.]\272\324B2#\35"
+ #"\350\321\243G,\31E\3063BHJJ"
+) 500
+(
+ #"\n\0\270\\.\261u\e\313\214Hd<;\177\376<^\24\27\27\vdg\225@u\30\311"
+ #"\213\n\4\2\17\37>\324)E\300\256q\262k\327\256\25\24\24h\247\341ng"
+ #"\321ht\334\270q\224L\254\242\320\210vv\356v\206=\313\240p\16\374\346"
+ #"\315\e\2154\334>\343\235_h\330\261\333\355CCCj\t\306t\256!\323\360"
+ #"\360\260F\2548YQQ\221p^\26\211\223m\330\260\301x\361_\276|Q\215\343"
+ #"\355\360\302\31\25\355\344\347\347\253&\20\263X\\\\l\f\2148\235N\355"
+ #"'\24\254M\351\242\\L\313\226-\323N\300Gv\343\306\r\274\b\4\2\202D#Z"
+ #"\271r\245N\n\256*\310\317\317\27\310\245(:d\334\277\177\337\204\332|"
+ #"\373\366-\277w\224\205\363(\0x\372\364\251r\n\256\a\305,n\267\333"
+ #"\270\317\b!>\237\17\0\\.\227b\254H\17X\267n\235\210\227\22\204\373Y"
+ #"\375\375\375\312\321\354\217\30\211D0\313\207\17\37L\361\331\313\227"
+ #"/5\308\310\36<x\300\3730\332\n\207\303\32\69j\363\365\353\327B\225"
+ #"\246\252I\223&i\304r\220\275\177\377\3360\f\2078\346gn\267\eWJ\354Y"
+ #"\364\213\267\331\324\fr\370\f\261\260\253\217\201\270G\215\377/\331"
+ #"\202\5\vL,\336n\267\3\200\342\234\233\233,''\307\4\242\21\341&\274r"
+ #"\337b\37~0}__\237\31cYL\370:\331\267o_b\24\267\317\334n\267!/\305k"
+ #"\316\2349\0 ;MC\261\222\365\365\365\231\bD\205d?~\374H\214b%kkk3\223"
+ #"(^\3645%\25+Ycc\243\25101M\2348\21\0\332\333\333\23\243X\311\276}"
+ #"\373f&Q\274\350,F*V\262\337\277\177\233\n\23\247\201\201\201\304\300"
+ #"$\223)z\v\305J\366\353\327/\223`\342\324\333\333\253\26\225\344Q\243"
+) 500
+(
+ #"\273\273[-*\231{A\240\331\261\222\334\316\24G\177T\222}\326\332\332"
+ #"\252\26\225d2\305\361\2\225d2\324\370\361\343\23\3\365\277?{\374\370"
+ #"qKK\213\5<\243\222~T1*\215\311\23\375\20\220\20\262b\305\n\335\364"
+ #"\272\232?\177~OO\2174\4m\372|\276\304\304\252>\v\207\303S\246L\201"
+ #"\221\205\215)}\263\265\265U\361\304i\372\364\351\211\211U\333\31buuu"
+ #"\341\255\306k\204K\204\220C\207\16\311\2\247N\235\312Jv\341\302\5\0("
+ #"//\2376m\32\206h\274FxE\317F\251\322\323\323\1`\375\372\365q\241\211"
+ #"\25\214\a\344\16\207C\32H\273\217\221v&m^\204\220\236\236\36\264I"
+ #"\327\1\322s\\yI\273w\357V$\320x\22a544\240\315{\367\356\321\300P("
+ #"\244@\326\331\331\211IO\237>m5\31\0\\\275z\25mvtt\320\360H$\22\211D"
+ #"\344d\32\305[\3413\\\6\3@4\32\225\206\327\327\327+\223566\216\r\31"
+ #"\235Y%Fedd\214\206j\27\214\37\f\254^\275\332D2\224\254\253Q\230\330"
+ #"\250\201\335$77W\251\233\3\0\314\235;\27\30\216\27\4\24\215Fe!\350"
+ #"\313\30Yuu5h\236\252fdd\0\300\314\2313M'\3\0\277\337/\275\305o\226cd"
+ #"g\316\234\201\221\25\263\242\262\263\263\1\200\16\274\346j\371\362"
+ #"\345t\23\30\0\366\354\331\3\0@\b)++\3\200\324\324T\215\326\200{\343"
+ #"\257^\2752\275\235\241\202\301\240\374\225Jojjj\2643\3@0\30\264\210"
+ #"\f\355\307\255\203\350nG\177\177\277n\316\266\2666\353\310._\276\34W"
+ #"\307{\367\356\245\316K.\31Q\334\230\266\333\355\377\a\262]\273v-Z"
+ #"\264\b\217ucd\263g\317f!{\367\356\235\245dtW\237\320=G\227\313\245"
+ #"\333\267"
+) 500
+(
+ #"\235N'\235\267X$\304\330\261c\a\320\361LcuE\345\365z\0257\aM\327\245"
+ #"K\227\0 \5w\227\177\376\374\251\233\241\260\260\360\372\365\353VcQ"
+ #"\245,Y\262\4\0\6\a\au\223\346\344\344\334\275{\327R\232\232\232\32"
+ #"\274\370\372\365+\34<x\20ot\233'\276\6,\355\1\263f\315B\230`0\230"
+ #"\302\372E\260\312J\332\\\321\r\230\t\23&\214\276\235\314z\356\364"
+ #"\364t\261\214\5\5\5\24\221\340\234\226\213L\367k\373P(\324\336\336.@"
+ #"&u^\214\f?\204\371\367\357\37\243\211[\267n\351\226\301\213U__O\261*"
+ #"++cd\363\346\315\3\0\331\216\203\232\26.\\\250\233F\200L\352\260p8L"
+ #"\360\35\260q\343F\0\370\364\351\23K#mii\261\331l6\233m\325\252U\32"
+ #"\311\214\314\313c\347\353ddEz\364\350Q\261G\244\262\333\355iii~\277"
+ #"\237B\vX\e\r$\204\340\361\342\226-[\330\311\6\a\a\217\35;\246\373"
+ #"\364F\311p7E\373\277+w\356\334I,\t\377#\241\241\343\307\217\e\"#z\3G"
+ #"mm\255\266\e4^n\\dk\326\254\341 \223mw\261\224\204\332\277\177?K\372"
+ #"\212\212\nE\343:d8!\241\222n\332\260\210\205\214\356ndff\262\222}"
+ #"\377\376]\212%0\325f!\243\366\353\352\352X\311\244Xb\337O555\325\326"
+ #"\326j$\220\316X\345\245\343\17\236\315\252a\t0I\355h\304\342?N\1\300"
+ #"\343\361(\223-^\274Xj\242\264\264\224b\5\2\1\203d\325\325\325\32\261"
+ #"\250\212\212\ne2\374\213\20^?\177\376\334,\207\21B\362\362\362\0@m"
+ #"\366AKI\374kR\254\340\252\252*\n\341p\214\36\22|\374\370\321 \31~"
+ #"\264YRR\242M\246\20\205?uuu\200\263\357\21y\275^\203LRy<\236"
+) 162
+(
+ #"\242\242\"Y \356/)62B\317P\320O8\35B\261\254\246\330\325\333\333+"
+ #"\373\23\375\300\300\0\235\335l\332\264)1Kl\275\231\226\226f\"\207"
+ #"\242JJJ\244\267'O\236\244\327\3623\n\24\272\356\346\315\233\322\300"
+ #"\206\206\6\23\253\222\352\331\263g\364Z\372}\221bb\371\0162\313\326"
+ #"\213\21\341\266\346\213\27/\22\275\243Jv\370\360a\0hjj\262\224\214("
+ #"\315:u\310\b!UUUVc\305J\345%\eKQ\254S\247N)&\370\17#l\0_X\204\310m\0"
+ #"\0\0\0IEND\256B`\202"
+) 0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 4 #"))))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 57 #";show-picture : symbol inventory -> mixed (image/boolean)"
+0 0 66 29 1 #"\n"
+0 0 17 3 56 #";Given name and an-inv, this function produces the image"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";of the toy with the corresponding name. If"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";the toy is not in the inventory, false is returned"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";instead."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"show-picture"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-image"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"show-picture"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 38 #";price-of : symbol inventory -> number"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";Given name and an-inv, it finds the price"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";of the corresponding toy with the name."
+0 0 66 29 1 #"\n"
+0 0 17 3 47 #";Returns 0 if the item is not in the inventory."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"price-of"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"price-of"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data Definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 39 #";A record (phone record) is a structure"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";(make-record s n) where s is a symbol and"
+0 0 66 29 1 #"\n"
+0 0 17 3 15 #";n is a number."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 13 #"define-struct"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"record"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"number"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data Definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 22 #";A directory is either"
+0 0 66 29 1 #"\n"
+0 0 17 3 20 #";1. an empty list or"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";2. (cons r dir) where r is a record and"
+0 0 66 29 1 #"\n"
+0 0 17 3 20 #";dir is a directory."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";whose-number : number directory -> symbol"
+0 0 66 29 1 #"\n"
+0 0 17 3 47 #";Given a-num and a-dir, finds the corresponding"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";name of the person who owns the number. If"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";the person is not in the directory, returns"
+0 0 66 29 1 #"\n"
+0 0 17 3 28 #";the symbol 'NotInDirectory."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 31 #";(define (dir-func a-num a-dir)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #"; [(empty? a-dir) ... ]"
+0 0 66 29 1 #"\n"
+0 0 17 3 60
+#"; [... (first a-dir) (dir-func a-num (rest a-dir)) ...]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"whose-number"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-num"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 15 #"NotInDirectory."
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"record-number"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-num"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"record-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"whose-number"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-num"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";phone-number : name directory -> number"
+0 0 66 29 1 #"\n"
+0 0 17 3 54 #";Given name and a-dir, finds the corresponding number."
+0 0 66 29 1 #"\n"
+0 0 17 3 41 #";Returns 0 if no number in the directory."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"phone-number"
+0 0 67 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 67 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 67 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 67 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 67 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"record-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"record-number"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"phone-number"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"list2"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-record"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 9 #"HsinyaLin"
+0 0 66 3 1 #" "
+0 0 20 3 10 #"6265939257"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-record"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 9 #"RonRonLin"
+0 0 66 11 1 #" "
+0 0 20 3 10 #"6267157010"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-record"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 8 #"TunaFish"
+0 0 66 3 1 #" "
+0 0 20 3 7 #"8888888"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 4 #"))))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";extract : inventory number -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 5 #"Given"
+0 0 17 3 1 #" "
+0 0 17 3 41 #"an-inv and price, it returns an inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 8 #"composed"
+0 0 17 3 1 #" "
+0 0 17 3 36 #"of inventory records (ir) which have"
+0 0 66 29 1 #"\n"
+0 0 17 3 27 #";prices greater than price."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 31 #";(define (extract an-inv price)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #"; [(empty? an-inv) ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 5 #"; "
+0 0 17 3 1 #"["
+0 0 17 3 3 #"..."
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 5 #"first"
+0 0 17 3 7 #" an-inv"
+0 0 17 3 33 #") (extract (rest an-inv)) ...])) "
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extract"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #">"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extract"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extract"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 4 #")]))"
+0 0 66 3 1 #" "
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"RAISE"
+0 0 66 3 1 #" "
+0 0 20 3 4 #"0.05"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 38 #";raise-prices : inventory -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 8 #"Consumes"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"an-inv"
+0 0 17 3 35 #" and produces an inventory in which"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"price"
+0 0 17 3 38 #" of each inventory record is increased"
+0 0 66 29 1 #"\n"
+0 0 17 3 18 #";by RAISE percent."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 30 #";(define (raise-prices an-inv)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 19 #"; [(empty?) ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 5 #"; "
+0 0 17 3 1 #"["
+0 0 17 3 4 #"else"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"..."
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 45 #"first an-inv) (raise-prices (rest an-inv))]))"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"raise-prices"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 66 29 1 #"\n"
+0 0 66 3 17 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 17 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"RAISE"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 17 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-image"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 66 3 16 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"raise-prices"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 6 #")))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #";Contract, Purpose, Header"
+0 0 66 29 1 #"\n"
+0 0 17 3 39 #";recall : symbol inventory -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 50 #";Removes the inventory record (ir) associated with"
+0 0 66 29 1 #"\n"
+0 0 17 3 23 #";ty from the inventory."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 30 #";(define (raise-prices an-inv)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 19 #"; [(empty?) ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 5 #"; "
+0 0 17 3 1 #"["
+0 0 17 3 4 #"else"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"..."
+0 0 17 3 1 #" "
+0 0 17 3 46 #"(first an-inv) (raise-prices (rest an-inv))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"recall"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"recall"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"recall"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 6 #")))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 10 #"substitute"
+0 0 17 3 1 #" "
+0 0 17 3 1 #":"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"symbol"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"symbol"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"inventory"
+0 0 17 3 13 #" -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 5 #"Given"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"old"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 3 #"new"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"an-inv"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 7 #"replace"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 8 #" name of"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 2 #"an"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"inventory"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"record "
+0 0 17 3 4 #"with"
+0 0 17 3 6 #" name "
+0 0 17 3 3 #"old"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"with"
+0 0 17 3 10 #" name new."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"substitute"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 67 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 67 3 3 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 67 3 3 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 66 29 1 #"\n"
+0 0 66 3 19 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 19 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-image"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 66 3 10 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"substitute"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 4 #")))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 3 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 67 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 15 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"substitute"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 67 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 6 #")))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0
blob - /dev/null
blob + 7bdf36e700c22d636a6f4b20240643dee67c8d11 (mode 644)
--- /dev/null
+++ 10.3.1.bak
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 73 0 1 #"\0"
+0 75 1 #"\0"
+0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 12 #"Courier New\0"
+0 18 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 150 0 150 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 175 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 37 #"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 38 #"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 37 #"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 39 #"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 132 60 36 0
+0 0 -1 -1 2 42 #"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 132 60 36 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 36 #"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 36 #"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 81 112 203 0
+0 0 -1 -1 2 38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 81 112 203 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 68 0 203 0 0
+0 -1 -1 2 31 #"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 68 0 203 0 0
+0 -1 -1 2 41 #"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 2 37 #"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 2 38 #"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 34 #"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 35 #"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 37 #"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 35 #"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 4 1 #"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 0 1 #"\0"
+0 75 12 #"Courier New\0"
+0.0 18 90 -1 90 -1 3 -1 0 1 0 1 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255
+255 255 1 -1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1
+ 0 1160 0 17 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 66 29 1 #"\n"
+0 0 17 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 66 29 1 #"\n"
+0 0 24 3 7 #"#reader"
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 66 3 1 #" "
+0 0 19 3 25 #"\"htdp-beginner-reader.ss\""
+0 0 66 3 1 #" "
+0 0 19 3 6 #"\"lang\""
+0 0 22 3 3 #")(("
+0 0 14 3 7 #"modname"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"10.3.1"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"read-case-sensitive"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"teachpacks"
+0 0 66 3 1 #" "
+0 0 22 3 3 #"())"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"htdp-settings"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"#("
+0 0 20 3 2 #"#t"
+0 0 66 3 1 #" "
+0 0 14 3 11 #"constructor"
+0 0 66 3 1 #" "
+0 0 14 3 17 #"repeating-decimal"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#f"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"none"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"#f"
+0 0 66 3 1 #" "
+0 0 22 3 5 #"())))"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data Definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";An ir (inventory record) is a structure"
+0 0 66 29 1 #"\n"
+0 0 17 3 52 #";(make-ir s n i) where s is a symbol, n is a number,"
+0 0 66 29 1 #"\n"
+0 0 17 3 19 #";and i is an image."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 13 #"define-struct"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ir"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"image"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 23 #";An inventory is either"
+0 0 66 29 1 #"\n"
+0 0 17 3 20 #";1. an empty list or"
+0 0 66 29 1 #"\n"
+0 0 17 3 61
+#";2. (cons ir inv) where ir is an inventory record (structure)"
+0 0 66 29 1 #"\n"
+0 0 17 3 25 #";and inv is an inventory."
+0 0 66 29 1 #"\n"
+0 0 66 3 9 #" "
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #";Contract, Purpose, Header"
+0 0 66 29 1 #"\n"
+0 0 17 3 38 #";contains-doll? : inventory -> boolean"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";Takes in an-inv (inventory) and searches to see if"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";it contains 'doll. Return true or false."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 32 #";(define (contains-doll? an-inv)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 13 #"; [() ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 57 #"; [() (first an-inv) (contains-doll? (rest an-inv))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 14 #"contains-doll?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 4 #"doll"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 14 #"contains-doll?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #";Contract, Purpose, Header"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";contains? : inventory symbol -> boolean"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";Takes in an-inv (inventory) and searches to see if"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";it contains keyword. Return true or false."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"contains?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"keyword"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"keyword"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"true"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 9 #"contains?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 7 #"keyword"
+0 0 22 3 4 #")]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"list1"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 5 #"robot"
+0 0 66 3 1 #" "
+0 0 20 3 5 #"29.95"
+0 0 66 3 1 #" "
+0 3 23 66 1 #"\0"
+2 -1.0 -1.0 0.0 0.0 0 6 500
+(
+ #"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\09\0\0\0u\b\2\0\0\0{\340\336\305\0"
+ #"\0\n\341IDATx\234\345\\}LM\377\37\177\237n\17\267\242\334\362\34B4"
+ #"\222\321\242\31\e\252\371F3$k\306<\305\230\247YFT\2141\305D\331\210)"
+ #"\263\306jhL\211\262!\326\252MC\321\246\247\215<w\251[\327\275J\267"
+ #"\373\371\375\361\351{\234\316\303\347|\316\271'\337?~\257\277\3169"
+ #"\357\367\347\375~\235\367\375<\274?\17\347\2r\0\277~\375r\2448\306"
+ #"\346\315\233)5\301AOYYY\16Z\0\0ooo*MG\334\324\326\326\28d\341\375"
+ #"\373\367\b\241\232\232\232I\223&\311*\253\367\344\353\353\v\0[\267nU"
+ #"m\201\305\314\2313i\336\331\t\324\342\373\367\357\b\241\372\372z\325"
+ #"\26\316\236=\3130\f\3030\257^\275\242\321g\20B\252\235a\264\267\267"
+ #"\e\f\6EE\354v\273N\247\3\0E\336\325\307\225\205\301`\b\f\fTT\4\23U\n"
+ #"\r\270\2@CC\303\247O\237(\225\31\206\301\27K\227.U\346\306\361\226"
+ #"\2011o\336<JM\325\256\265\211+\0l\330\260!<<\334\323\323\223a\30\275"
+ #"^\357\343\343\23\30\30x\350\320\241\242\242\242\246\246&\236\362\344"
+ #"\311\223\221\212v\242\364\345\310\241rvv&\273suu]\276|\271J/\332r\5"
+ #"\00077\267\261c\307\32\f\6\17\17\17\2i''\247\314\314\314\277\3155??"
+ #"\37S$\253577\27\24\24\254Y\263\206\313\330f\263\321;\322\200+\0\254"
+ #"\\\271RE\301s\347\316)\252\204\332\264\255k\327\256\251(E\337\315ah"
+ #"\303\225\\5\245\360\376\375{E\372\232\365Y\\\364\366\366J\211\20\247"
+ #"!~\370\360A\221Y\r\362\1\206\351g\4\17KRf\271\312^^^f\263"
+) 500
+(
+ #"\231\236\200\366q%\373\346J\273\272\272\24%\6\3R\a(C\325\323\323\243"
+ #"\327\353\351\315\16\bWz\f\e6\214^\371?\346\32\31\31I\257\374\37sU\4"
+ #"\355\271\326\325\325\5\5\0051\2\b5E\37\22 \223\26\251@pp0\245\346"
+ #"\344\311\223\333\332\332\350-k\20Wax\"\"\"n\334\270a2\231\254V\253"
+ #"\311djll\274t\351\222\260`HH\210\262\341@E\316\301\303\335\273wU\224"
+ #"\2324i\222R\2\32pU\264R\364\366\355[^\260ZZZ\26-Zt\373\366m\331\262"
+ #"\232\315\267d\261`\301\2\a\177\341\1\344j6\233\203\202\202\350k\243"
+ #"\335n\37@\256\356\356\356\nZ\206\30\302\303\303\337\275{\207\20Z\261"
+ #"b\205lh\35\352\a\314f\263\272\202\36\36\36\a\17\36D\b=~\374\330\337"
+ #"\337\37\0\2\2\2dK)\350_\273\273\273\277~\375ZZZ\372\345\313\227\246"
+ #"\246\246\353\327\257+\342\267j\325\252\177\376\371'>>^4\267b\273\5"
+ #"\22h~\353A\203\6)\242\305\242\250\250\250\247\247\207\306\305\203\a"
+ #"\17d\311\320\326\327\254\254,.\t\235N\267q\343\306\214\214\214\262"
+ #"\2622\234/;\210\327\257_\3\200\311d\322\200kWWWww7{\233\220\220\340"
+ #"\0205\1ZZZp\24\202\203\203+**Dud\332\226\237\237\37\316<\364z\275"
+ #"\233\233\e\3030c\306\214\1\0\27\27\27u\265B\n\b!\0())\251\255\255MKK"
+ #"c\30\346\316\235;<\35I\256\376\376\376\f\303|\376\374\31_\263\357"
+ #"\372\361\343GmYbtvv\2@GG\a\3030\205\205\205mmm\a\17\36d\30&,,\214"
+ #"\325\21\357\a\330t\244\247\247Gt\211j\330\260aIIIiiiZq\345%\\\6\203"
+ #"\1\257\230s\23#\21\36\335\335\335\370\2IO\233\364z\375\233"
+) 500
+(
+ #"7o\264\241\t\0\0\337\276}\223\325\21\251\3eee 7\277\323\353\365\332V"
+ #"\6\\\331\274\275\275\t:\"\\\355v;\215\365\236\236\36u\264D\321\336"
+ #"\336\16\0\236\236\236\4\35\21\256K\226,\2215\355\345\345\245\232\226"
+ #"(\236<y\2\0\323\247O'\350\250\317\aF\215\32\245\272\254\20\270%)\256"
+ #"\0034\360\360\360P\272OD\306\217\37?duTrmmmU\272OD\206\315f\223\325"
+ #"\21_{\343-\247\t\341\345\345\365\343\307\17\rG/\251\25;.\23\225\\e"
+ #"\25\224\202\206\353\377\367\272\213\n|\377\376\235FM\204+\36B\b\320v"
+ #"\24\0\200\322\322R\0\2308q\242\214\2360M\2342e\212\350s\26\231\231"
+ #"\231d\5\245\300m4==](\342:\22q)\365\16,\206\17\37\256-W\354\261\276"
+ #"\276^T\364\347Z\252\244\250\321\23'N\20~\20\325 \30\344>\247\235\307"
+ #"\272\272\272j^Me\301\333\317\341\267-QB\f\303\260\317\253\253\253"
+ #"\265%\204g\205\242\340\rf|\256x\226\23\32\32*Z\30!\324\320\320\3400"
+ #"\275~HMM\225\22\311p\305+\24\341\341\341\302\2228\t\222\355\321\224"
+ #"\342\376\375\373R\"\31\256xf\262h\321\"a\311\2337o\202\3\353BR\300"
+ #"\263BQ\360\23\32\232&\t\0\353\326\255\303\327{\367\356\25\325q\260"
+ #"\23\210\210\210\20\212pUfoi\307\330\213\27/\342\213\301\203\a\323"
+ #"\307\214\36\261\261\261\302\207\274\337\220\226+;\23\322|\366\2021m"
+ #"\3324\341C\324?\355R\234\273h\313\225\255\254\v\27.\24JIq\315\315"
+ #"\315\5\0\336\344\4\37pd1a\302\4-H\366!##\203 5\231L\334\333~\\kjj@p"
+ #"\304\253\274\274\234{\353\370Z6\27\35\35\35\4)o7\252\37\327+W\256\0@"
+ #"tt4\367\341\356\335\273\271"
+) 500
+(
+ #"\323v\37\37\37\r8\376\v\362\224\2207\210\366\343\212k\317\2349s\330'"
+ #"\305\305\305v\273}\307\216\35\354\23u\307E\244@^\274\371\365\353W"
+ #"\277{\251\316\225]\325\342\351\260uH\223\316\225\373\346Bivv6H\365"
+ #"\257x\307\21/\270\272\271\2719\0220JX\255V\202\224\267\264\341\f\0"
+ #"6\233m\320\240A\334@r\301\353\244\310\255A[\360\332\261S\\\\\234\213"
+ #"\213\213\24Q\0\350\354\354\344\276\37a\370\326\34\274\250;\345\345"
+ #"\345\2617\302\235\273\352\352\352\223'Ovvv2\f3\177\376|P~\250\212\6)"
+ #"))\242\317\277|\371\322\357~\317\236=aaa\344\26p\367\356]\254\214\20"
+ #"\332\266m\e{\335\332\332J\263\250\210\21\20\20\20\23\23s\354\330\261"
+ #"\364\364\364-[\266pE\b\241\254\254,\235N\347\344$2\216\2624@\247\323"
+ #"%&&\222\271\262\355\fq\366\322\265\202N\247\353\243\"\201?\375@oo"
+ #"\257\354\20\217k3\36E\204\ao1\30\206\211\214\214|\372\364\251\325jMJ"
+ #"JZ\265jUNN\16\353\306b\261Hu\314l\222\212\20\32;v,\276\346*\377\376"
+ #"\375\273\357\312\331\331\371\350\321\243\344\270b\315S\247NI\275}KK"
+ #"\213h\301\252\252\252\303\207\17\357\332\265+!!\341\305\213\27F\243"
+ #"\261\245\245\5\2175\301\301\301\253W\257\226u\212q\346\314\31\204P"
+ #"\337\330@(SRR\2\0\215\215\215<Cqqq\3447\354\352\352\"H]\\\\\306\215"
+ #"\e\307{gww\367\3\a\16\30\215F\241\221\321\243G\3B\210\320\266\216\34"
+ #"9\302\376@<\2348q\202\314\265\267\267\227 \345\366\203K\226,\251\251"
+ #"\251![\333\277\177?`\243R1\300\266\356\335\273'\24=|\370\220l\35!TYY"
+ #")%b\203\352\344\344$k\a!\224\222\222\322\27\2605"
+) 500
+(
+ #"k\326\3606\244\361\242\225TP\21B?\177\376\224u@\250]\270\267\6\0///"
+ #"\32\256s\347\316\355g\v\347\332,\2\2\2h\254\220\271\376\376\375[Tt"
+ #"\372\364i\354\345\302\205\v\224\246\372\365\275\353\327\257G\bUUU]"
+ #"\276|\271\255\255M\252{R\4)#\354\n&\315\361\307\364\364t\0M\227\320D"
+ #"\203\221\232\232**b\307\352g\317\236\221\215\334\272u\253\217\362\0"
+ #"0\374\3\0000\30\f\4)\0\224\224\224\310\32\371K\\\261\v\321\263\e\0"
+ #"\220\227\2277u\352T\204\220\325j\335\267o\337\214\0313\244\16D\32"
+ #"\215\306\277\3045))ITz\376\374y\362d\323\325\325\365\217\376\337\341"
+ #"\212\203\307\203N\247\v\t\tA\b%$$\0\0\3030~~~\261\261\261\307\216\35"
+ #"\23\267\366w\270\212V\266\331\263g\263I\26\2255u$\36=zDe\235\310\265"
+ #"\265\265UQ\203Q\271\277\245\311\241\fE\a\313A\365^\234\242\325m\2556"
+ #"\32Tr\2459\236\302B\263-\6\372\352\302\205\257\257/\215\32\0\214\349"
+ #"\22'\371R\n\271\271\271\224NUruqq\241\262\16\260s\347NBP\0\0w[4PY\a"
+ #"\350\253\240\354\261\370\227/_R\232\32\360}n\362\21\26E\30p\256\25"
+ #"\25\25Z\231\32p\256x\277\35\237\230\24b\331\262e\364\246\6\234\353"
+ #"\317\237?\1`\356\334\271\242R| \253\253\253\213\306\324\200s\265X,\0"
+ #"0k\326,Q\351\376\375\373\341\337]>Y\f8W\274\256\350\347\347'*\305-Ox"
+ #"\324U\34\264=j\177p\323J\2X/\345\345\345d\35\32k*\343:t\350PE\372J?"
+ #"\177\22\205J\256\362\347h\6\0*\271\322\177<\202\367o5\331\35W\306u"
+ #"\361\342\305\f\303\214\e7.&&\206\240f2\231\330\377\374(,,\4\200\347"
+ #"\317\237"
+) 342
+(
+ #"\253\246\370\a\264\255\t!\274\242\30\32\32j4\32\267o\337\3165\22\32"
+ #"\32\32\37\37\177\372\364\351\374\374|L\216k\37\244\27\202\270j\351"
+ #"\351\351W\257^%\20P\362\251\227\222w\343\222\300\211\271P'11\221\367"
+ #"J\0p\374\370qG\271\262\25\216R\337f\263\231\315\346\250\250(\350?"
+ #"\337\262\331l\211\211\211\274\3566::\32!\324\334\334<b\304\bB\266I"
+ #"\353{\310\220!\0000b\304\bJ}\26\354v\5\315\337\"l\332\264\t\0:::\304"
+ #"MQVk\234\260\342\277pP\4v\345\237\346\323m\34\221\312\312JQ)-W\354I"
+ #"\352,\24\18w\241<y\202\2671\244>\356\244\345\212O&)\335\244e\207+"
+ #"\312\357\0\212\213\213\201\260\371\255\250\362\361\364-\26KNN\316"
+ #"\332\265ki\16\226\310\32gO)dgg\213{W\304\325h4\322\204\207\305\370"
+ #"\361\343\353\352\352\310\\-\26KAA\1w\252\363\371\363g\r\270\"\2123"
+ #"\332111W\256\\\261X,X_x\336\340\366\355\333\311\311\311\370\224\255"
+ #"\20\311\311\311\222\256\225r\305\260\333\355&\223\311l6\323\364D\224"
+ #"?BTT\24\371\263\323\377\1\250\227\355f\254\315s9\0\0\0\0IEND\256B`"
+ #"\202"
+) 0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 20 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 4 #"doll"
+0 0 66 3 1 #" "
+0 0 20 3 4 #"9.95"
+0 0 66 3 1 #" "
+0 3 21 66 1 #"\0"
+2 -1.0 -1.0 0.0 0.0 0 5 500
+(
+ #"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\0T\0\0\0u\b\2\0\0\0_\371Q\5\0\0\baI"
+ #"DATx\234\325\\_HS\357\e\177\217\231\332\\[h\00313m\264j!\254\314V"
+ #"\220F--\252\v#\f\242\302\274\20\262\b\212\f\274H\"\"\250 \272\311"
+ #"\253\376\b\321E\27%\366\207B\363b\375!\212\32\264\213\246i\323L\233"
+ #"\2469k\233f\233\353\375^\274\277\316\357\264\271\355l\347y\316\231"
+ #"\237\253\355\374\371<\317s\236\347}\337\347\375\313QJI2!??\177``\200"
+ #"\20\242\321h~\376\374\211*+\5\225=\0010\313\t!\36\217'==\375\375\373"
+ #"\367x\262\270d\363<\307q!WV\256\\\351p80d%\235\347\351_tww\263+\235"
+ #"\235\235{\367\356\305\220\225t\236\17A\177\177\177AA\1!\4CO%=\237"
+ #"\225\225\305\t0\3433K\226,\241\224>x\360\0E\3\252\20\334n7!\204\343"
+ #"\270\246\246\246\307\217\37\23B\32\32\32d\326A\261\260\337\272ukff"
+ #"\346\375\373\367\371+Z\255\26\273m\vA\252\234\302\204\350\352\352\32"
+ #"\34\34\24^)++\223Y\a\305<\177\352\324\251\214\214\214s\347\316)\""
+ #"\235A\311\332\236\343\270\17\37>\30\215F\245\24P\270\235_\265j\325"
+ #"\263g\317\224\222\256\244\347m6\333\332\265k\211\2106\234\343P\364T"
+ #"\254\302#\204\24\27\0273\223\204\215\274\320H\376:R;\237\24\31^\244"
+ #"\f\207\a\222\222I\221\333SJ].\327\262e\313\302o\231L&D\367\310\234T"
+ #"\305DEEEJJ\n!d\371\362\345\330\262\222\"\354\225BR\204\275R\230\255"
+ #"\306\373\375\376\232\232\32.2\366\355\333\347p8\376\374\371\23\215\5"
+ #"\273\\a \336/u\372\364\351\231yd\326;\34\323\323\323\337\276}\23\363"
+) 500
+(
+ #"\344\376\375\373\2311\375\375\375\"\311\207\206\206v\354\330!\374\20"
+ #"\255\255\255\374]e\214\267\331l\221\274\364\365\353\327Ho\2358q\342"
+ #"\356\335\273\211I\274z\365jFF\6/\245\242\242\202\312o\374\372\365"
+ #"\353\305\4\352\272u\353\220\24\370G\f\222\214\230\202\315f\263\325j"
+ #"\25\336u\273\335\365\365\3652\350f\265Ze5\236\rZ\361\350\350\350\210"
+ #"\364dss3\377\330\355\333\267\221\364\31\36\36&2\344\366|\336^ZZ\372"
+ #"\374\371\363\304\336ER\22\267\235W\253\325\354\a\2454^\313\331[\26"
+ #"\213\205\210\350\371$\b\244\270\242\224\356\332\265\vD\4\236\236X"
+ #"\375y\255V\353\361x\bD\304RJ\221<\17\37\366>\237\217\3438\217\307#"
+ #"\364\233D0\373\323\322\322@\330x\300Wx\314K\340\264\32\215\306\353"
+ #"\365\302\322\2{\36\311rB\b+D\327\257_\a\344\204\364<\263<//\217\237c"
+ #"\a\a\354H&X\205\207\347s!\366\354\331\3I\a\322f\234<y\22\212*&>}\372"
+ #"\4E\5P\346_\277~}\371\362e*\327p\30\340$\207T\343\17\37>\274a\303\6"
+ #"\20UD\342\325\253WPT\222\312<+\347\273w\357nii\1\322'6\276\177\377"
+ #"\16E%\265\302{\364\350\321\316\235;AT\21\t\266J\5\6\t\327\26g\316"
+ #"\234)//\207\252{\304\243\275\275\35\212*\361f\23i\3620&\6\6\6\26/^\f"
+ #"B\225H\330\263\242\16\233l\211\27\r\370\305\343\346JOO\367\373\375\6"
+ #"\203\341\343\307\217PJ\304%\375\367\357\337Plq\e/O&7#jjjrss\317\237?"
+ #"\17E\230\210\361\212X\336\336\336\276m\3336X\321qX\242\240\317\t\316"
+ #"G\27\233\3411\313KJJ`\305\213Dee\345\347\317\237\341y\305\264\207l"
+ #"\205\344\2349s\240\32\330\270\300j8"
+) 500
+(
+ #"\ffQ\261\244`\300\367\365\365-]\272\24Iz\354v\376\332\265kH\262c\202"
+ #"\37\267\34\37\37G\21\20=0\304<\223\0~\375\372\25\345\256\313\345\312"
+ #"\313\313c\242C\246\264`\21\315\363\354\303o\331\262\5\374\213[\255"
+ #"\326\355\333\267G\21\312@\261\303-\322Waw5\32\r\322W'\204TUU\365\366"
+ #"\366\216\214\214\\\272t)33S\250Unn.\222\334\177t\230\361\352\255["
+ #"\267\br\365\36\311\31\t\317\300'\200\320\332\336h4vvv\22\345\222\319"
+ #"\221b2\2318\216+...**\3428\216Y\16\233\314\0vE\320\361\344\311\23"
+ #"\330\350\312\311\311\241\224\366\366\366\212\17\351`0\350t:a\325\b\a"
+ #"\311\316\316F\265\234RJ\376V\253\204\220\2337oFyrllL\245R\2058\303"
+ #"\345r\201\253\364?}\220x\205hkk\23\376\235;wn\244\240+))\231\232\232"
+ #"\22>\334\323\323\303na(\246\330\362\323\356\356\356\276\276\276\224"
+ #"\224\24\275^\317\22\330(P\253\325>\237\17\\\at\343\3\201@\24W+\v\364"
+ #"\345\247\251\2510\323\201~\277\37\204G\210Y\263\352Z\311\301\f)\300"
+ #"\352\223I\206\34\306\267\266\266J'ihhp:\235\322y\376\1F\23\22\2\220"
+ #"\211\35\257\327{\364\350Q\351<B\310Q\346\215F#\310\356\177\330A{\"O"
+ #"\330\257Y\263\6\204\207_\330\a\59\214\327\353\365 <G\216\34\1\341"
+ #"\341!\207\361\205\205\205 <\26\213\345\335\273w T\fr\30?\177\376|("
+ #"\252\3\a\16@Q\221Y\267\301htt\24\220M\16\343GFF\240\250ZZZ\0g\207"
+ #"\345\330H\374\345\313\27(\252M\2336\31\f\6\376\24\31\211\220\303\363"
+ #"?~\374\0d\343{\370\322!G\222\223\223\223\303\266u\200`zz\32\252\2478"
+ #"\313j{\2\327G"
+) 500
+(
+ #"&\362\30\37s\240&^@\305\221\34\306WVV\302\22\212\334\234\27\e\260"
+ #"\375\244p`\214\275^\270p\301\357\367K\347A\367\374\275{\367\3009\217"
+ #"\35;\326\324\324$\235\a\275\266\317\316\316\36\e\e\3\247\5\31\325"
+ #"\222cS!\206\b\220\301l\364\260GZ\220\355\363\371\216\37?.\221d\326"
+ #"\214\336\206CzL\315\262^\235\20\v\26,\220\310\200k|[[\e\36\371\215\e"
+ #"7\244RHo-\243\0\233\277\252\252J\312\353\210e\336\343\361\224\226"
+ #"\226\332\355v$~\"\271\330#\366\347W\254X\321\325\325\205\307O$\257 A"
+ #",\363CCC\32\215\6\217\237\20r\350\320!)\257c\205}ZZ\332\2337oV\257^"
+ #"\215A\16\5\24\317766\6\2\201$\267\234 y\236\343\270\262\2622\31\316w"
+ #"\2248\252\203U\346\37>|\210\304,\204\324\357\v\321\334\206\342\342"
+ #"\305\213\30\264\341HMM\225\364:\220\17\376\217\362\362\362\247O\237"
+ #"\202\323\206C\257\327_\271rE\n\3\312\261\21\340\234H\202\340\313\374"
+ #"\302\205\v\3019\303\1r~\n\274\361\330Y\35\371k9;EC\22\17l\210NNN\206"
+ #"\257\37\5\304\324\324\324\274y\363\b\320\242p`\317\253T*vv)\0066o"
+ #"\336\fh9\301\350\330 \325v|!\257\253\253\3#\225\334\326\206\242\260"
+ #"\260\360\355\333\267\200\204g\317\236\345\265\35\37\37\adFIr\230\242"
+ #"\215\215\215RHB\346\341\241t\23\2\205TX\347\305\373\256\333\355\326"
+ #"\351tB\263\233\233\233\21t\244\24i\306fbb\202_9\304q\234\230\223}"
+ #"\202\301`GG\207V\253\315\312\312\342\327\236\214\216\216RJ\27-Z\204"
+ #"\241$!\230cl!3J\6\203\201\235\354%D \20\350\351\351\231\361\2703v"
+ #"\3047\245\264\276\276\36IC,\343\371#\341(\245/^\274\210\231"
+) 202
+(
+ #"\220\251T\252\203\a\17\316\270\323rbb\302\351t\n\347\271\241\224D\31"
+ #"\303\v\6\203w\356\334\251\255\255e\1777n\334\310\216]\366x<6\233\315"
+ #"\341p\f\17\17\27\24\24\30\f\206\242\242\242\230\303\357:\235nrr\222"
+ #"\377\v\271\32\r\352+\na\267\333\a\a\a\241\330\230\236\371\371\371"
+ #"\265\265\265!;p\2442\3r\361\250\256\256\6d\253\253\253\3d\23\2 \267"
+ #"\177\371\362\245\305b\t\337\6\"\235\31\e\222\312\274\335n7\231L\302+"
+ #":\235\256\272\272\332l6\233\315fi\212\311\1I\236\347\353p\265Z\355"
+ #"\365z\201T\222\17\211'9\314r\266\3s6ZN\b\371\17\24\274S\2\f\350I\266"
+ #"\0\0\0\0IEND\256B`\202"
+) 0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 26 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"rocket"
+0 0 66 3 1 #" "
+0 0 20 3 5 #"59.95"
+0 0 66 3 1 #" "
+0 3 21 66 1 #"\0"
+2 -1.0 -1.0 0.0 0.0 0 5 500
+(
+ #"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\0003\0\0\0u\b\2\0\0\0l\302N\f\0\0\b"
+ #"9IDATx\234\315\233[H\24_\34\307\177\353\256m\333n\332\305Z\273mIX"
+ #"\202\31\226\255\21E\322B\241ADR\30X`\5BDB/A\21R\21\24\4\322\205\324"
+ #"\207\350\16\25\21t\243\202B\"\272\240\17=\264eXRY\232!\262\233i\271"
+ #"\272\332\371?\374\326\343\354\354\\\31693\343\376\277/;s.\277\363"
+ #"\231\337\271\314\271\314\332\b!`\231\334n\367\237?\177\304\362\246"
+ #"\230\213\"Uii\351\337\277\177\205\263;LD\221\312f\263\31\264`\211"
+ #"\317\244X\302\210\26\326&\312\351t^\271rE$'1U2\17\345\346\346b\17"
+ #"\313\316\316\3465e&\331\266m\333\244Xyyy\30\276u\353V\1\27\230F\326"
+ #"\321\321!\305\272x\361b\\1\0~\277?9d3f\314\320h$\225\225\225\274n"
+ #"\263\21\223FZi\vS\264i\263\361\225eN\337\334\276};\275^\273v\255b"
+ #"\232\23'Np\3314\301gCCC\251\251\251\364V\315`ss\263\317\347\363x<"
+ #"\254v\215\2670Y=j\250\274\274\234\335\254Q2\256\207\4\200\262\2622V"
+ #"\313\306\300F\3116o\336\314\222x\362\344\311\254\226\215`\235;w\216"
+ #"\253Up\265\37C=@w\244\220\311\341p\f\17\17wvvfff\352&\266\374\215."
+ #"\325\223'O\0 ++\213)\265pUJ\235t\373\366m\256,L)\205\261B\241\20\26S"
+ #"XX\310\236\353\300\201\3\0\320\325\325e!\331\316\235;\221\254\273"
+ #"\273\233=\327\347\317\237\1\340\310\221#V\221\235={\26\261\262\262"
+ #"\262x\3632V\250 \231\327\353\305\2\232\233\233y\363.]\272\324B2#\35"
+ #"\350\321\243G,\31E\3063BHJJ"
+) 500
+(
+ #"\n\0\270\\.\261u\e\313\214Hd<;\177\376<^\24\27\27\vdg\225@u\30\311"
+ #"\213\n\4\2\17\37>\324)E\300\256q\262k\327\256\25\24\24h\247\341ng"
+ #"\321ht\334\270q\224L\254\242\320\210vv\356v\206=\313\240p\16\374\346"
+ #"\315\e\2154\334>\343\235_h\330\261\333\355CCCj\t\306t\256!\323\360"
+ #"\360\260F\2548YQQ\221p^\26\211\223m\330\260\301x\361_\276|Q\215\343"
+ #"\355\360\302\31\25\355\344\347\347\253&\20\263X\\\\l\f\2148\235N\355"
+ #"'\24\254M\351\242\\L\313\226-\323N\300Gv\343\306\r\274\b\4\2\202D#Z"
+ #"\271r\245N\n\256*\310\317\317\27\310\245(:d\334\277\177\337\204\332|"
+ #"\373\366-\277w\224\205\363(\0x\372\364\251r\n\256\a\305,n\267\333"
+ #"\270\317\b!>\237\17\0\\.\227b\254H\17X\267n\235\210\227\22\204\373Y"
+ #"\375\375\375\312\321\354\217\30\211D0\313\207\17\37L\361\331\313\227"
+ #"/5\308\310\36<x\300\3730\332\n\207\303\32\69j\363\365\353\327B\225"
+ #"\246\252I\223&i\304r\220\275\177\377\3360\f\2078\346gn\267\eWJ\354Y"
+ #"\364\213\267\331\324\fr\370\f\261\260\253\217\201\270G\215\377/\331"
+ #"\202\5\vL,\336n\267\3\200\342\234\233\233,''\307\4\242\21\341&\274r"
+ #"\337b\37~0}__\237\31cYL\370:\331\267o_b\24\267\317\334n\267!/\305k"
+ #"\316\2349\0 ;MC\261\222\365\365\365\231\bD\205d?~\374H\214b%kkk3\223"
+ #"(^\3645%\25+Ycc\243\25101M\2348\21\0\332\333\333\23\243X\311\276}"
+ #"\373f&Q\274\350,F*V\262\337\277\177\233\n\23\247\201\201\201\304\300"
+ #"$\223)z\v\305J\366\353\327/\223`\342\324\333\333\253\26\225\344Q\243"
+) 500
+(
+ #"\273\273[-*\231{A\240\331\261\222\334\316\24G\177T\222}\326\332\332"
+ #"\252\26\225d2\305\361\2\225d2\324\370\361\343\23\3\365\277?{\374\370"
+ #"qKK\213\5<\243\222~T1*\215\311\23\375\20\220\20\262b\305\n\335\364"
+ #"\272\232?\177~OO\2174\4m\372|\276\304\304\252>\v\207\303S\246L\201"
+ #"\221\205\215)}\263\265\265U\361\304i\372\364\351\211\211U\333\31buuu"
+ #"\341\255\306k\204K\204\220C\207\16\311\2\247N\235\312Jv\341\302\5\0("
+ #"//\2376m\32\206h\274FxE\317F\251\322\323\323\1`\375\372\365q\241\211"
+ #"\25\214\a\344\16\207C\32H\273\217\221v&m^\204\220\236\236\36\264I"
+ #"\327\1\322s\\yI\273w\357V$\320x\22a544\240\315{\367\356\321\300P("
+ #"\244@\326\331\331\211IO\237>m5\31\0\\\275z\25mvtt\320\360H$\22\211D"
+ #"\344d\32\305[\3413\\\6\3@4\32\225\206\327\327\327+\223566\216\r\31"
+ #"\235Y%Fedd\214\206j\27\214\37\f\254^\275\332D2\224\254\253Q\230\330"
+ #"\250\201\335$77W\251\233\3\0\314\235;\27\30\216\27\4\24\215Fe!\350"
+ #"\313\30Yuu5h\236\252fdd\0\300\314\2313M'\3\0\277\337/\275\305o\226cd"
+ #"g\316\234\201\221\25\263\242\262\263\263\1\200\16\274\346j\371\362"
+ #"\345t\23\30\0\366\354\331\3\0@\b)++\3\200\324\324T\215\326\200{\343"
+ #"\257^\2752\275\235\241\202\301\240\374\225Jojjj\2643\3@0\30\264\210"
+ #"\f\355\307\255\203\350nG\177\177\277n\316\266\2666\353\310._\276\34W"
+ #"\307{\367\356\245\316K.\31Q\334\230\266\333\355\377\a\262]\273v-Z"
+ #"\264\b\217ucd\263g\317f!{\367\356\235\245dtW\237\320=G\227\313\245"
+ #"\333\267"
+) 500
+(
+ #"\235N'\235\267X$\304\330\261c\a\320\361LcuE\345\365z\0257\aM\327\245"
+ #"K\227\0 \5w\227\177\376\374\251\233\241\260\260\360\372\365\353VcQ"
+ #"\245,Y\262\4\0\6\a\au\223\346\344\344\334\275{\327R\232\232\232\32"
+ #"\274\370\372\365+\34<x\20ot\233'\276\6,\355\1\263f\315B\230`0\230"
+ #"\302\372E\260\312J\332\\\321\r\230\t\23&\214\276\235\314z\356\364"
+ #"\364t\261\214\5\5\5\24\221\340\234\226\213L\367k\373P(\324\336\336.@"
+ #"&u^\214\f?\204\371\367\357\37\243\211[\267n\351\226\301\213U__O\261*"
+ #"++cd\363\346\315\3\0\331\216\203\232\26.\\\250\233F\200L\352\260p8L"
+ #"\360\35\260q\343F\0\370\364\351\23K#mii\261\331l6\233m\325\252U\32"
+ #"\311\214\314\313c\347\353ddEz\364\350Q\261G\244\262\333\355iii~\277"
+ #"\237B\vX\e\r$\204\340\361\342\226-[\330\311\6\a\a\217\35;\246\373"
+ #"\364F\311p7E\373\277+w\356\334I,\t\377#\241\241\343\307\217\e\"#z\3G"
+ #"mm\255\266\e4^n\\dk\326\254\341 \223mw\261\224\204\332\277\177?K\372"
+ #"\212\212\nE\343:d8!\241\222n\332\260\210\205\214\356ndff\262\222}"
+ #"\377\376]\212%0\325f!\243\366\353\352\352X\311\244Xb\337O555\325\326"
+ #"\326j$\220\316X\345\245\343\17\236\315\252a\t0I\355h\304\342?N\1\300"
+ #"\343\361(\223-^\274Xj\242\264\264\224b\5\2\1\203d\325\325\325\32\261"
+ #"\250\212\212\ne2\374\213\20^?\177\376\334,\207\21B\362\362\362\0@m"
+ #"\366AKI\374kR\254\340\252\252*\n\341p\214\36\22|\374\370\321 \31~"
+ #"\264YRR\242M\246\20\205?uuu\200\263\357\21y\275^\203LRy<\236"
+) 162
+(
+ #"\242\242\"Y \356/)62B\317P\320O8\35B\261\254\246\330\325\333\333+"
+ #"\373\23\375\300\300\0\235\335l\332\264)1Kl\275\231\226\226f\"\207"
+ #"\242JJJ\244\267'O\236\244\327\3623\n\24\272\356\346\315\233\322\300"
+ #"\206\206\6\23\253\222\352\331\263g\364Z\372}\221bb\371\0162\313\326"
+ #"\213\21\341\266\346\213\27/\22\275\243Jv\370\360a\0hjj\262\224\214("
+ #"\315:u\310\b!UUUVc\305J\345%\eKQ\254S\247N)&\370\17#l\0_X\204\310m\0"
+ #"\0\0\0IEND\256B`\202"
+) 0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 4 #"))))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 57 #";show-picture : symbol inventory -> mixed (image/boolean)"
+0 0 66 29 1 #"\n"
+0 0 17 3 56 #";Given name and an-inv, this function produces the image"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";of the toy with the corresponding name. If"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";the toy is not in the inventory, false is returned"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";instead."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"show-picture"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"false"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-image"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"show-picture"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 38 #";price-of : symbol inventory -> number"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";Given name and an-inv, it finds the price"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";of the corresponding toy with the name."
+0 0 66 29 1 #"\n"
+0 0 17 3 47 #";Returns 0 if the item is not in the inventory."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"price-of"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"price-of"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data Definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 39 #";A record (phone record) is a structure"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";(make-record s n) where s is a symbol and"
+0 0 66 29 1 #"\n"
+0 0 17 3 15 #";n is a number."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 13 #"define-struct"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"record"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"name"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"number"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 16 #";Data Definition"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 22 #";A directory is either"
+0 0 66 29 1 #"\n"
+0 0 17 3 20 #";1. an empty list or"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";2. (cons r dir) where r is a record and"
+0 0 66 29 1 #"\n"
+0 0 17 3 20 #";dir is a directory."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 42 #";whose-number : number directory -> symbol"
+0 0 66 29 1 #"\n"
+0 0 17 3 47 #";Given a-num and a-dir, finds the corresponding"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";name of the person who owns the number. If"
+0 0 66 29 1 #"\n"
+0 0 17 3 44 #";the person is not in the directory, returns"
+0 0 66 29 1 #"\n"
+0 0 17 3 28 #";the symbol 'NotInDirectory."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 31 #";(define (dir-func a-num a-dir)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #"; [(empty? a-dir) ... ]"
+0 0 66 29 1 #"\n"
+0 0 17 3 60
+#"; [... (first a-dir) (dir-func a-num (rest a-dir)) ...]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"whose-number"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-num"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 15 #"NotInDirectory."
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"="
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"record-number"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-num"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"record-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"whose-number"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-num"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";phone-number : name directory -> number"
+0 0 66 29 1 #"\n"
+0 0 17 3 54 #";Given name and a-dir, finds the corresponding number."
+0 0 66 29 1 #"\n"
+0 0 17 3 41 #";Returns 0 if no number in the directory."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"phone-number"
+0 0 67 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 67 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 67 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 1 #")"
+0 0 67 3 1 #" "
+0 0 20 3 1 #"0"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 67 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"record-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"record-number"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"phone-number"
+0 0 66 3 1 #" "
+0 0 14 3 4 #"name"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"a-dir"
+0 0 22 3 5 #"))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"list2"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-record"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 9 #"HsinyaLin"
+0 0 66 3 1 #" "
+0 0 20 3 10 #"6265939257"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-record"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 9 #"RonRonLin"
+0 0 66 11 1 #" "
+0 0 20 3 10 #"6267157010"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"make-record"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 8 #"TunaFish"
+0 0 66 3 1 #" "
+0 0 20 3 7 #"8888888"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 4 #"))))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 40 #";extract : inventory number -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 48 #";Given an-inv and price, it returns an inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 46 #";composed of inventory records (ir) which have"
+0 0 66 29 1 #"\n"
+0 0 17 3 27 #";prices greater than price."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 31 #";(define (extract an-inv price)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #"; [(empty? an-inv) ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 5 #"; "
+0 0 17 3 1 #"["
+0 0 17 3 3 #"..."
+0 0 17 3 47 #" (first an-inv) (extract (rest an-inv)) ...])) "
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extract"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #">"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extract"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extract"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 4 #")]))"
+0 0 66 3 1 #" "
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"RAISE"
+0 0 66 3 1 #" "
+0 0 20 3 4 #"0.05"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 38 #";raise-prices : inventory -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 51 #";Consumes an-inv and produces an inventory in which"
+0 0 66 29 1 #"\n"
+0 0 17 3 48 #";the price of each inventory record is increased"
+0 0 66 29 1 #"\n"
+0 0 17 3 18 #";by RAISE percent."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 17 3 9 #";Template"
+0 0 66 29 1 #"\n"
+0 0 17 3 30 #";(define (raise-prices an-inv)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 19 #"; [(empty?) ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 5 #"; "
+0 0 17 3 1 #"["
+0 0 17 3 4 #"else"
+0 0 17 3 51 #" ... (first an-inv) (raise-prices (rest an-inv))]))"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"raise-prices"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 66 29 1 #"\n"
+0 0 66 3 17 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 17 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"RAISE"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 17 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-image"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 66 3 16 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"raise-prices"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 6 #")))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 26 #";Contract, Purpose, Header"
+0 0 66 29 1 #"\n"
+0 0 17 3 39 #";recall : symbol inventory -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 50 #";Removes the inventory record (ir) associated with"
+0 0 66 29 1 #"\n"
+0 0 17 3 23 #";ty from the inventory."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 30 #";(define (raise-prices an-inv)"
+0 0 66 29 1 #"\n"
+0 0 17 3 8 #"; (cond"
+0 0 66 29 1 #"\n"
+0 0 17 3 19 #"; [(empty?) ...]"
+0 0 66 29 1 #"\n"
+0 0 17 3 5 #"; "
+0 0 17 3 1 #"["
+0 0 17 3 55 #"else ... (first an-inv) (raise-prices (rest an-inv))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"recall"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"recall"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #"))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"recall"
+0 0 66 3 1 #" "
+0 0 14 3 2 #"ty"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 6 #")))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 10 #"substitute"
+0 0 17 3 1 #" "
+0 0 17 3 1 #":"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"symbol"
+0 0 17 3 30 #" symbol inventory -> inventory"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 5 #"Given"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"old"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 3 #"new"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"an-inv"
+0 0 17 3 1 #","
+0 0 17 3 20 #" replace the name of"
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 2 #"an"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"inventory"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"record "
+0 0 17 3 4 #"with"
+0 0 17 3 24 #" name old with name new."
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"substitute"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 67 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 66 29 1 #"\n"
+0 0 67 3 3 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 67 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 66 29 1 #"\n"
+0 0 67 3 3 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 8 #"symbol=?"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"ir-name"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 66 29 1 #"\n"
+0 0 66 3 19 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 19 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-image"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 66 3 10 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"substitute"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 66 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 4 #")))]"
+0 0 66 29 1 #"\n"
+0 0 66 3 3 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 67 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 15 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"substitute"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"old"
+0 0 66 3 1 #" "
+0 0 14 3 3 #"new"
+0 0 67 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 67 3 1 #" "
+0 0 14 3 6 #"an-inv"
+0 0 22 3 6 #")))]))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0
blob - /dev/null
blob + c3c0261f061142511db6168cc073c3a87df55547 (mode 644)
--- /dev/null
+++ 10.3.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 10.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")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+;Template
+;fun-for-losh : list-of-shapes -> ???
+;Consumes a list-of-shapes.
+;
+;(define (fun-for-losh alosh)
+; (cond
+; [(empty? alosh) ...]
+; [(circle? (first alosh)) ... (first alosh) (fun-for-losh (rest alosh))]
+; [(rectangle? (first alosh)) ...(first alosh) (fun-for-losh (rest alosh))]
+; [else ...]))
+
+;draw-losh : list-of-shapes -> boolean
+;Consumes alosh and draws the shapes on the canvas,
+;returning true. If drawing fails, it returns false.
+
+(define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+;draw-a-circle : circle -> boolean?
+;Draws a circle given a-circle (struct circle).
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+; draw-a-rectangle : rectangle -> boolean
+; Returns true after drawing, consumes a-rect.
+
+(define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;translate-losh : list-of-shapes number -> list-of-shapes
+;Given alosh, returns a list-of-shapes that have translated
+;delta pixels in the x direction. This function
+;does not affect the canvas.
+
+(define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+;clear-losh : list-of-shapes -> boolean
+;Clears shapes corresponding to entries in alosh
+;and returns true. Does so by calling clear-a-rectangle
+;and clear-a-circle.
+
+(define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+; clear-a-circle : circle -> boolean
+; Clears a circle given a-circle, returns true if
+; evaluation completes successfully, false otherwise.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+; clear-a-rectangle : rectangle -> boolean
+; Clears rectangle specified by a-rect and returns true
+; if evaluation suceeds, false otherwise.
+
+(define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+;Data Definition
+;
+;A picture is a list-of-shapes?, I think.
+;
+;draw-and-clear-picture : picture -> boolean
+;Draws alosh, sleeps for a while, then clears alosh.
+;!!!CHANGE!!! Now it clears, sleeps for a while,
+;then draws alosh.
+
+(define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+; (sleep-for-a-while 2)
+ (clear-losh alosh)))
+;
+;move-picture : number picture -> picture
+;Draws a picture delta pixels to the right, sleeps for a while,
+;clears the picture, and then returns the translated picture.
+
+(define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false]))
+
+(start 500 100)
+
+(control-left-right FACE 100 move-picture draw-losh)
\ No newline at end of file
blob - /dev/null
blob + f3cbdd2f0eb55743c0d05d2059410503f7ebf538 (mode 644)
--- /dev/null
+++ 11.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.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")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+;Template
+;fun-for-losh : list-of-shapes -> ???
+;Consumes a list-of-shapes.
+;
+;(define (fun-for-losh alosh)
+; (cond
+; [(empty? alosh) ...]
+; [(circle? (first alosh)) ... (first alosh) (fun-for-losh (rest alosh))]
+; [(rectangle? (first alosh)) ...(first alosh) (fun-for-losh (rest alosh))]
+; [else ...]))
+
+;draw-losh : list-of-shapes -> boolean
+;Consumes alosh and draws the shapes on the canvas,
+;returning true. If drawing fails, it returns false.
+
+(define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+;draw-a-circle : circle -> boolean?
+;Draws a circle given a-circle (struct circle).
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+; draw-a-rectangle : rectangle -> boolean
+; Returns true after drawing, consumes a-rect.
+
+(define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;translate-losh : list-of-shapes number -> list-of-shapes
+;Given alosh, returns a list-of-shapes that have translated
+;delta pixels in the x direction. This function
+;does not affect the canvas.
+
+(define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+;clear-losh : list-of-shapes -> boolean
+;Clears shapes corresponding to entries in alosh
+;and returns true. Does so by calling clear-a-rectangle
+;and clear-a-circle.
+
+(define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+; clear-a-circle : circle -> boolean
+; Clears a circle given a-circle, returns true if
+; evaluation completes successfully, false otherwise.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+; clear-a-rectangle : rectangle -> boolean
+; Clears rectangle specified by a-rect and returns true
+; if evaluation suceeds, false otherwise.
+
+(define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+;Data Definition
+;
+;A picture is a list-of-shapes?, I think.
+;
+;draw-and-clear-picture : picture -> boolean
+;Draws alosh, sleeps for a while, then clears alosh.
+;!!!CHANGE!!! Now it clears, sleeps for a while,
+;then draws alosh.
+
+(define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+; (sleep-for-a-while 2)
+ (clear-losh alosh)))
+;
+;move-picture : number picture -> picture
+;Draws a picture delta pixels to the right, sleeps for a while,
+;clears the picture, and then returns the translated picture.
+
+(define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false]))
+
+(start 500 100)
+
+(control-left-right FACE 100 move-picture draw-losh)
\ No newline at end of file
blob - /dev/null
blob + 979dfd3ab84956e7f7928a56d057236937a0e237 (mode 644)
--- /dev/null
+++ 11.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.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")))))
+;A natural-number is
+;1. 0 or
+;2. (add1 n) where n is a natural-number.
+;
+;A list-of-symbols is
+;1. an empty list or
+;2. (cons s los) where s is a symbol and
+;los is a list-of-symbols.
+;
+;repeat : natural-number symbol -> list-of-symbols
+;Given a natural-number n, returns word n times
+;as a list-of-symbols.
+;
+;Template
+;(define (repeat n word)
+; (cond
+; [(zero? n) ...]
+; [else ... (repeat (sub1 n)) ...]))
+
+(define (repeat n word)
+ (cond
+ [(zero? n) empty]
+ [else (cons word (repeat (sub1 n) word))]))
+
+;; f : number -> number
+(define (f x)
+ (+ (* 3 (* x x))
+ (+ (* -6 x)
+ -1)))
+;
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn and lop is a list-of-posns.
+;tabulate-f : natural-number -> list-of-posns
+;Creates a "table". Returns a list of n posns of the form
+;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))...
+
+(define (tabulate-f n)
+ (cond
+ [(zero? n) empty]
+ [else (cons (make-posn (f n) n) (tabulate-f (sub1 n)))]))
\ No newline at end of file
blob - /dev/null
blob + 52ad5e78c3332171930134ce0f72349f56debd66 (mode 644)
--- /dev/null
+++ 11.2.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.3) (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")))))
+;A natural-number is
+;1. 0 or
+;2. (add1 n) where n is a natural-number.
+;
+;A list-of-symbols is
+;1. an empty list or
+;2. (cons s los) where s is a symbol and
+;los is a list-of-symbols.
+;
+;repeat : natural-number symbol -> list-of-symbols
+;Given a natural-number n, returns word n times
+;as a list-of-symbols.
+;
+;Template
+;(define (repeat n word)
+; (cond
+; [(zero? n) ...]
+; [else ... (repeat (sub1 n)) ...]))
+
+(define (repeat n word)
+ (cond
+ [(zero? n) empty]
+ [else (cons word (repeat (sub1 n) word))]))
+
+;; f : number -> number
+(define (f x)
+ (+ (* 3 (* x x))
+ (+ (* -6 x)
+ -1)))
+;
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn and lop is a list-of-posns.
+;tabulate-f : natural-number -> list-of-posns
+;Creates a "table". Returns a list of n posns of the form
+;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))...
+
+(define (tabulate-f n)
+ (cond
+ [(zero? n) empty]
+ [else (cons (make-posn (f n) n) (tabulate-f (sub1 n)))]))
\ No newline at end of file
blob - /dev/null
blob + 1b571e18c3529dbde8bcb2f34778e29595d49abf (mode 644)
--- /dev/null
+++ 11.2.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.3) (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")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+;Template
+;fun-for-losh : list-of-shapes -> ???
+;Consumes a list-of-shapes.
+;
+;(define (fun-for-losh alosh)
+; (cond
+; [(empty? alosh) ...]
+; [(circle? (first alosh)) ... (first alosh) (fun-for-losh (rest alosh))]
+; [(rectangle? (first alosh)) ...(first alosh) (fun-for-losh (rest alosh))]
+; [else ...]))
+
+;draw-losh : list-of-shapes -> boolean
+;Consumes alosh and draws the shapes on the canvas,
+;returning true. If drawing fails, it returns false.
+
+(define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+;draw-a-circle : circle -> boolean?
+;Draws a circle given a-circle (struct circle).
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+; draw-a-rectangle : rectangle -> boolean
+; Returns true after drawing, consumes a-rect.
+
+(define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;translate-losh : list-of-shapes number -> list-of-shapes
+;Given alosh, returns a list-of-shapes that have translated
+;delta pixels in the x direction. This function
+;does not affect the canvas.
+
+(define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+;clear-losh : list-of-shapes -> boolean
+;Clears shapes corresponding to entries in alosh
+;and returns true. Does so by calling clear-a-rectangle
+;and clear-a-circle.
+
+(define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+; clear-a-circle : circle -> boolean
+; Clears a circle given a-circle, returns true if
+; evaluation completes successfully, false otherwise.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+; clear-a-rectangle : rectangle -> boolean
+; Clears rectangle specified by a-rect and returns true
+; if evaluation suceeds, false otherwise.
+
+(define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+;Data Definition
+;
+;A picture is a list-of-shapes?, I think.
+;
+;draw-and-clear-picture : picture -> boolean
+;Draws alosh, sleeps for a while, then clears alosh.
+;!!!CHANGE!!! Now it clears, sleeps for a while,
+;then draws alosh.
+
+(define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+ (sleep-for-a-while 0.1)
+ (clear-losh alosh)))
+;
+;move-picture : number picture -> picture
+;Draws a picture delta pixels to the right, sleeps for a while,
+;clears the picture, and then returns the translated picture.
+
+(define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false]))
+
+(start 500 100)
+
+;A natural-number is
+;1. 0 or
+;2. (add1 n) where n is a natural-number.
+;
+;A list-of-symbols is
+;1. an empty list or
+;2. (cons s los) where s is a symbol and
+;los is a list-of-symbols.
+;
+;repeat : natural-number symbol -> list-of-symbols
+;Given a natural-number n, returns word n times
+;as a list-of-symbols.
+;
+;Template
+;(define (repeat n word)
+; (cond
+; [(zero? n) ...]
+; [else ... (repeat (sub1 n)) ...]))
+
+(define (repeat n word)
+ (cond
+ [(zero? n) empty]
+ [else (cons word (repeat (sub1 n) word))]))
+
+;; f : number -> number
+(define (f x)
+ (+ (* 3 (* x x))
+ (+ (* -6 x)
+ -1)))
+;
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn and lop is a list-of-posns.
+;tabulate-f : natural-number -> list-of-posns
+;Creates a "table". Returns a list of n posns of the form
+;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))...
+
+(define (tabulate-f n)
+ (cond
+ [(zero? n) empty]
+ [else (cons (make-posn (f n) n) (tabulate-f (sub1 n)))]))
+;
+;apply-n : natural-number list-of-shapes -> boolean
+;Applies the function move-picture n times to alosh.
+;Returns true if evaluation succeeds.
+;
+;Template
+;(define (apply-n n alosh)
+; (cond
+; [(zero? n) true]
+; [else ... (apply-n (sub1 n))]
+;
+(define (apply-n n alosh)
+ (cond
+ [(zero? n) alosh]
+ [else (move-picture 4 (apply-n (sub1 n) alosh))]))
\ No newline at end of file
blob - /dev/null
blob + 3386c76a71d910530cff3c4123426db4c62fdd2b (mode 644)
--- /dev/null
+++ 11.2.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.4) (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")))))
+A deep-list is either
+1. a symbol or
+2. (cons dl empty) where dl is a deep-list.
+
+depth : deep-list -> number
+Consumes a deep-list dl and determines how many
+cons were used to construct it.
+
+(define (depth dl)
+ (cond
+ []
+ []))
\ No newline at end of file
blob - /dev/null
blob + fe0a7e3eaef18a8ed91ce6a180e3cf5a3d934779 (mode 644)
--- /dev/null
+++ 11.2.4.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.4) (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")))))
+;A deep-list is either
+;1. a symbol or
+;2. (cons dl empty) where dl is a deep-list.
+;
+;depth : deep-list -> number
+;Consumes a deep-list dl and determines how many
+;cons were used to construct it.
+;
+;Examples
+;(depth (cons (cons (cons 'food empty) empty) empty))
+;3
+;(depth (cons 'food empty))
+;1
+;(depth 'food)
+;0
+
+(define (depth dl)
+ (cond
+ [(symbol? dl) 0]
+ [(cons? dl) (+ 1 (depth (first dl)))]))
+
+;Test
+;(define dl1 (cons (cons (cons 'food empty) empty) empty))
+;
+;make-deep : symbol natural-number -> deep-list
+;Consumes word and n to produce a deep-list
+;containing word constructed using n cons's.
+;
+;Examples:
+;(make-deep 'hey 3)
+;(cons (cons (cons 'hey empty) empty) empty)
+;(make-deep 'hey 0)
+;'hey
+;(make-deep 'hey 1)
+;(cons 'hey empty)
+;
+;Template
+;(define (make-deep word n)
+; (cond
+; [(zero? n) ...]
+; [(> n 0) ... (make-deep word (sub1 n))]))
+
+(define (make-deep word n)
+ (cond
+ [(zero? n) word]
+ [(> n 0) (cons (make-deep word (sub1 n)) empty)]))
+
blob - /dev/null
blob + 94df811dac0e0d128686c0d11a6bb279f58a154d (mode 644)
--- /dev/null
+++ 11.3.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;;Produces an intenger between n and m-1
+
+;; random-n-m : integer integer -> integer
+;; ...
+;; Assume: n < m
+(define (random-n-m n m)
+ (+ (random (- m n)) n))
blob - /dev/null
blob + 97dd3a993a39dc4830366a46513d6761e28a6676 (mode 644)
--- /dev/null
+++ 11.3.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;;Produces an intenger between n and m-1
+
+;; random-n-m : integer integer -> integer
+;; ...
+;; Assume: n < m
+(define (random-n-m n m)
+ (+ (random (- m n)) n))
+
+;Data Definition
+;A natural-number is either
+;1. 0 or
+;2. (add1 n) where n is a natural-number.
+;
+;A list-of-numbers is either
+;1. an empty list or
+;2. (cons n lon) where n is a number and
+;lon is a list-of-numbers.
+;
+;tie-dyed : natural-number -> list-of-numbers
+;Consumes a natural-number n and produces a list
+;with that many randomly numbers between
+;20 and 120.
+;
+;Template
+;(define (tie-dyed n)
+; (cond
+; [(zero? n) ...]
+; [(>= n 1) ... (tie-dyed (sub1 n))]
+; [else (error 'tie-dyed "Not a natural number")]))
+
+;Examples
+;(tie-dyed 0)
+;empty
+;(tie-dyed 1)
+;(cons (random-n-m 20 121) empty)
+;(tie-dyed 2)
+;(cons (random-n-m 20 121)
+; (cons (random-n-m 20 121) empty))
+
+(define (tie-dyed n)
+ (cond
+ [(zero? n) empty]
+ [(>= n 1) (cons (random-n-m 20 121) (tie-dyed (sub1 n)))]
+ [else (error 'tie-dyed "Not a natural number")]))
+
+;Contract, Purpose, Header
+;draw-circles : posn list-of-numbers -> boolean
+;Given p and a-list, draw-circles draws concentric circles centered at p
+;with radius given by the elements of a-list. Each circle is drawn
+;by calling draw-circle.
+;
+;Template
+
+(define (draw-circles p a-list)
+ (cond
+ [(empty? a-list) true]
+ [(draw-circle p (first a-list) 'red) (draw-circles p (rest a-list))]
+ [else false]))
+
+(start 200 200)
+(draw-circles (make-posn 100 100) (tie-dyed 1000))
\ No newline at end of file
blob - /dev/null
blob + a2ce2499a9a523a1dd9f3597ea60a6ccf0f8aaeb (mode 644)
--- /dev/null
+++ 11.3.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.3.3) (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")))))
+;;Produces an intenger between n and m-1
+
+;; random-n-m : integer integer -> integer
+;; ...
+;; Assume: n < m
+(define (random-n-m n m)
+ (+ (random (- m n)) n))
+
+create-temps : number number number -> list-of-numbers
+Creates a list-of-numbers consisting of n numbers between low and high.
+Example
+(create-temps 0 low high)
+empty
+(create-temps 1 low high)
+(random-n-m low (+ high 1))
+
+(define (create-temps n low high)
+ (cond
+ []
+ []))
+
+(
+
+(define
\ No newline at end of file
blob - /dev/null
blob + 003965ad109d7833cf8e69b60ebec03130b48a5f (mode 644)
--- /dev/null
+++ 11.3.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.3.3) (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")))))
+;;Produces an intenger between n and m-1
+
+;; random-n-m : integer integer -> integer
+;; ...
+;; Assume: n < m
+(define (random-n-m n m)
+ (+ (random (- m n)) n))
+;
+;create-temps : number number number -> list-of-numbers
+;Creates a list-of-numbers consisting of n numbers between low and high.
+;Example
+;(create-temps 0 low high)
+;empty
+;(create-temps 1 low high)
+;(cons (random-n-m low (+ high 1)) empty)
+;(create-temps 2 low high)
+;(cons (random-n-m low (+ high 1)) (cons (random-n-m low (+ high 1)) empty))
+;
+;Template
+;
+;(define (create-temps n low high)
+; (cond
+; [(zero? n) ...]
+; [(>= n 1) ...]
+; [else (error 'create-temps "expected 1st arg: natural number")]))
+
+(define (create-temps n low high)
+ (cond
+ [(zero? n) empty]
+ [(>= n 1) (cons (random-n-m low (+ high 1)) (create-temps (sub1 n) low high))]
+ [else (error 'create-temps "expected 1st arg: natural number")]))
+
+;Data Definition
+;A list-of-temperatures is either
+;1. an empty list or
+;2. (cons t los) where t is a number and los is a list-of-temperatures.
+
+;Header, Purpose, Contract
+;check-range1? : list-of-temperatures -> boolean
+;Given a-list, returns true if the list of temperatures are within the range
+;low and high (endpoints included as true).
+;
+(define (check-range1? a-list low high)
+ (cond
+ [(empty? a-list) true]
+ [(cons? a-list) (cond
+ [(and
+ (number? (first a-list))
+ (>= (first a-list) low)
+ (<= (first a-list) high))
+ (check-range1? (rest a-list) low high)]
+ [(number? (first a-list)) false]
+ [else
+ (error 'check-range1? "list should be composed of numbers")])]
+ [else (error 'check-range1? "expected 3 arg: list number number")]))
+
+;create-prices : natural-number number number -> list-of-numbers
+;Given a natural-number n, creates a list of n prices
+;between low and high rounded to the nearest
+;dime ($0.10). Creates this list by
+;making the function call random-dime.
+;
+;Examples
+;(create-prices 0 low high)
+;empty
+;(create-prices 1 low high)
+;(cons (random-dime low high) empty)
+;(create-prices 2 low high)
+;(cons (random-dime low high)
+; (cons (random-dime low high) empty))
+;
+(define (create-prices n low high)
+ (cond
+ [(zero? n) empty]
+ [(>= n 1) (cons (random-dime low high) (create-prices (sub1 n) low high))]
+ [else (error 'create-prices "expected 1st arg: natural-number")]))
+
+;random-dime : number number -> number
+;Given low and high, creates a number (decimal) between low and high
+;rounded to the nearest dime. It does so by choosing a random integer
+;between 0 and (high-low)/0.1, inclusive. So for example,
+;for low=0 and high=1, it chooses a number between 0 and 10 (inclusive).
+;It then multiplies this number by 0.1, the value of a dime.
+;This function thus returns us a number between $0.00 and $1.00,
+;rounded to the nearest dime.
+
+(define (random-dime low high)
+ (*
+ (random-n-m 0
+ (+ (/ (- high low) 0.1) 1))
+ 0.1))
+
+;
+;dollar-store? : list-of-numbers -> boolean
+;Checks a-list to see if the prices are below 1. Returns true
+;if the statement is true, false otherwise.
+;
+;Template
+;(define (dollar-store? a-list)
+; (cond
+; [(empty? a-list) ...]
+; [(cons? a-list) (first a-list) (rest a-list)]))
+
+(define (dollar-store? a-list)
+ (cond
+ [(empty? a-list) true]
+ [(cons? a-list) (cond
+ [(and
+ (number? (first a-list))
+ (< (first a-list) 1))
+ (dollar-store? (rest a-list))]
+ [else false])]))
+
+;eval-until-true : natural-number number number -> boolean
+;Keep evaluating (dollar-store? (create-prices n low high))
+;until it returns true.
+;
+(define (eval-until-true n low high)
+ (cond
+ [(dollar-store? (create-prices n low high)) true]
+ [else (eval-until-true n low high)]))
\ No newline at end of file
blob - /dev/null
blob + 886f4f96ea622d83a54c7682945cc7fffe67aed9 (mode 644)
--- /dev/null
+++ 11.3.5.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.3.5) (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")))))
+;;Produces an intenger between n and m-1
+
+;; random-n-m : integer integer -> integer
+;; ...
+;; Assume: n < m
+(define (random-n-m n m)
+ (+ (random (- m n)) n))
+;
+;create-temps : number number number -> list-of-numbers
+;Creates a list-of-numbers consisting of n numbers between low and high.
+;Example
+;(create-temps 0 low high)
+;empty
+;(create-temps 1 low high)
+;(cons (random-n-m low (+ high 1)) empty)
+;(create-temps 2 low high)
+;(cons (random-n-m low (+ high 1)) (cons (random-n-m low (+ high 1)) empty))
+;
+;Template
+;
+;(define (create-temps n low high)
+; (cond
+; [(zero? n) ...]
+; [(>= n 1) ...]
+; [else (error 'create-temps "expected 1st arg: natural number")]))
+
+(define (create-temps n low high)
+ (cond
+ [(zero? n) empty]
+ [(>= n 1) (cons (random-n-m low (+ high 1)) (create-temps (sub1 n) low high))]
+ [else (error 'create-temps "expected 1st arg: natural number")]))
+
+;Data Definition
+;A list-of-temperatures is either
+;1. an empty list or
+;2. (cons t los) where t is a number and los is a list-of-temperatures.
+
+;Header, Purpose, Contract
+;check-range1? : list-of-temperatures -> boolean
+;Given a-list, returns true if the list of temperatures are within the range
+;low and high (endpoints included as true).
+;
+(define (check-range1? a-list low high)
+ (cond
+ [(empty? a-list) true]
+ [(cons? a-list) (cond
+ [(and
+ (number? (first a-list))
+ (>= (first a-list) low)
+ (<= (first a-list) high))
+ (check-range1? (rest a-list) low high)]
+ [(number? (first a-list)) false]
+ [else
+ (error 'check-range1? "list should be composed of numbers")])]
+ [else (error 'check-range1? "expected 3 arg: list number number")]))
+
+;create-prices : natural-number number number -> list-of-numbers
+;Given a natural-number n, creates a list of n prices
+;between low and high rounded to the nearest
+;dime ($0.10). Creates this list by
+;making the function call random-dime.
+;
+;Examples
+;(create-prices 0 low high)
+;empty
+;(create-prices 1 low high)
+;(cons (random-dime low high) empty)
+;(create-prices 2 low high)
+;(cons (random-dime low high)
+; (cons (random-dime low high) empty))
+;
+(define (create-prices n low high)
+ (cond
+ [(zero? n) empty]
+ [(>= n 1) (cons (random-dime low high) (create-prices (sub1 n) low high))]
+ [else (error 'create-prices "expected 1st arg: natural-number")]))
+
+;random-dime : number number -> number
+;Given low and high, creates a number (decimal) between low and high
+;rounded to the nearest dime. It does so by choosing a random integer
+;between 0 and (high-low)/0.1, inclusive. So for example,
+;for low=0 and high=1, it chooses a number between 0 and 10 (inclusive).
+;It then multiplies this number by 0.1, the value of a dime.
+;This function thus returns us a number between $0.00 and $1.00,
+;rounded to the nearest dime.
+
+(define (random-dime low high)
+ (*
+ (random-n-m 0
+ (+ (/ (- high low) 0.1) 1))
+ 0.1))
+
+;
+;dollar-store? : list-of-numbers -> boolean
+;Checks a-list to see if the prices are below 1. Returns true
+;if the statement is true, false otherwise.
+;
+;Template
+;(define (dollar-store? a-list)
+; (cond
+; [(empty? a-list) ...]
+; [(cons? a-list) (first a-list) (rest a-list)]))
+
+(define (dollar-store? a-list)
+ (cond
+ [(empty? a-list) true]
+ [(cons? a-list) (cond
+ [(and
+ (number? (first a-list))
+ (< (first a-list) 1))
+ (dollar-store? (rest a-list))]
+ [else false])]))
+
+;eval-until-true : natural-number number number -> boolean
+;Keep evaluating (dollar-store? (create-prices n low high))
+;until it returns true.
+;
+(define (eval-until-true n low high)
+ (cond
+ [(dollar-store? (create-prices n low high)) true]
+ [else (eval-until-true n low high)]))
\ No newline at end of file
blob - /dev/null
blob + 2b8cbd832992aff7e9a76e50689da83f41e461bf (mode 644)
--- /dev/null
+++ 11.3.5.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.3.5) (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")))))
+;;Produces an intenger between n and m (both endpoints included)
+
+;; random-n-m : integer integer -> integer
+;; ...
+;; Assume: n < m
+(define (random-n-m n m)
+ (+ (random (- (+ m 1) n)) n))
+
+;riot : natural-number natural-number natural-number -> boolean
+;Draws a grid grid-length long and grid-length wide
+;with num-lines vertically and num-lines
+;horizontally and n balloons randomly scattered in
+;the grid. Returns true once evaluation completes.
+;This function does this by calling
+;(drawgrid grid-length num-lines whichlength?) to draw the grid lines and
+;(draw-balloons grid-length num-balloons) to draw the balloons.
+
+;Examples
+;(riot 15 500 5)
+;Starts a canvas 500px wide by 500px long and creates
+;5 lines vertically and 5 lines horizontally.
+;It then draws 15 red-circles on the canvas that represent
+;balloons.
+
+(define (riot num-balloons grid-length num-lines)
+ (and
+ (start grid-length grid-length)
+ (drawgrid grid-length num-lines 1)
+ (draw-balloons num-balloons grid-length)))
+
+;Contract, Purpose, Header
+;drawgrid : natural-number natural-number natural-number -> boolean
+;Draws num-lines horizontal lines and
+;num-lines vertical lines given grid-length.
+;We do this by drawing the
+;horizontal and vertical lines corresponding to whichline?
+;then drawing the remainder of the lines by recursively calling
+;on drawgrid. For example, if whichline? is 2, we draw the
+;second horizontal and second vertical line (in that order).
+;
+;Examples
+;(drawgrid 100 0 1)
+;true
+
+;(drawgrid 100 1 1)
+;Draws one horizontal line and one vertical
+;line in the center of the canvas.
+;The horizontal line starts from (make-posn 50 0)
+;and goes to (make-posn 50 100). The vertical line
+;starts from (make-posn 0 50) and goes to
+;(make-posn 100 50).
+
+;(drawgrid 100 2 1)
+;Draws two horizontal lines and two vertical lines.
+;The horizontal lines start from (make-posn 33 0)
+;and (make-posn 67 0) and go to
+;(make-posn 33 100) and to (make-posn 67 100),
+;respectively. The vertical lines start from
+;(make-posn 0 33) and (make-posn 0 67) and go to
+;(make-posn 100 33) and (make-posn 100 67),
+;respectively.
+;
+;Template
+;(define (drawgrid grid-length num-lines))
+;;
+;Template
+(define (drawgrid grid-length num-lines whichline?)
+ (cond
+ [(zero? num-lines) true]
+ [(> whichline? num-lines) true]
+ [(and
+ (>= num-lines 1)
+ (<= whichline? num-lines))
+ (and
+ (draw-solid-line (make-posn 0
+ (* whichline?
+ (round (/ grid-length (+ num-lines 1)))))
+ (make-posn grid-length
+ (* whichline?
+ (round (/ grid-length (+ num-lines 1)))))
+ 'black)
+ (draw-solid-line (make-posn (* whichline?
+ (round (/ grid-length (+ num-lines 1))))
+ 0)
+ (make-posn (* whichline?
+ (round (/ grid-length (+ num-lines 1))))
+ grid-length)
+ 'black)
+ (drawgrid grid-length num-lines (add1 whichline?)))]))
+;
+;Contract, Purpose, Header
+;draw-balloons : natural-number natural-number -> boolean
+;Draw num-balloons of balloons randomly
+;scattered in a grid of width and height grid-length.
+;It does so by drawing one solid disk colored 'red
+;with radius R centered at
+;(make-posn (random-n-m 0 grid-length) (random-n-m 0 grid-length)
+;that is, a disk centered at a random point within
+;the grid. It then draws the remaining balloons
+;by calling on itself
+;to draw one less balloon than it started with.
+;It returns true when finished.
+;
+;Examples
+;(draw-balloons 0 grid-length)
+;true
+;(draw-balloons 1 grid-length)
+;Draws one balloon randomly scattered
+;in the canvas grid-length wide and high.
+;
+(define (draw-balloons num-balloons grid-length)
+ (cond
+ [(zero? num-balloons) true]
+ [(draw-solid-disk (make-posn (random-n-m 0 grid-length)
+ (random-n-m 0 grid-length))
+ RADIUS
+ 'red)
+ (draw-balloons (sub1 num-balloons) grid-length)]))
+
+(define RADIUS 3)
+(riot 50 500 20)
\ No newline at end of file
blob - /dev/null
blob + b91ef4c05b087d3506eee31c0305db4d04897d12 (mode 644)
--- /dev/null
+++ 11.4.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.4.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")))))
blob - /dev/null
blob + 3ad00162e2564dc00fb3eb216e4885a5fb82b18a (mode 644)
--- /dev/null
+++ 11.4.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.4.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")))))
+;A natural-number is either
+;1. 0 or
+;2. (add1 n) where n is a natural-number
+;
+;! : natural-number -> natural number
+;Computes the factorial of n,
+;ie, n * (n-1) * (n-2)...2 * 1.
+
+(define (! n)
+ (cond
+ [(zero? n) 1]
+ [(>= n 1) (* n (! (sub1 n)))]))
+;
+;product : natural-number natural-number -> natural-number
+;Given m and n, and assuming m > n, computes (m!)/(n!).
+
+(define (product m n)
+ (/ (! m) (! n)))
+
+;; f : number -> number
+(define (f x)
+ (+ (* 3 (* x x))
+ (+ (* -6 x)
+ -1)))
+
+;
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn and lop is a list-of-posns.
+;tabulate-f20 : natural-number -> list-of-posns
+;Creates a "table". Returns a list of n posns of the form
+;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))...
+;Stops when n=20 (table includes n=20).
+
+(define (tabulate-f20 n)
+ (cond
+ [(< n 20) empty]
+ [else (cons (make-posn (f n) n) (tabulate-f20 (sub1 n)))]))
+
+;
+;Let limit be a natural number. A natural number [>=limit] (N[>=limit])
+;is either
+;
+;1. limit or
+;2. (add1 n) where n is a natural number [>=limit].
+
+;Contract, Purpose, Header
+;tabulate-f-lim : N[limit] N[>=limit] -> lop
+;Creates a table of posns containing the entries
+;(make-posn (f n) n) from n (inclusive) to limit (exclusive).
+
+(define (tabulate-f-lim limit n)
+ (cond
+ [(= n limit) empty]
+ [(> n limit) (cons (make-posn (f n) n) (tabulate-f-lim limit (sub1 n)))]))
+
+;A natural-number [<=limit] (N[<=limit]) is either
+;1. limit or
+;2. (sub1 n) where n is a natural-number [<=limit].
+
+;Contract, Purpose, Header
+;tabulate-f-lim-ascend : N[limit] N[<=limit] -> list-of-posns
+;Produces a list-of-posns (lop) of the form
+;1. empty list or
+;2. (cons (make-posn n (f n)) lop) where lop is a list-of-posns.
+;The list begins from n (inclusive) and ascends to limit (exclusive)
+;where we have defined that limit >= n.
+;
+;Template
+(define (tabulate-f-lim-ascend limit n)
+ (cond
+ [(= limit n) empty]
+ [(>= limit n) (cons (make-posn n (f n))
+ (tabulate-f-lim-ascend limit (add1 n)))]))
+
+;A natural-number [>=1] (N[>=1]) is either
+;1. 1 or
+;2. (add1 n) where n is a natural-number [>=1].
+;
+;is-not-divisible-by<=i : N [>=1] N[>i] -> boolean
+;Determines if m is divisible by any number between
+;1 (exclusive) and i (inclusive). Returns
+;true if the m is never divisible and false otherwise.
+;Template
+
+(define (is-not-divisible-by<=i i m)
+ (cond
+ [(= i 1) true]
+ [(> i 1) (and (not (zero? (remainder m i)))
+ (is-not-divisible-by<=i (sub1 i) m))]))
+;
+;Purpose, Contract, Header
+;prime? : natural-number [>=2]
+(define (prime? n)
+ (is-not-divisible-by<=i (round (sqrt n)) n))
+;
+;add : N N -> N
+;Adds n and x without using the + operator.
+;
+;Template
+(define (add n x)
+ (cond
+ [(= x 0) n]
+ [(> x 0) (add1 (add n (sub1 x)))]))
+
+;multiply : N N -> N
+;Multiplies n by x without using either
+;the + or * operator.
+
+(define (multiply n x)
+ (cond
+ [(zero? x) 0]
+ [(> x 0) (add n (multiply n (sub1 x)))]))
+
+;A rational number [R] can be represented as a fraction
+;m/n where both m and n are natural-numbers.
+
+;multiply-by-rational : R N -> R
+;Given a natural-number x, multiply by rational-number n.
+
+;(define (multiply-by-rational n x)
+; (cond
+; [(zero? x) 0]
+; [(> x 0) (add-rational n (multiply-by-rational n (sub1 x)))]))
+
+;add-rational : R R -> R
+;Given two rational-numbers n and x,
+;add the two numbers.
+;This is hard...give up
+;
+;exponent : N N -> N
+;Raises x to the nth power.
+
+(define (exponent x n)
+ (cond
+ [(zero? n) 1]
+ [(> n 0) (multiply (exponent x (sub1 n)) x)]))
+
+A deep-list is either
+1. a symbol or
+2. (cons dl empty) where dl is a deep-list.
+
+;depth : deep-list -> number
+;Consumes a deep-list dl and determines how many
+;cons were used to construct it.
+;
+;Examples
+;(depth (cons (cons (cons 'food empty) empty) empty))
+;3
+;(depth (cons 'food empty))
+;1
+;(depth 'food)
+;0
+
+(define (depth dl)
+ (cond
+ [(symbol? dl) 0]
+ [(cons? dl) (+ 1 (depth (first dl)))]))
+
+;make-deep : symbol natural-number -> deep-list
+;Consumes word and n to produce a deep-list
+;containing word constructed using n cons's.
+;
+;Examples:
+;(make-deep 'hey 3)
+;(cons (cons (cons 'hey empty) empty) empty)
+;(make-deep 'hey 0)
+;'hey
+;(make-deep 'hey 1)
+;(cons 'hey empty)
+;
+;Template
+;(define (make-deep word n)
+; (cond
+; [(zero? n) ...]
+; [(> n 0) ... (make-deep word (sub1 n))]))
+
+(define (make-deep word n)
+ (cond
+ [(zero? n) word]
+ [(> n 0) (cons (make-deep word (sub1 n)) empty)]))
+
+;Let the depth of a deep-list represent a natural-number.
+;The depth of a deep-list represents the number of cons
+;used to construct it.
+;
+;Some examples:
+;1. anysymbol represents 0,
+;2. (cons anysymbol empty) represents 1
+;3. (cons (cons anysymbol empty)) represents 2,
+;and so forth, where anysymbol is a symbol.
+;
+;Hence, we can represent
+;1.0 as (make-deep 'anysymbol 0)
+;2.3 as (make-deep 'anysymbol 3)
+;3.8 as (make-deep 'anysymbol 8).
+;
+;addDL : deep-list deep-list -> deep-list
+;Given dl1 and dl2, produces a new deep-list
+;that represents the sum of the natural numbers
+;of dl1 and dl2. In other words,
+;produces a new deep-list as deep as the sum of
+;the depth of dl1 and dl2.
+
+(define (addDL dl1 dl2)
+ (make-deep 'anysymbol (+ (depth dl1) (depth dl2))))
+
+(define DEEPLIST1 (make-deep 'anysymbol 5))
+(define DEEPLIST2 (make-deep 'anysymbol 8))
\ No newline at end of file
blob - /dev/null
blob + 56cdebcf578ccb000d551404b5139000a117fb90 (mode 644)
--- /dev/null
+++ 12.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 12.2.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")))))
+;A natural-number is either
+;1. 0 or
+;2. (add1 n) where n is a natural-number
+;
+;! : natural-number -> natural number
+;Computes the factorial of n,
+;ie, n * (n-1) * (n-2)...2 * 1.
+
+(define (! n)
+ (cond
+ [(zero? n) 1]
+ [(>= n 1) (* n (! (sub1 n)))]))
+;
+;product : natural-number natural-number -> natural-number
+;Given m and n, and assuming m > n, computes (m!)/(n!).
+
+(define (product m n)
+ (/ (! m) (! n)))
+
+;; f : number -> number
+(define (f x)
+ (+ (* 3 (* x x))
+ (+ (* -6 x)
+ -1)))
+
+;
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn and lop is a list-of-posns.
+;tabulate-f20 : natural-number -> list-of-posns
+;Creates a "table". Returns a list of n posns of the form
+;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))...
+;Stops when n=20 (table includes n=20).
+
+(define (tabulate-f20 n)
+ (cond
+ [(< n 20) empty]
+ [else (cons (make-posn (f n) n) (tabulate-f20 (sub1 n)))]))
+
+;
+;Let limit be a natural number. A natural number [>=limit] (N[>=limit])
+;is either
+;
+;1. limit or
+;2. (add1 n) where n is a natural number [>=limit].
+
+;Contract, Purpose, Header
+;tabulate-f-lim : N[limit] N[>=limit] -> lop
+;Creates a table of posns containing the entries
+;(make-posn (f n) n) from n (inclusive) to limit (exclusive).
+
+(define (tabulate-f-lim limit n)
+ (cond
+ [(= n limit) empty]
+ [(> n limit) (cons (make-posn (f n) n) (tabulate-f-lim limit (sub1 n)))]))
+
+;A natural-number [<=limit] (N[<=limit]) is either
+;1. limit or
+;2. (sub1 n) where n is a natural-number [<=limit].
+
+;Contract, Purpose, Header
+;tabulate-f-lim-ascend : N[limit] N[<=limit] -> list-of-posns
+;Produces a list-of-posns (lop) of the form
+;1. empty list or
+;2. (cons (make-posn n (f n)) lop) where lop is a list-of-posns.
+;The list begins from n (inclusive) and ascends to limit (exclusive)
+;where we have defined that limit >= n.
+;
+;Template
+(define (tabulate-f-lim-ascend limit n)
+ (cond
+ [(= limit n) empty]
+ [(>= limit n) (cons (make-posn n (f n))
+ (tabulate-f-lim-ascend limit (add1 n)))]))
+
+;A natural-number [>=1] (N[>=1]) is either
+;1. 1 or
+;2. (add1 n) where n is a natural-number [>=1].
+;
+;is-not-divisible-by<=i : N [>=1] N[>i] -> boolean
+;Determines if m is divisible by any number between
+;1 (exclusive) and i (inclusive). Returns
+;true if the m is never divisible and false otherwise.
+;Template
+
+(define (is-not-divisible-by<=i i m)
+ (cond
+ [(= i 1) true]
+ [(> i 1) (and (not (zero? (remainder m i)))
+ (is-not-divisible-by<=i (sub1 i) m))]))
+;
+;Purpose, Contract, Header
+;prime? : natural-number [>=2]
+(define (prime? n)
+ (is-not-divisible-by<=i (round (sqrt n)) n))
+;
+;add : N N -> N
+;Adds n and x without using the + operator.
+;
+;Template
+(define (add n x)
+ (cond
+ [(= x 0) n]
+ [(> x 0) (add1 (add n (sub1 x)))]))
+
+;multiply : N N -> N
+;Multiplies n by x without using either
+;the + or * operator.
+
+(define (multiply n x)
+ (cond
+ [(zero? x) 0]
+ [(> x 0) (add n (multiply n (sub1 x)))]))
+
+;A rational number [R] can be represented as a fraction
+;m/n where both m and n are natural-numbers.
+
+;multiply-by-rational : R N -> R
+;Given a natural-number x, multiply by rational-number n.
+
+;(define (multiply-by-rational n x)
+; (cond
+; [(zero? x) 0]
+; [(> x 0) (add-rational n (multiply-by-rational n (sub1 x)))]))
+
+;add-rational : R R -> R
+;Given two rational-numbers n and x,
+;add the two numbers.
+;This is hard...give up
+;
+;exponent : N N -> N
+;Raises x to the nth power.
+
+(define (exponent x n)
+ (cond
+ [(zero? n) 1]
+ [(> n 0) (multiply (exponent x (sub1 n)) x)]))
+;
+;A deep-list is either
+;1. a symbol or
+;2. (cons dl empty) where dl is a deep-list.
+
+;depth : deep-list -> number
+;Consumes a deep-list dl and determines how many
+;cons were used to construct it.
+;
+;Examples
+;(depth (cons (cons (cons 'food empty) empty) empty))
+;3
+;(depth (cons 'food empty))
+;1
+;(depth 'food)
+;0
+
+(define (depth dl)
+ (cond
+ [(symbol? dl) 0]
+ [(cons? dl) (+ 1 (depth (first dl)))]))
+
+;make-deep : symbol natural-number -> deep-list
+;Consumes word and n to produce a deep-list
+;containing word constructed using n cons's.
+;
+;Examples:
+;(make-deep 'hey 3)
+;(cons (cons (cons 'hey empty) empty) empty)
+;(make-deep 'hey 0)
+;'hey
+;(make-deep 'hey 1)
+;(cons 'hey empty)
+;
+;Template
+;(define (make-deep word n)
+; (cond
+; [(zero? n) ...]
+; [(> n 0) ... (make-deep word (sub1 n))]))
+
+(define (make-deep word n)
+ (cond
+ [(zero? n) word]
+ [(> n 0) (cons (make-deep word (sub1 n)) empty)]))
+
+;Let the depth of a deep-list represent a natural-number.
+;The depth of a deep-list represents the number of cons
+;used to construct it.
+;
+;Some examples:
+;1. anysymbol represents 0,
+;2. (cons anysymbol empty) represents 1
+;3. (cons (cons anysymbol empty)) represents 2,
+;and so forth, where anysymbol is a symbol.
+;
+;Hence, we can represent
+;1.0 as (make-deep 'anysymbol 0)
+;2.3 as (make-deep 'anysymbol 3)
+;3.8 as (make-deep 'anysymbol 8).
+;
+;addDL : deep-list deep-list -> deep-list
+;Given dl1 and dl2, produces a new deep-list
+;that represents the sum of the natural numbers
+;of dl1 and dl2. In other words,
+;produces a new deep-list as deep as the sum of
+;the depth of dl1 and dl2.
+
+(define (addDL dl1 dl2)
+ (make-deep 'anysymbol (+ (depth dl1) (depth dl2))))
+
+(define DEEPLIST1 (make-deep 'anysymbol 5))
+(define DEEPLIST2 (make-deep 'anysymbol 8))
\ No newline at end of file
blob - /dev/null
blob + ef4a47fa22385b831ce6284800b6a9a230aa1f6f (mode 644)
--- /dev/null
+++ 12.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 12.2.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")))))
+;A mail structure is
+;(make-mail f d m) where f and m are strings,
+;d is a date.
+
+(define-struct mail (from date message))
+;
+;A list-of-mail is either
+;1. an empty list or
+;2. (cons mail lom) where mail is a mail structure
+;and lom is a list-of-mail.
+;
+;sort-mail : list-of-mail -> list-of-mail
+;Given alom (a list-of-mail),
+;sorts the mail based on name
+;by insertion sorting and returns
+;the sorted list.
+
+(define (sort-mail alom)
+ (cond
+ [(empty? alom) empty]
+ [(cons? alom) (insert (first alom) (sort-mail (rest alom)))]))
+
+;insert : mail list-of-mail -> list-of-mail
+;Given amail and alom, insert amail into the proper
+;position in alom and return the new list-of-mail.
+;This is done by comparing the name of amail with
+;the name of the first mail in alom.
+;
+;Template
+;(define (insert amail alom)
+; (cond
+; [(string<? (mail-from amail) (mail-from (first alom)))
+; ...]
+; [else ...]))
+
+(define (insert amail alom)
+ (cond
+ [(empty? alom) (cons amail alom)]
+ [(string<? (mail-from amail) (mail-from (first alom)))
+ (cons amail alom)]
+ [else (cons (first alom)
+ (insert amail (rest alom)))]))
+
+;Test
+;(define POSTMAN (cons (make-mail "Sally" 4561923 "Hi it's me Sally") (cons (make-mail "Jennifer" 9133217 "Sitting at home") (cons (make-mail "Tweety" 1234567 "Add me on Twitter") (cons (make-mail "Aaron" 5939257 "RonRon") (cons (make-mail "Zebrafish" 8888888 "Alphabetical") (cons (make-mail "Jabra" 2950 "Headset") empty)))))))
+
+;; search : number list-of-numbers -> boolean
+(define (search n alon)
+ (cond
+ [(empty? alon) false]
+ [else (or (= (first alon) n) (search n (rest alon)))]))
+;
+;search-sorted : number list-of-numbers -> boolean
+;Determines if n is in alon and returns true if it is,
+;false otherwise. alon is assumed to be sorted
+;in descending order. Performs a linear-search.
+;
+;Template
+;(define (search-sorted n alon)
+; (cond
+; [(empty? alon) ...]
+; [(= n (first alon)) ...]
+; [else ... (search-sorted (rest alon))]))
+
+(define (search-sorted n alon)
+ (cond
+ [(empty? alon) false]
+ [(= n (first alon)) true]
+ [(> n (first alon)) false]
+ [else (search-sorted n (rest alon))]))
+
+;Test
+;(define MRLIST (cons 15 (cons 12 (cons 12 (cons 9 (cons 3 (cons 0 empty)))))))
blob - /dev/null
blob + 74595be75e4924b8c7e2a9b9da579c66ec193492 (mode 644)
--- /dev/null
+++ 12.3.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 12.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")))))
+;A mail structure is
+;(make-mail f d m) where f and m are strings,
+;d is a date.
+
+(define-struct mail (from date message))
+;
+;A list-of-mail is either
+;1. an empty list or
+;2. (cons mail lom) where mail is a mail structure
+;and lom is a list-of-mail.
+;
+;sort-mail : list-of-mail -> list-of-mail
+;Given alom (a list-of-mail),
+;sorts the mail based on name
+;by insertion sorting and returns
+;the sorted list.
+
+(define (sort-mail alom)
+ (cond
+ [(empty? alom) empty]
+ [(cons? alom) (insert (first alom) (sort-mail (rest alom)))]))
+
+;insert : mail list-of-mail -> list-of-mail
+;Given amail and alom, insert amail into the proper
+;position in alom and return the new list-of-mail.
+;This is done by comparing the name of amail with
+;the name of the first mail in alom.
+;
+;Template
+;(define (insert amail alom)
+; (cond
+; [(string<? (mail-from amail) (mail-from (first alom)))
+; ...]
+; [else ...]))
+
+(define (insert amail alom)
+ (cond
+ [(empty? alom) (cons amail alom)]
+ [(string<? (mail-from amail) (mail-from (first alom)))
+ (cons amail alom)]
+ [else (cons (first alom)
+ (insert amail (rest alom)))]))
+
+;Test
+;(define POSTMAN (cons (make-mail "Sally" 4561923 "Hi it's me Sally") (cons (make-mail "Jennifer" 9133217 "Sitting at home") (cons (make-mail "Tweety" 1234567 "Add me on Twitter") (cons (make-mail "Aaron" 5939257 "RonRon") (cons (make-mail "Zebrafish" 8888888 "Alphabetical") (cons (make-mail "Jabra" 2950 "Headset") empty)))))))
+
+;; search : number list-of-numbers -> boolean
+(define (search n alon)
+ (cond
+ [(empty? alon) false]
+ [else (or (= (first alon) n) (search n (rest alon)))]))
+;
+;search-sorted : number list-of-numbers -> boolean
+;Determines if n is in alon and returns true if it is,
+;false otherwise. alon is assumed to be sorted
+;in descending order. Performs a linear-search.
+;
+;Template
+;(define (search-sorted n alon)
+; (cond
+; [(empty? alon) ...]
+; [(= n (first alon)) ...]
+; [else ... (search-sorted (rest alon))]))
+
+(define (search-sorted n alon)
+ (cond
+ [(empty? alon) false]
+ [(= n (first alon)) true]
+ [(> n (first alon)) false]
+ [else (search-sorted n (rest alon))]))
+
+;Test
+;(define MRLIST (cons 15 (cons 12 (cons 12 (cons 9 (cons 3 (cons 0 empty)))))))
blob - /dev/null
blob + 9220c12a5d73d653fdcbd5f68f5cfc43f4a169ca (mode 644)
--- /dev/null
+++ 12.3.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 12.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")))))
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn
+;and lop is a list-of-posns.
+
+;A polygon is either
+;1. (cons p empty) where p is a posn or
+;2. (cons p q) where p is a posn and q is a polygon.
+;(That is, a polygon includes all the elements
+;of a list-of-posns except the empty list.)
+;
+;draw-polygon : polygon -> true
+;Given a-poly (a polygon) which
+;represents the vertices of the polygon, draw this polygon
+;by connecting the dots between the posn elements
+;in the list. It first connects the last posn to
+;the first posn, then sequentially connects the
+;remaining posns to each other. It extracts
+;the last posn of a-poly by calling on the last
+;function. Returns true when evaluation completes.
+
+(define (draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (cons (last a-poly) a-poly))]))
+;
+;connect-dots : polygon -> boolean
+;Given a-poly, connects the posns in sequential order.
+;IE, the 1st posn connects to the 2nd, the 2nd to the 3rd,
+;and so forth to the last dot.
+
+(define (connect-dots a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (and
+ (draw-solid-line (first a-poly)
+ (second a-poly)
+ 'black)
+ (connect-dots (rest a-poly)))]))
+
+;Test
+;(define MRPOLY (cons (make-posn 50 50) (cons (make-posn 50 80) (cons (make-posn 100 80) empty))))
+;(connect-dots MRPOLY)
+;
+;last : polygon -> posn
+;Given a-poly, finds the last posn element
+;within the list-of-posns and returns it.
+
+(define (last a-poly)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (last (rest a-poly))]))
+
+;Test
+(define MRPOLY (cons (make-posn 50 50) (cons (make-posn 50 80) (cons (make-posn 100 80) (cons (make-posn 140 230) (cons (make-posn 180 330) (cons (make-posn 240 220) (cons (make-posn 130 220) empty))))))))
+
+;add-at-end : polygon posn -> polygon
+;Given a-poly and first-posn,
+;it adds first-posn to
+;the end of a-poly, returning
+;the new polygon. When add-at-end is called,
+;first-posn should be replaced with
+;(first a-poly), so that the function call should be
+;(add-at-end a-poly (first a-poly))
+
+(define (add-at-end a-poly first-posn)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (cons (add-at-end a-poly first-posn) (cons first-posn empty))]))
+;
+;modified-draw-polygon : polygon -> true
+;Draws polygon specified by a-poly, where
+;each posn in a-poly represents a vertex in
+;the polygon. It does so by using connect-dots
+;to connect the dots of each vertex.
+;Specifically, it connects the 1st dot to the 2nd,
+;the 2nd to the 3rd, and so forth, and finally
+;connects the last dot to the 1st dot to finish
+;the polygon by calling on add-at-end.
+
+(define (modified-draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (add-at-end a-poly))]))
\ No newline at end of file
blob - /dev/null
blob + 86d7e6af5fef4c44bba09537aeeef7a4f7d336a9 (mode 644)
--- /dev/null
+++ 12.4.1 revised.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |12.4.1 revised|) (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")))))
+;;Data Definition
+;;A word is either
+;;1. an empty list or
+;;2. (cons l w) where l is a symbol (one of the
+;;lowercase letters 'a, 'b, ... 'z) and w is a word.
+;;
+;;Examples
+;;empty
+;;(cons 'i empty)
+;;(cons 'h (cons 'i empty))
+;;(cons 'n (cons 'a (cons 'm (cons 'e empty))))
+;;
+;;A list-of-words is either
+;;1. (cons w empty) or
+;;2. (cons w low) where w is a word
+;;and low is a list-of-words.
+;;
+;;Examples
+;;(cons empty empty)
+;;empty empty
+;;(cons (cons 'i empty) empty)
+;;i
+;;(cons (cons 'h (cons 'i empty)) empty)
+;;hi
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty))) empty)
+;;hi joe
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty)))
+;; (cons (cons 'i (cons 't (cons 's empty)))
+;; empty)))
+;;hi joe its
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty)))
+;; (cons (cons 'i (cons 't (cons 's empty)))
+;; (cons (cons 'm (cons 'e empty)) empty))))
+;;hi joe its me
+;
+;;arrangements : word -> list-of-words
+;;Given a-word, return all permutations
+;;as a list-of-words. This is done
+;;by inserting the first letter into
+;;each permutation of the rest of the word.
+;
+(define (arrangements a-word)
+ (cond
+ [(empty? a-word) (cons empty empty)]
+ [else (insert-everywhere/in-all-words (first a-word)
+ (arrangements (rest a-word)))]))
+;
+;;insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+;;Given a-symbol and a-low, insert a-symbol into every possible position
+;;to generate a new list-of-words. In general, if the words in a-low
+;;contain x letters, there should be (x+1)*x words in the list-of-words output.
+;
+;
+;;Examples
+;;(define ex1 (cons empty empty))
+;;(insert-everywhere/in-all-words 'a ex1)
+;;(cons (cons 'a empty) empty)
+;;
+;;(define ex2 (cons (cons 'i empty) empty))
+;;(insert-everywhere/in-all-words 'a ex2)
+;;(cons (cons 'a (cons 'i empty))
+;; (cons (cons 'i (cons 'a empty)) empty))
+;;
+;;(define ex3 (cons (cons 'h (cons 'i empty))
+;; (cons (cons 'i (cons 'h empty)) empty)))
+;;(insert-everywhere/in-all-words 'b ex3)
+;;(cons (cons 'b (cons 'h (cons 'i empty)))
+;; (cons (cons 'h (cons 'b (cons 'i empty)))
+;; (cons (cons 'h (cons 'i (cons 'b empty)))
+;; (cons (cons 'b (cons 'i (cons 'h empty)))
+;; (cons (cons 'i (cons 'b (cons 'h empty)))
+;; (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
+;
+(define (insert-everywhere/in-all-words a-symbol a-low)
+ (cond
+ [(empty? (first a-low))
+ (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0)]
+ [(cons? (first a-low)) ;evaluates true if the first element
+ ;in a-low is a word
+ (cons (insert-everywhere/in-all-words a-symbol (rest a-low))
+ (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0))()]))
+
+;insert-symbol-everywhere/in-single-word : symbol word number -> list-of-words
+;Given a-symbol and a-word, inserts a-symbol into every possible position
+;to generate a list-of-words. Begins insertion at the nth position.
+
+(define (insert-symbol-everywhere/in-single-word a-symbol a-word n)
+ (cond
+ [(empty? a-word) (cons (cons a-symbol empty) empty)]
+ [(and
+ (cons? a-word)
+ (<= n (length a-word)))
+ (cons (insert-symbol-here a-symbol a-word n)
+ (insert-symbol-everywhere/in-single-word a-symbol a-word (add1 n)))]
+ [(> n (length a-word)) empty]
+ [else (error 'insert-symbol-everywhere/in-single-word "unexpected error")]))
+;
+;insert-symbol-here : symbol word number -> word
+;Given a-symbol and a-word and n, insert a-symbol
+;in the nth position of a-word. Right before
+;the word is the 0th position. The first position
+;is right after the first letter.
+;
+;Examples:
+;(insert-symbol-here 'a (cons 'n empty) 0)
+;(cons 'a (cons 'n empty))
+;
+;(insert-symbol-here 'a (cons 'n empty) 1)
+;(cons 'n (cons 'a empty))
+;
+
+(define (insert-symbol-here a-symbol a-word n)
+ (cond
+ [(= n 0) (cons a-symbol a-word)]
+ [(>= n 1)
+ (cons (first a-word)
+ (insert-symbol-here a-symbol (rest a-word) (sub1 n)))]))
+
+;Test insert-symbol-here
+;(define word1 empty)
+;(define word2 (cons 'a empty))
+;(define word3 (cons 'a (cons 'b empty)))
+;(define word4 (cons 'a (cons 'b (cons 'c empty))))
+;(insert-symbol-here 'x word1 0)
+;(insert-symbol-here 'x word2 0)
+;(insert-symbol-here 'x word2 1)
+;(insert-symbol-here 'x word3 0)
+;(insert-symbol-here 'x word3 1)
+;(insert-symbol-here 'x word3 2)
+
+;Examples of insert-symbol-everywhere/in-single-word
+;
+;(define ex01 empty)
+;(insert-symbol-everywhere/in-single-word 'x ex01 0)
+;(cons (cons 'x empty) empty)
+;(define ex02 (cons 'a empty))
+;(insert-symbol-everywhere/in-single-word 'x ex02 0)
+;(cons (cons 'x (cons 'a empty))
+; (cons (cons 'a (cons 'x empty)) empty))
+;(append (cons (cons 'x (cons 'a empty)) empty)
+; (cons (cons 'a (cons 'x empty)) empty))
+;(define ex03 (cons 'a (cons 'b empty)))
+;(insert-symbol-everywhere/in-single-word 'x ex03 0)
+;(cons (cons 'x (cons 'a (cons 'b empty)))
+; (cons (cons 'a (cons 'x (cons 'b empty)))
+; (cons (cons 'a (cons 'b (cons 'x empty))) empty)))
+;(define ex04 (list 'p 'a 'r 't 'y))
+;(insert-symbol-everywhere/in-single-word 'x ex04 0)
+;
+
+;Test insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+
+(define ex1 (cons empty empty))
+(insert-everywhere/in-all-words 'a ex1)
+(cons (cons 'a empty) empty)
+
+(define ex2 (cons (cons 'i empty) empty))
+(insert-everywhere/in-all-words 'a ex2)
+(cons (cons 'a (cons 'i empty))
+ (cons (cons 'i (cons 'a empty)) empty))
+
+(define ex3 (cons (cons 'h (cons 'i empty))
+ (cons (cons 'i (cons 'h empty)) empty)))
+(insert-everywhere/in-all-words 'b ex3)
+(cons (cons 'b (cons 'h (cons 'i empty)))
+ (cons (cons 'h (cons 'b (cons 'i empty)))
+ (cons (cons 'h (cons 'i (cons 'b empty)))
+ (cons (cons 'b (cons 'i (cons 'h empty)))
+ (cons (cons 'i (cons 'b (cons 'h empty)))
+ (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
blob - /dev/null
blob + 08b931b69b28ec4a31bd37548c522b4a382441b7 (mode 644)
--- /dev/null
+++ 12.4.1 revised.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |12.4.1 revised|) (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")))))
+;Data Definition
+;A word is either
+;1. an empty list or
+;2. (cons l w) where l is a symbol (one of the
+;lowercase letters 'a, 'b, ... 'z) and w is a word.
+;
+;Examples
+;empty
+;(cons 'i empty)
+;(cons 'h (cons 'i empty))
+;(cons 'n (cons 'a (cons 'm (cons 'e empty))))
+;
+;A list-of-words is either
+;1. (cons w empty) or
+;2. (cons w low) where w is a word
+;and low is a list-of-words.
+;
+;Examples
+;(cons empty empty)
+;empty empty
+;(cons (cons 'i empty) empty)
+;(cons (list 'i) empty)
+;i
+;(cons (cons 'h (cons 'i empty)) empty)
+;(cons (list 'h 'i) empty)
+;(list (list 'h 'i))
+;hi
+;(cons (cons 'h (cons 'i empty))
+; (cons (cons 'j (cons 'o (cons 'e empty))) empty))
+;(cons (list 'h 'i)
+; (cons (list 'j 'o 'e) empty))
+;(list (list 'h 'i)
+; (list 'j 'o 'e))
+;hi joe
+;(cons (cons 'h (cons 'i empty))
+; (cons (cons 'j (cons 'o (cons 'e empty)))
+; (cons (cons 'i (cons 't (cons 's empty)))
+; empty)))
+;(cons (list 'h 'i)
+; (cons (list 'j 'o 'e)
+; (cons (list 'i 't 's) empty)))
+;(list (list 'h 'i)
+; (list 'j 'o 'e)
+; (list 'i 't 's))
+;hi joe its
+;(cons (cons 'h (cons 'i empty))
+; (cons (cons 'j (cons 'o (cons 'e empty)))
+; (cons (cons 'i (cons 't (cons 's empty)))
+; (cons (cons 'm (cons 'e empty)) empty))))
+;(cons (list 'h 'i)
+; (cons (list 'j 'o 'e)
+; (cons (list 'i 't 's)
+; (cons (list 'm 'e) empty))))
+;(list (list 'h 'i)
+; (list 'j 'o 'e)
+; (list 'i 't 's)
+; (list 'm 'e))
+;hi joe its me
+;
+;arrangements : word -> list-of-words
+;Given a-word, return all permutations
+;as a list-of-words. This is done
+;by inserting the first letter into
+;each permutation of the rest of the word.
+
+(define (arrangements a-word)
+ (cond
+ [(empty? a-word) (cons empty empty)]
+ [else (insert-everywhere/in-all-words (first a-word)
+ (arrangements (rest a-word)))]))
+
+;insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+;Given a-symbol and a-low, insert a-symbol into every possible position
+;to generate a new list-of-words. In general, if the words in a-low
+;contain x letters, there should be (x+1)*x words in the list-of-words output.
+;
+;
+;Examples
+;(define ex1 (cons empty empty))
+;(insert-everywhere/in-all-words 'a ex1)
+;(cons (cons 'a empty) empty)
+;
+;(define ex2 (cons (list 'i) empty))
+;(cons (cons 'i empty) empty)
+;(insert-everywhere/in-all-words 'a ex2)
+;(cons (cons 'a (cons 'i empty))
+; (cons (cons 'i (cons 'a empty)) empty))
+;(cons (list 'a 'i)
+; (cons (list 'i 'a) empty))
+;(list (list 'a 'i)
+; (list 'i 'a))
+;
+;(define ex3 (cons (cons 'h (cons 'i empty))
+; (cons (cons 'i (cons 'h empty)) empty)))
+;(insert-everywhere/in-all-words 'b ex3)
+;(cons (cons 'b (cons 'h (cons 'i empty)))
+; (cons (cons 'h (cons 'b (cons 'i empty)))
+; (cons (cons 'h (cons 'i (cons 'b empty)))
+; (cons (cons 'b (cons 'i (cons 'h empty)))
+; (cons (cons 'i (cons 'b (cons 'h empty)))
+; (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
+
+(define (insert-everywhere/in-all-words a-symbol a-low)
+ (cond
+ [(empty? a-low) empty]
+ [(empty? (first a-low))
+ (cons (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0) empty)]
+ [(cons? (first a-low)) ;evaluates true if the first element
+ ;in a-low is a word
+ (append (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0)
+ (insert-everywhere/in-all-words a-symbol (rest a-low)))]))
+
+;insert-symbol-everywhere/in-single-word : symbol word number -> list-of-words
+;Given a-symbol and a-word, inserts a-symbol into every possible position
+;to generate a list-of-words. Begins insertion at the nth position.
+
+(define (insert-symbol-everywhere/in-single-word a-symbol a-word n)
+ (cond
+ [(empty? a-word) (cons a-symbol empty)]
+ [(and
+ (cons? a-word)
+ (<= n (length a-word)))
+ (cons (insert-symbol-here a-symbol a-word n)
+ (insert-symbol-everywhere/in-single-word a-symbol a-word (add1 n)))]
+ [(> n (length a-word)) empty]
+ [else (error 'insert-symbol-everywhere/in-single-word "unexpected error")]))
+;
+;insert-symbol-here : symbol word number -> word
+;Given a-symbol and a-word and n, insert a-symbol
+;in the nth position of a-word. Right before
+;the word is the 0th position. The first position
+;is right after the first letter.
+;
+;Examples:
+;(insert-symbol-here 'a (cons 'n empty) 0)
+;(cons 'a (cons 'n empty))
+;
+;(insert-symbol-here 'a (cons 'n empty) 1)
+;(cons 'n (cons 'a empty))
+;
+
+(define (insert-symbol-here a-symbol a-word n)
+ (cond
+ [(= n 0) (cons a-symbol a-word)]
+ [(>= n 1)
+ (cons (first a-word)
+ (insert-symbol-here a-symbol (rest a-word) (sub1 n)))]))
+
+;Test insert-symbol-here
+;(define word1 empty)
+;(define word2 (cons 'a empty))
+;(define word3 (cons 'a (cons 'b empty)))
+;(define word4 (cons 'a (cons 'b (cons 'c empty))))
+;(insert-symbol-here 'x word1 0)
+;(insert-symbol-here 'x word2 0)
+;(insert-symbol-here 'x word2 1)
+;(insert-symbol-here 'x word3 0)
+;(insert-symbol-here 'x word3 1)
+;(insert-symbol-here 'x word3 2)
+
+;Examples of insert-symbol-everywhere/in-single-word
+;
+;(define ex01 empty)
+;(insert-symbol-everywhere/in-single-word 'x ex01 0)
+;(cons (cons 'x empty) empty)
+;(define ex02 (cons 'a empty))
+;(insert-symbol-everywhere/in-single-word 'x ex02 0)
+;(cons (cons 'x (cons 'a empty))
+; (cons (cons 'a (cons 'x empty)) empty))
+;(append (cons (cons 'x (cons 'a empty)) empty)
+; (cons (cons 'a (cons 'x empty)) empty))
+;(define ex03 (cons 'a (cons 'b empty)))
+;(insert-symbol-everywhere/in-single-word 'x ex03 0)
+;(cons (cons 'x (cons 'a (cons 'b empty)))
+; (cons (cons 'a (cons 'x (cons 'b empty)))
+; (cons (cons 'a (cons 'b (cons 'x empty))) empty)))
+;(define ex04 (list 'p 'a 'r 't 'y))
+;(insert-symbol-everywhere/in-single-word 'x ex04 0)
+;
+
+;Test insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+;
+;(define ex1 (cons empty empty))
+;(insert-everywhere/in-all-words 'a ex1)
+;(cons (cons 'a empty) empty)
+;
+;(define ex2 (cons (cons 'i empty) empty))
+;(insert-everywhere/in-all-words 'a ex2)
+;(cons (cons 'a (cons 'i empty))
+; (cons (cons 'i (cons 'a empty)) empty))
+;
+;(define ex3 (cons (cons 'h (cons 'i empty))
+; (cons (cons 'i (cons 'h empty)) empty)))
+;(insert-everywhere/in-all-words 'b ex3)
+;(cons (cons 'b (cons 'h (cons 'i empty)))
+; (cons (cons 'h (cons 'b (cons 'i empty)))
+; (cons (cons 'h (cons 'i (cons 'b empty)))
+; (cons (cons 'b (cons 'i (cons 'h empty)))
+; (cons (cons 'i (cons 'b (cons 'h empty)))
+; (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
+
+;Test insert-everywhere/in-all-words a-symbol a-low
+;(define list-a (list (list 'h 'i)
+; (list 'i 'h)))
+;
+;(insert-everywhere/in-all-words 'x list-a)
+;
+;Results
+;(list (list 'x 'h 'i)
+; (list 'h 'x 'i)
+; (list 'h 'i 'x)
+; (list 'h 'i 'x)
+; (list 'i 'x' h)
+; (list 'i 'h 'x))
+
+(define list2 (list empty))
\ No newline at end of file
blob - /dev/null
blob + aa24da9ebc32d3cf319bd41a803ef67288602486 (mode 644)
--- /dev/null
+++ 12.4.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 12.4.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")))))
+;A list-of-posns is either
+;1. an empty list or
+;2. (cons p lop) where p is a posn
+;and lop is a list-of-posns.
+
+;A polygon is either
+;1. (cons p empty) where p is a posn or
+;2. (cons p q) where p is a posn and q is a polygon.
+;(That is, a polygon includes all the elements
+;of a list-of-posns except the empty list.)
+;
+;draw-polygon : polygon -> true
+;Given a-poly (a polygon) which
+;represents the vertices of the polygon, draw this polygon
+;by connecting the dots between the posn elements
+;in the list. It first connects the last posn to
+;the first posn, then sequentially connects the
+;remaining posns to each other. It extracts
+;the last posn of a-poly by calling on the last
+;function. Returns true when evaluation completes.
+
+(define (draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (cons (last a-poly) a-poly))]))
+;
+;connect-dots : polygon -> boolean
+;Given a-poly, connects the posns in sequential order.
+;IE, the 1st posn connects to the 2nd, the 2nd to the 3rd,
+;and so forth to the last dot.
+
+(define (connect-dots a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (and
+ (draw-solid-line (first a-poly)
+ (second a-poly)
+ 'black)
+ (connect-dots (rest a-poly)))]))
+
+;Test
+;(define MRPOLY (cons (make-posn 50 50) (cons (make-posn 50 80) (cons (make-posn 100 80) empty))))
+;(connect-dots MRPOLY)
+;
+;last : polygon -> posn
+;Given a-poly, finds the last posn element
+;within the list-of-posns and returns it.
+
+(define (last a-poly)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (last (rest a-poly))]))
+
+;Test
+(define MRPOLY (cons (make-posn 50 50) (cons (make-posn 50 80) (cons (make-posn 100 80) (cons (make-posn 140 230) (cons (make-posn 180 330) (cons (make-posn 240 220) (cons (make-posn 130 220) empty))))))))
+
+;add-at-end : polygon posn -> polygon
+;Given a-poly and first-posn,
+;it adds first-posn to
+;the end of a-poly, returning
+;the new polygon. When add-at-end is called,
+;first-posn should be replaced with
+;(first a-poly), so that the function call should be
+;(add-at-end a-poly (first a-poly))
+
+(define (add-at-end a-poly first-posn)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (cons (add-at-end a-poly first-posn) (cons first-posn empty))]))
+;
+;modified-draw-polygon : polygon -> true
+;Draws polygon specified by a-poly, where
+;each posn in a-poly represents a vertex in
+;the polygon. It does so by using connect-dots
+;to connect the dots of each vertex.
+;Specifically, it connects the 1st dot to the 2nd,
+;the 2nd to the 3rd, and so forth, and finally
+;connects the last dot to the 1st dot to finish
+;the polygon by calling on add-at-end.
+
+(define (modified-draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (add-at-end a-poly))]))
\ No newline at end of file
blob - /dev/null
blob + 0829fe52cbc5f7373fd406e2b7a9aa894b5f3169 (mode 644)
--- /dev/null
+++ 12.4.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 12.4.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")))))
+;;Data Definition
+;;A word is either
+;;1. an empty list or
+;;2. (cons l w) where l is a symbol (one of the
+;;lowercase letters 'a, 'b, ... 'z) and w is a word.
+;;
+;;Examples
+;;empty
+;;(cons 'i empty)
+;;(cons 'h (cons 'i empty))
+;;(cons 'n (cons 'a (cons 'm (cons 'e empty))))
+;;
+;;A list-of-words is either
+;;1. (cons w empty) or
+;;2. (cons w low) where w is a word
+;;and low is a list-of-words.
+;;
+;;Examples
+;;(cons empty empty)
+;;empty empty
+;;(cons (cons 'i empty) empty)
+;;i
+;;(cons (cons 'h (cons 'i empty)) empty)
+;;hi
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty))) empty)
+;;hi joe
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty)))
+;; (cons (cons 'i (cons 't (cons 's empty)))
+;; empty)))
+;;hi joe its
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty)))
+;; (cons (cons 'i (cons 't (cons 's empty)))
+;; (cons (cons 'm (cons 'e empty)) empty))))
+;;hi joe its me
+;
+;;arrangements : word -> list-of-words
+;;Given a-word, return all permutations
+;;as a list-of-words. This is done
+;;by inserting the first letter into
+;;each permutation of the rest of the word.
+;
+(define (arrangements a-word)
+ (cond
+ [(empty? a-word) (cons empty empty)]
+ [else (insert-everywhere/in-all-words (first a-word)
+ (arrangements (rest a-word)))]))
+;
+;;insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+;;Given a-symbol and a-low, insert a-symbol into every possible position
+;;to generate a new list-of-words. In general, if the words in a-low
+;;contain x letters, there should be (x+1)*x words in the list-of-words output.
+;
+;
+;;Examples
+;;(define ex1 (cons empty empty))
+;;(insert-everywhere/in-all-words 'a ex1)
+;;(cons (cons 'a empty) empty)
+;;
+;;(define ex2 (cons (cons 'i empty) empty))
+;;(insert-everywhere/in-all-words 'a ex2)
+;;(cons (cons 'a (cons 'i empty))
+;; (cons (cons 'i (cons 'a empty)) empty))
+;;
+;;(define ex3 (cons (cons 'h (cons 'i empty))
+;; (cons (cons 'i (cons 'h empty)) empty)))
+;;(insert-everywhere/in-all-words 'b ex3)
+;;(cons (cons 'b (cons 'h (cons 'i empty)))
+;; (cons (cons 'h (cons 'b (cons 'i empty)))
+;; (cons (cons 'h (cons 'i (cons 'b empty)))
+;; (cons (cons 'b (cons 'i (cons 'h empty)))
+;; (cons (cons 'i (cons 'b (cons 'h empty)))
+;; (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
+;
+(define (insert-everywhere/in-all-words a-symbol a-low)
+ (cond
+ [(empty? (first a-low))
+ (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0)]
+ [(cons? (first a-low)) ;evaluates true if the first element
+ ;in a-low is a word
+ (cons (insert-everywhere/in-all-words a-symbol (rest a-low))
+ (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0))()]))
+
+;insert-symbol-everywhere/in-single-word : symbol word number -> list-of-words
+;Given a-symbol and a-word, inserts a-symbol into every possible position
+;to generate a list-of-words. Begins insertion at the nth position.
+
+(define (insert-symbol-everywhere/in-single-word a-symbol a-word n)
+ (cond
+ [(empty? a-word) (cons (cons a-symbol empty) empty)]
+ [(and
+ (cons? a-word)
+ (<= n (length a-word)))
+ (cons (insert-symbol-here a-symbol a-word n)
+ (insert-symbol-everywhere/in-single-word a-symbol a-word (add1 n)))]
+ [(> n (length a-word)) empty]
+ [else (error 'insert-symbol-everywhere/in-single-word "unexpected error")]))
+;
+;insert-symbol-here : symbol word number -> word
+;Given a-symbol and a-word and n, insert a-symbol
+;in the nth position of a-word. Right before
+;the word is the 0th position. The first position
+;is right after the first letter.
+;
+;Examples:
+;(insert-symbol-here 'a (cons 'n empty) 0)
+;(cons 'a (cons 'n empty))
+;
+;(insert-symbol-here 'a (cons 'n empty) 1)
+;(cons 'n (cons 'a empty))
+;
+
+(define (insert-symbol-here a-symbol a-word n)
+ (cond
+ [(= n 0) (cons a-symbol a-word)]
+ [(>= n 1)
+ (cons (first a-word)
+ (insert-symbol-here a-symbol (rest a-word) (sub1 n)))]))
+
+;Test insert-symbol-here
+;(define word1 empty)
+;(define word2 (cons 'a empty))
+;(define word3 (cons 'a (cons 'b empty)))
+;(define word4 (cons 'a (cons 'b (cons 'c empty))))
+;(insert-symbol-here 'x word1 0)
+;(insert-symbol-here 'x word2 0)
+;(insert-symbol-here 'x word2 1)
+;(insert-symbol-here 'x word3 0)
+;(insert-symbol-here 'x word3 1)
+;(insert-symbol-here 'x word3 2)
+
+;Examples of insert-symbol-everywhere/in-single-word
+;
+;(define ex01 empty)
+;(insert-symbol-everywhere/in-single-word 'x ex01 0)
+;(cons (cons 'x empty) empty)
+;(define ex02 (cons 'a empty))
+;(insert-symbol-everywhere/in-single-word 'x ex02 0)
+;(cons (cons 'x (cons 'a empty))
+; (cons (cons 'a (cons 'x empty)) empty))
+;(append (cons (cons 'x (cons 'a empty)) empty)
+; (cons (cons 'a (cons 'x empty)) empty))
+;(define ex03 (cons 'a (cons 'b empty)))
+;(insert-symbol-everywhere/in-single-word 'x ex03 0)
+;(cons (cons 'x (cons 'a (cons 'b empty)))
+; (cons (cons 'a (cons 'x (cons 'b empty)))
+; (cons (cons 'a (cons 'b (cons 'x empty))) empty)))
+;(define ex04 (list 'p 'a 'r 't 'y))
+;(insert-symbol-everywhere/in-single-word 'x ex04 0)
+;
+
+;Test insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+
+(define ex1 (cons empty empty))
+(insert-everywhere/in-all-words 'a ex1)
+(cons (cons 'a empty) empty)
+
+(define ex2 (cons (cons 'i empty) empty))
+(insert-everywhere/in-all-words 'a ex2)
+(cons (cons 'a (cons 'i empty))
+ (cons (cons 'i (cons 'a empty)) empty))
+
+(define ex3 (cons (cons 'h (cons 'i empty))
+ (cons (cons 'i (cons 'h empty)) empty)))
+(insert-everywhere/in-all-words 'b ex3)
+(cons (cons 'b (cons 'h (cons 'i empty)))
+ (cons (cons 'h (cons 'b (cons 'i empty)))
+ (cons (cons 'h (cons 'i (cons 'b empty)))
+ (cons (cons 'b (cons 'i (cons 'h empty)))
+ (cons (cons 'i (cons 'b (cons 'h empty)))
+ (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
blob - /dev/null
blob + 0e6c4b97629ad724e3b78fdd2260d433faf30f94 (mode 644)
--- /dev/null
+++ 13.0.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 13.0.3) (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")))))
+;Data Definition
+;A word is either
+;1. an empty list or
+;2. (cons l w) where l is a symbol (one of the
+;lowercase letters 'a, 'b, ... 'z) and w is a word.
+;
+Examples
+(cons 'h (cons 'i empty))
+(cons 'n (cons 'a (cons 'm (cons 'e empty))))
+
+A list-of-words is either
+1. (cons w empty) or
+2. (cons w low) where w is a word
+and low is a list-of-words.
+
+arrangements : word -> list-of-words
+Given a-word, return a list-of-words
+whose elements consist of words such
+that the list contains all
+the possible rearrangements (permutations)
+of the letters.
+
+(define (arrangements a-word)
+ (cond
+ [(empty? a-word) ...]
+ []))
+
blob - /dev/null
blob + 19424efc172ea592dab3e34ebd858f36dcb4a73f (mode 644)
--- /dev/null
+++ 13.0.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 13.0.3) (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")))))
+(define list-a (list 0 1 2 3 4 5))
+(define list-b (cons 0 (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 empty)))))))
+(define list-c (list (list 'adam 0) (list 'eve 1) (list 'louisXIV 2)))
+(define list-d (cons (cons 'adam (cons 0 empty))
+ (cons (cons 'eve (cons 1 empty))
+ (cons (cons 'louisXIV (cons 2 empty)) empty))))
+
+
+;Data Definition
+;A mixed-list is either
+;1. an empty list
+;2. (cons ns ml) where ns is either a number or a symbol
+;and ml is a mixed-list
+;3. (cons ml1 ml2) where ml1 and ml2 are both mixed-lists.
+;
+;
+;
+;list=? : mixed-list mixed-list -> boolean
+;Compares list1 and list2 and returns true if equal,
+;false otherwise.
+
+(define (list=? list1 list2)
+ (cond
+ [(and
+ (empty? list1)
+ (empty? list2)) true]
+ [(or
+ (empty? list1)
+ (empty? list2)) false]
+ [(and (symbol? (first list1))
+ (symbol? (first list2))
+ (symbol=? (first list1) (first list2)))
+ (list=? (rest list1) (rest list2))]
+ [(and (number? (first list1))
+ (number? (first list2))
+ (= (first list1) (first list2)))
+ (list=? (rest list1) (rest list2))]
+ [(and
+ (cons? (first list1))
+ (cons? (first list2))
+ (list=? (first list1) (first list2)))
+ (list=? (rest list1) (rest list2))]
+ [else false]))
+
+(define list-e (cons (cons 1 (cons 2 empty)) empty))
+(define list-f (list (list 1 2)))
+;(list=? list-g list-h) is incorrect for this case
+(define list-g (cons 'a
+ (cons (cons 1 empty)
+ (cons false empty))))
+(define list-h (list 'a (cons 1 empty) false))
+
+(cons (cons 1 (cons 2 empty))
+ (cons (cons 2 (cons 3 empty)) empty))
+(list (list 1 2)
+ (list 2 3))
+
+(cons 'a (list 0 false))
+(cons 'a (cons 0 (cons false empty)))
+(list 'a 0 false)
+
+(list (cons 1 (cons 13 empty)))
+(cons (cons 1 (cons 13 empty)) empty)
+(list (list 1 13))
+
+(list empty empty (cons 1 empty))
+(cons empty
+ (cons empty
+ (cons (cons 1 empty) empty)))
+(list empty empty (list 1))
+
+(cons 'a (cons (list 1) (list false empty)))
+(cons 'a (cons (cons 1 empty) (cons false (cons empty empty))))
+(list 'a (list 1) false empty)
\ No newline at end of file
blob - /dev/null
blob + 0bb774ec723b30b4db2836e2f557882f712029aa (mode 644)
--- /dev/null
+++ 14.1.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.1.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")))))
+(define list-a (list 0 1 2 3 4 5))
+(define list-b (cons 0 (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 empty)))))))
+(define list-c (list (list 'adam 0) (list 'eve 1) (list 'louisXIV 2)))
+(define list-d (cons (cons 'adam (cons 0 empty))
+ (cons (cons 'eve (cons 1 empty))
+ (cons (cons 'louisXIV (cons 2 empty)) empty))))
+
+
+;Data Definition
+;A mixed-list is either
+;1. an empty list
+;2. (cons ns ml) where ns is either a number or a symbol
+;and ml is a mixed-list
+;3. (cons ml1 ml2) where ml1 and ml2 are both mixed-lists.
+;
+;
+;
+;list=? : mixed-list mixed-list -> boolean
+;Compares list1 and list2 and returns true if equal,
+;false otherwise.
+
+(define (list=? list1 list2)
+ (cond
+ [(and
+ (empty? list1)
+ (empty? list2)) true]
+ [(or
+ (empty? list1)
+ (empty? list2)) false]
+ [(and (symbol? (first list1))
+ (symbol? (first list2))
+ (symbol=? (first list1) (first list2)))
+ (list=? (rest list1) (rest list2))]
+ [(and (number? (first list1))
+ (number? (first list2))
+ (= (first list1) (first list2)))
+ (list=? (rest list1) (rest list2))]
+ [(and
+ (cons? (first list1))
+ (cons? (first list2))
+ (list=? (first list1) (first list2)))
+ (list=? (rest list1) (rest list2))]
+ [else false]))
+
+(define list-e (cons (cons 1 (cons 2 empty)) empty))
+(define list-f (list (list 1 2)))
+;(list=? list-g list-h) is incorrect for this case
+(define list-g (cons 'a
+ (cons (cons 1 empty)
+ (cons false empty))))
+(define list-h (list 'a (cons 1 empty) false))
+
+(cons (cons 1 (cons 2 empty))
+ (cons (cons 2 (cons 3 empty)) empty))
+(list (list 1 2)
+ (list 2 3))
+
+(cons 'a (list 0 false))
+(cons 'a (cons 0 (cons false empty)))
+(list 'a 0 false)
+
+(list (cons 1 (cons 13 empty)))
+(cons (cons 1 (cons 13 empty)) empty)
+(list (list 1 13))
+
+(list empty empty (cons 1 empty))
+(cons empty
+ (cons empty
+ (cons (cons 1 empty) empty)))
+(list empty empty (list 1))
+
+(cons 'a (cons (list 1) (list false empty)))
+(cons 'a (cons (cons 1 empty) (cons false (cons empty empty))))
+(list 'a (list 1) false empty)
+
+(list (symbol=? 'a 'b) (symbol=? 'c 'c) false)
+(list false true false)
+(cons false
+ (cons true
+ (cons false empty)))
+
+(list (+ 10 20) (* 10 20) (/ 10 20))
+(list 30 200 0.5)
+(cons 30
+ (cons 200
+ (cons 0.5)))
+
+(list 'dana 'jane 'mary 'laura)
+(cons 'dana
+ (cons 'jane
+ (cons 'mary
+ (cons 'laura))))
+
+(first (list 1 2 3))
+1
+(rest (list 1 2 3))
+(list 2 3)
+(cons 2 (cons 3 empty))
+
+'(1 a 2 b 3 c)
+(list 1 'a 2 'b 3 'c)
+
+'((alan 1000)
+ (barb 2000)
+ (carl 1500)
+ (dawn 2300))
+(list (list 'alan 1000)
+ (list 'barb 2000)
+ (list 'carl 1500)
+ (list 'dawn 2300))
+
+'((My First Paper)
+ (Sean Fisler)
+ (Section 1
+ (Subsection 1 Life is difficult)
+ (Subsection 2 But learning things makes it interesting))
+ (Section 2
+ Conclusion? What conclusion?))
+(list (list 'My 'First 'Paper)
+ (list 'Sean 'Fisler)
+ (list 'Section 1
+ (list 'Subsection 1 'Life 'is 'difficult)
+ (list 'Subsection 2 'But 'learning 'things 'makes 'it 'interesting))
+ (list 'Section 2
+ (list 'Conclusion? 'What 'conclusion?))
+
\ No newline at end of file
blob - /dev/null
blob + 267ce3781fe68f8eeb834ef7c8ac3f7b618777cb (mode 644)
--- /dev/null
+++ 14.1.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.1.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")))))
+;A child structure is
+;(make-child father mother name date eyes) where
+;
+;1. name and eyes are symbols,
+;2. date is a number,
+;3. and father and mother are either
+;a. child structures or
+;b. empty.
+;
+(define-struct child (father mother name date eyes))
+;
+;A family tree node (ftn) is either
+;1. empty or
+;2. (make-child father mother name date eyes) where
+;a. father and mother are ftn,
+;b. name and eyes are symbols,
+;c. and date is a number.
+;
+
+(define Carl (make-child empty empty 'Carl 1926 'green))
+(define Bettina (make-child empty empty 'Bettina 1926 'green))
+(define Adam (make-child Carl Bettina 'Adam 1950 'yellow))
+(define Dave (make-child Carl Bettina 'Dave 1955 'black))
+(define Eva (make-child Carl Bettina 'Eva 1965 'blue))
+(define Fred (make-child empty empty 'Fred 1966 'pink))
+(define Gustav (make-child Fred Eva 'Gustav 1988 'brown))
+
+;Template
+;fun-for-ftn : ftn -> ???
+;(define (fun-for-ftn a-ftree)
+; (cond
+; [(empty? a-ftree) ...]
+; [else
+; ... (fun-for-ftn (child-father a-ftree)) ...
+; ... (fun-for-ftn (child-mother a-ftree)) ...
+; ... (child-name a-ftree) ...
+; ... (child-date a-ftree) ...
+; ... (child-eyes a-ftree) ...]))
+
+;blue-eyed-ancestor? : ftn -> boolean
+;Given a-ftree, determine if there is
+;a child in a-ftree with 'blue in eyes field.
+(define (blue-eyed-ancestor? a-ftree)
+ (cond
+ [(empty? a-ftree) false]
+ [else
+ (or
+ (symbol=? (child-eyes a-ftree) 'blue)
+ (blue-eyed-ancestor? (child-father a-ftree))
+ (blue-eyed-ancestor? (child-mother a-ftree)))]))
+
+;count-persons : ftn -> number
+;Given a-ftree, determines the number of people in the
+;family tree.
+
+;Examples:
+;(count-persons Carl)
+;1
+;(count-persons Dave)
+;3
+
+(define (count-persons a-ftree)
+ (cond
+ [(empty? a-ftree) 0]
+ [else
+ (+ 1
+ (count-persons (child-father a-ftree))
+ (count-persons (child-mother a-ftree)))]))
+;
+;average-age : ftn -> number
+;Computes the average age of all the people
+;in a family tree. Sums the ages
+;and divides by the count of persons.
+
+(define (average-age a-ftree)
+ (/ (sum-of-ages a-ftree)
+ (count-persons a-ftree)))
+;
+;sum-of-ages : ftn -> number
+;Computes the sum of the ages of
+;the people in a family tree.
+;
+;Examples:
+;(sum-of-ages Carl)
+;83
+;(sum-of-ages Eva)
+;210
+
+(define CURRENTYEAR 2009)
+
+(define (sum-of-ages a-ftree)
+ (cond
+ [(empty? a-ftree) 0]
+ [else
+ (+ (- CURRENTYEAR (child-date a-ftree))
+ (sum-of-ages (child-father a-ftree))
+ (sum-of-ages (child-mother a-ftree)))]))
+
+;A list-of-eye-colors is either
+;1. an empty list or
+;2. (cons ec loec) where ec is a symbol and
+;loec is a list-of-eye-colors.
+;(alternatively written as (list ec1 ec2 ... empty)
+;where each argument represents a symbol).
+;
+;eye-colors : ftn -> list-of-eye-colors
+
+(define (eye-colors a-ftree)
+ (cond
+ [(empty? a-ftree) empty]
+ [else (append
+ (list (child-eyes a-ftree))
+ (eye-colors (child-father a-ftree))
+ (eye-colors (child-mother a-ftree)))]))
+
+;proper-blue-eyed-ancestor? : ftn -> boolean
+;Given a-ftree, determine if the person
+;has a proper blue eyed ancestor
+;(someone in the family tree with blue eyes
+; who is not the person in question)
+
+(define (proper-blue-eyed-ancestor? a-ftree)
+ (cond
+ [(empty? a-ftree) false]
+ [else (or (blue-eyed-ancestor? (child-father a-ftree))
+ (blue-eyed-ancestor? (child-mother a-ftree)))]))
blob - /dev/null
blob + 435da52a62590013010134b95e5b659af4d8904c (mode 644)
--- /dev/null
+++ 14.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.2.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")))))
+A node is a structure
+(make-node (s n l r)) where s is a number, and
+n, l, and r are symbols.
+
+(define-struct node (ssn name left right))
\ No newline at end of file
blob - /dev/null
blob + 66bae7218de899d4c5380fa87c6ac45af73ad949 (mode 644)
--- /dev/null
+++ 14.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.2.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")))))
+;A binary-tree (BT) is either
+;1. false or
+;2. a structure (make-node s n l r)
+;where s is a number, n is a symbol,
+;and l and r are BTs.
+;
+;A node is a structure
+;(make-node s n l r) where
+;s is a number, n is a symbol,
+;and l and r are BTs.
+
+(define-struct node (ssn name left right))
+;
+;Template
+;fun-for-BT : BT -> ???
+;(define (fun-for-BT a-BT)
+; (cond
+; [(false? a-BT) ...]
+; [else
+; ... (node-ssn a-BT) ...
+; ... (node-name a-BT) ...
+; ... (fun-for-BT (node-left a-BT)) ...
+; ... (fun-for-BT (node-right a-BT)) ...]))
+;
+;contains-bt : number BT -> boolean
+;If a-num is in a-BT, then returns true.
+;Otherwise, returns false.
+
+(define (contains-bt a-num a-BT)
+ (cond
+ [(false? a-BT) false]
+ [else
+ (or (= a-num (node-ssn a-BT))
+ (contains-bt a-num (node-left a-BT))
+ (contains-bt a-num (node-right a-BT)))]))
+
+(define BT64 (make-node 64 'Pete false false))
+(define BT39 (make-node 39 'Matt false false))
+(define BT27 (make-node 27 'Ron false false))
+(define BT92 (make-node 92 'Jim false false))
+(define BT87 (make-node 87 'Sam BT64 BT39))
+(define BT24 (make-node 24 'Bob BT27 BT92))
+(define BT15 (make-node 15 'Joe BT87 BT24))
+
+;search-bt : number BT -> symbol/false
+;Find the node in a-BT with ssn n and return
+;the node's name. Otherwise, return false.
+
+(define (search-bt a-num a-BT)
+ (cond
+ [(false? a-BT) false]
+ [else
+ (cond
+ [(= a-num (node-ssn a-BT)) (node-name a-BT)]
+ [(contains-bt a-num (node-left a-BT))
+ (search-bt a-num (node-left a-BT))]
+ [(contains-bt a-num (node-right a-BT))
+ (search-bt a-num (node-right a-BT))])]))
+;
+;BST Invariant
+;
+;A binary search tree is a proper subclass of binary
+;trees. The following are BSTs:
+;
+;1. false and
+;2. (make-node soc name left right) where
+;a. left and right are BSTs,
+;b. (node-ssn left) is less than soc,
+;c. (node-ssn right) is greater than soc.
+;
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon) where n is a number and lon is a list-of-numbers
+;(alternatively written as (list n1 n2 ...))
+
+;inorder2 : BT -> list-of-numbers
+;Given a-BT, extract all the ssn from each node
+;to form a list-of-numbers
+;and sort the resulting list.
+
+(define (inorder2 a-BT)
+ (cond
+ [(false? a-BT) (list)]
+ [else (sort-list (extract a-BT))]))
+
+;extract : BT -> list-of-numbers
+;Given a-BT, extract all the ssn values of
+;each node and put them in a list.
+;
+(define (extract a-BT)
+ (cond
+ [(false? a-BT) (list)]
+ [else
+ (append (list (node-ssn a-BT))
+ (extract (node-left a-BT))
+ (extract (node-right a-BT)))]))
+
+;sort-list : list-of-numbers -> list-of-numbers.
+;
+;Given a-list, sort the list and return
+;as a new list-of-numbers. Do this
+;by inserting the first number
+;in the proper position in the
+;sorted remainder of the list. (insertion-sort)
+
+(define (sort-list a-list)
+ (cond
+ [(empty? a-list) (list)]
+ [else (insert (first a-list) (sort-list (rest a-list)))]))
+
+;insert : number list-of-numbers -> list-of-numbers
+;Given a-number and a-lon, insert a-number in the
+;proper position in a-lon to produce a list-of-numbers
+;in ascending order.
+
+(define (insert a-number a-lon)
+ (cond
+ [(empty? a-lon) (list a-number)]
+ [else
+ (cond
+ [(<= a-number (first a-lon)) (append (list a-number)
+ a-lon)]
+ [(> a-number (first a-lon)) (append (list (first a-lon))
+ (insert a-number (rest a-lon)))])]))
+
+
+;search-bst : number BST -> symbol/false
+;Given a-BST, find the node with ssn a-number
+;and return the node's name. Otherwise, return false.
+;Start with the node's ssn. If a-number matches
+;the ssn, return the name of the node.
+;If a-number is larger than the ssn, repeat the search
+;on the right node. If a-number is less than the ssn,
+;repeat the search on the left node. If the node
+;is false, return false.
+
+(define (search-bst a-number a-BST)
+ (cond
+ [(false? a-BST) false]
+ [else
+ (cond
+ [(= a-number (node-ssn a-BST)) (node-name a-BST)]
+ [(> a-number (node-ssn a-BST)) (search-bst a-number (node-right a-BST))]
+ [(< a-number (node-ssn a-BST)) (search-bst a-number (node-left a-BST))])]))
+
+;(define BST06 (make-node 6 'Pete false false))
+;(define BST18 (make-node 18 'Matt false false))
+;(define BST31 (make-node 31 'Ron false false))
+;(define BST43 (make-node 43 'Jim false false))
+;(define BST57 (make-node 57 'Sam false false))
+;(define BST69 (make-node 69 'Bob false false))
+;(define BST81 (make-node 81 'Joe false false))
+;(define BST93 (make-node 93 'Bill false false))
+;(define BST12 (make-node 12 'Don BST06 BST18))
+;(define BST37 (make-node 37 'Carl BST31 BST43))
+;(define BST63 (make-node 63 'Hank BST57 BST69))
+;(define BST87 (make-node 87 'Frank BST81 BST93))
+;(define BST25 (make-node 25 'Will BST12 BST37))
+;(define BST75 (make-node 75 'Greg BST63 BST87))
+;(define BST50 (make-node 50 'Lars BST25 BST75))
+
+(define BST10 (make-node 10 'Pete false false))
+(define BST24 (make-node 24 'Matt false false))
+(define BST99 (make-node 99 'Ron false false))
+(define BST15 (make-node 15 'Jim BST10 BST24))
+(define BST77 (make-node 77 'Sam false false))
+(define BST95 (make-node 95 'Bob false BST99))
+(define BST29 (make-node 29 'Joe BST15 false))
+(define BST89 (make-node 89 'Bill BST77 BST95))
+(define BST63 (make-node 63 'Don BST29 BST89))
+
+;
+;create-bst : BST number symbol -> BST
+;Creates a new BST from B, N, and S. This
+;new BST replaces one false node with
+;(make-node N S false false).
+;(Note: other nodes in the former BST B
+; must link to this new node)
+
+(define (create-bst B N S)
+ (cond
+ [(false? B) (make-node N S false false)]
+ [else
+ (cond
+ [(< N (node-ssn B))
+ (make-node (node-ssn B)
+ (node-name B)
+ (create-bst (node-left B) N S)
+ (node-right B))]
+ [(> N (node-ssn B))
+ (make-node (node-ssn B)
+ (node-name B)
+ (node-left B)
+ (create-bst (node-right B) N S))]
+ [(= N (node-ssn B))
+ (error 'create-bst "cannot duplicate index")])]))
+
+;To create tree A using only create-bst:
+
+(create-bst
+ (create-bst
+ (create-bst
+ (create-bst
+ (create-bst
+ (create-bst
+ (create-bst
+ (create-bst
+ (create-bst false 63 'Don)
+ 29 'Mike)
+ 89 'John)
+ 15 'Will)
+ 10 'Mitchell)
+ 24 'Pete)
+ 77 'Larry)
+ 95 'Frank)
+ 99 'Lars)
+
+;Data Definition
+;
+;A list-of-names/numbers (lonn) is either
+;1. empty or
+;2. (cons (list ssn name) lonn) where ssn is a number,
+;name is a symbol, and lonn is a list-of-names/numbers (lonn).
+;
+;(alternatively written as (list (list ssn1 name1)
+; (list ssn2 name2) ...))
+;
+;create-bst-from-list : lonn -> BST
+;
+;Given a-lonn, create a BST from the
+;list-of-names/numbers.
+
+(define (create-bst-from-list a-lonn)
+ (cond
+ [(empty? a-lonn) false]
+ [else (create-bst (create-bst-from-list (rest a-lonn))
+ (first (first a-lonn))
+ (first (rest (first a-lonn))))]))
+
+(define sample
+ '((99 o)
+ (77 l)
+ (24 i)
+ (10 h)
+ (95 g)
+ (15 d)
+ (89 c)
+ (29 b)
+ (63 a)))
blob - /dev/null
blob + 57c0feabef6f9795dac64f5f80d860b1a48c0b54 (mode 644)
--- /dev/null
+++ 14.3.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.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")))))
+A web-page is either
+1. empty or
+2. (cons s wp)
+3. (cons ewp wp)
+where s is a symbol and
+ewp, wp are web-pages.
+
blob - /dev/null
blob + 74f7d00c2867e54c5eb6c597eb28143914fa28df (mode 644)
--- /dev/null
+++ 14.3.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.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")))))
+;A web-page is either
+;1. empty or
+;2. (cons s wp)
+;3. (cons ewp wp)
+;where s is a symbol and
+;ewp, wp are web-pages (WP).
+;(ewp, embedded web page)
+;
+;Template
+;fun-for-wp : WP -> ???
+;(define (fun-for-wp a-WP)
+; (cond
+; [(empty? a-WP) ...]
+; [(symbol? (first a-WP)) ... (first a-WP) (fun-for-wp (rest a-WP)) ...]
+; [else ... (first a-WP) (fun-for-wp (rest a-WP)) ...]))
+;
+;size : wp -> number
+;Determine the size of a wp, that is,
+;how many symbols are in a-wp.
+
+(define (size a-WP)
+ (cond
+ [(empty? a-WP) 0]
+ [(symbol? (first a-WP)) (+ 1 (size (rest a-WP)))]
+ [else (+ (size (first a-WP))
+ (size (rest a-WP)))]))
+
+(define MRWP '((h i)
+ (m y)
+ (n a m e)
+ (i s)
+ (j o e)))
+
+(define MRSWP '(h i m y n a m e i s
+ (s a l l y)
+ (r i d e)
+ a n d i a m
+ (a n)
+ (a s t r o)
+ n a u t))
+
+;occurs1 : WP symbol -> number
+;Given a-WP and a-symbol, determines
+;the number of occurrences of a-symbol
+;in a-WP ignoring embedded webpages
+;(that is, do not search ewp for
+;webpages of the form (cons ewp wp)).
+
+;occurs1 : WP symbol -> number
+;(define (occurs1 a-WP a-symbol)
+; (cond
+; [(empty? a-WP) 0]
+; [(symbol? (first a-WP))
+; (cond
+; [(symbol=? (first a-WP) a-symbol) (+ 1 (occurs1 (rest a-WP) a-symbol))]
+; [else (occurs1 (rest a-WP) a-symbol)])]
+; [else (occurs1 (rest a-WP) a-symbol)]))
+
+(define (occurs1 a-WP a-symbol)
+ (cond
+ [(empty? a-WP) 0]
+ [(and (symbol? (first a-WP))
+ (symbol=? (first a-WP) a-symbol)) (+ 1 (occurs1 (rest a-WP) a-symbol))]
+ [else (occurs1 (rest a-WP) a-symbol)]))
+
+;occurs2 : WP symbol -> number
+;Determines the number of times
+;a-symbol occurs in a-WP, counting
+;embedded web pages (ewp).
+
+(define (occurs2 a-WP a-symbol)
+ (cond
+ [(empty? a-WP) 0]
+ [(symbol? (first a-WP))
+ (cond
+ [(symbol=? (first a-WP) a-symbol) (+ 1 (occurs2 (rest a-WP) a-symbol))]
+ [else (occurs2 (rest a-WP) a-symbol)])]
+ [else (+ (occurs2 (first a-WP) a-symbol)
+ (occurs2 (rest a-WP) a-symbol))]))
+;
+;replace : symbol symbol WP -> WP
+;Replace old with new in a-WP and return
+;the new WP.
+
+(define (replace new old a-WP)
+ (cond
+ [(empty? a-WP) empty]
+ [(symbol? (first a-WP))
+ (cond
+ [(symbol=? (first a-WP) old) (cons new
+ (replace new old (rest a-WP)))]
+ [else (cons (first a-WP)
+ (replace new old (rest a-WP)))])]
+ [else (cons (replace new old (first a-WP))
+ (replace new old (rest a-WP)))]))
+
+;depth : WP -> number
+;Calculates the depth of a-WP, which
+;is the number of immediately embedded web pages.
+;If there are several immediately embedded webpages,
+;we return the maximum of the depths of
+;the embedded webpages plus 1 to account for the
+;embedding of the first webpage.
+
+(define (depth a-WP)
+ (cond
+ [(empty? a-WP) 0]
+ [(symbol? (first a-WP)) (depth (rest a-WP))]
+ [else (max (+ 1 (depth (first a-WP)))
+ (depth (rest a-WP)))]))
+
+;(define NESTEDWP1 '(l e v e l z e r o
+; (o n e)
+; (o n e)
+; (o n e)
+; (o n e
+; (t w o
+; (t h r e e))
+; (t w o))))
+;(define NESTEDWP2 '(l e v e l z e r o
+; (o n e
+; (t w o
+; (t h r e e
+; (f o u r))))
+; (o n e
+; (t w o
+; (t h r e e
+; (f o u r
+; (f i v e
+; (s i x
+; (s e v e n)))))))
+; (o n e
+; (t w o
+; (t h r e e
+; (f o u r
+; (f i v e
+; (s i x))))))))
+
+
+
+
\ No newline at end of file
blob - /dev/null
blob + c29c6eb3fd44581aa159400614643155a381aa7e (mode 644)
--- /dev/null
+++ 14.4.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.4.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")))))
+;A web-page is either
+;1. empty or
+;2. (cons s wp)
+;3. (cons ewp wp)
+;where s is a symbol and
+;ewp, wp are web-pages (WP).
+;(ewp, embedded web page)
+;
+;Template
+;fun-for-wp : WP -> ???
+;(define (fun-for-wp a-WP)
+; (cond
+; [(empty? a-WP) ...]
+; [(symbol? (first a-WP)) ... (first a-WP) (fun-for-wp (rest a-WP)) ...]
+; [else ... (first a-WP) (fun-for-wp (rest a-WP)) ...]))
+;
+;size : wp -> number
+;Determine the size of a wp, that is,
+;how many symbols are in a-wp.
+
+(define (size a-WP)
+ (cond
+ [(empty? a-WP) 0]
+ [(symbol? (first a-WP)) (+ 1 (size (rest a-WP)))]
+ [else (+ (size (first a-WP))
+ (size (rest a-WP)))]))
+
+(define MRWP '((h i)
+ (m y)
+ (n a m e)
+ (i s)
+ (j o e)))
+
+(define MRSWP '(h i m y n a m e i s
+ (s a l l y)
+ (r i d e)
+ a n d i a m
+ (a n)
+ (a s t r o)
+ n a u t))
+
+;occurs1 : WP symbol -> number
+;Given a-WP and a-symbol, determines
+;the number of occurrences of a-symbol
+;in a-WP ignoring embedded webpages
+;(that is, do not search ewp for
+;webpages of the form (cons ewp wp)).
+
+;occurs1 : WP symbol -> number
+;(define (occurs1 a-WP a-symbol)
+; (cond
+; [(empty? a-WP) 0]
+; [(symbol? (first a-WP))
+; (cond
+; [(symbol=? (first a-WP) a-symbol) (+ 1 (occurs1 (rest a-WP) a-symbol))]
+; [else (occurs1 (rest a-WP) a-symbol)])]
+; [else (occurs1 (rest a-WP) a-symbol)]))
+
+(define (occurs1 a-WP a-symbol)
+ (cond
+ [(empty? a-WP) 0]
+ [(and (symbol? (first a-WP))
+ (symbol=? (first a-WP) a-symbol)) (+ 1 (occurs1 (rest a-WP) a-symbol))]
+ [else (occurs1 (rest a-WP) a-symbol)]))
+
+;occurs2 : WP symbol -> number
+;Determines the number of times
+;a-symbol occurs in a-WP, counting
+;embedded web pages (ewp).
+
+(define (occurs2 a-WP a-symbol)
+ (cond
+ [(empty? a-WP) 0]
+ [(symbol? (first a-WP))
+ (cond
+ [(symbol=? (first a-WP) a-symbol) (+ 1 (occurs2 (rest a-WP) a-symbol))]
+ [else (occurs2 (rest a-WP) a-symbol)])]
+ [else (+ (occurs2 (first a-WP) a-symbol)
+ (occurs2 (rest a-WP) a-symbol))]))
+;
+;replace : symbol symbol WP -> WP
+;Replace old with new in a-WP and return
+;the new WP.
+
+(define (replace new old a-WP)
+ (cond
+ [(empty? a-WP) empty]
+ [(symbol? (first a-WP))
+ (cond
+ [(symbol=? (first a-WP) old) (cons new
+ (replace new old (rest a-WP)))]
+ [else (cons (first a-WP)
+ (replace new old (rest a-WP)))])]
+ [else (cons (replace new old (first a-WP))
+ (replace new old (rest a-WP)))]))
+
+;depth : WP -> number
+;Calculates the depth of a-WP, which
+;is the number of immediately embedded web pages.
+;If there are several immediately embedded webpages,
+;we return the maximum of the depths of
+;the embedded webpages plus 1 to account for the
+;embedding of the first webpage.
+
+(define (depth a-WP)
+ (cond
+ [(empty? a-WP) 0]
+ [(symbol? (first a-WP)) (depth (rest a-WP))]
+ [else (max (+ 1 (depth (first a-WP)))
+ (depth (rest a-WP)))]))
+
+;(define NESTEDWP1 '(l e v e l z e r o
+; (o n e)
+; (o n e)
+; (o n e)
+; (o n e
+; (t w o
+; (t h r e e))
+; (t w o))))
+;(define NESTEDWP2 '(l e v e l z e r o
+; (o n e
+; (t w o
+; (t h r e e
+; (f o u r))))
+; (o n e
+; (t w o
+; (t h r e e
+; (f o u r
+; (f i v e
+; (s i x
+; (s e v e n)))))))
+; (o n e
+; (t w o
+; (t h r e e
+; (f o u r
+; (f i v e
+; (s i x))))))))
+
+
+
+
\ No newline at end of file
blob - /dev/null
blob + 8c2c8dc9f03f31e06c70bcecf44f635f6ec04229 (mode 644)
--- /dev/null
+++ 14.4.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 14.4.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")))))
+;A operator structure is a sturcture
+;(operator left right) where operator represents
+;one of the primitive operators mul (multiplication),
+;add (addition), sub (subtraction), and div
+;(division). Left and right are numbers or symbols
+;(symbols represent variables, which ultimately
+;represent numbers).
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+;
+;(+ 10 -10)
+;(make-add 10 -10)
+;
+;(+ (* 20 3) 33)
+;(make-add (make-mul 20 3) 33)
+;
+;(* 3.14 (* r r))
+;(make-mul 3.14 (make-mul 'r 'r))
+;
+;(+ (* 9/5 c) 32)
+;(make-add (make-mul 9/5 'c) 32)
+;
+;(+ (* 3.14 (* o o))
+; (* 3.14 (* i i)))
+;(make-add (make-mul 3.14 (make-mul 'o 'o))
+; (make-mul 3.14 (make-mul 'i 'i)))
+
+(define struct1 (make-add (make-mul 3.14 (make-mul 'o 'o))
+ (make-mul 3.14 (make-mul 'i 'i))))
+(define struct2 (make-add (make-mul 3.14 (make-mul 4 5))
+ (make-mul 3.14 (make-mul 9 2))))
+
+;The SchemeData that we consider are
+;1. numbers
+;2. symbols, and
+;3. the structures add, mul, div, sub.
+
+;Definition
+;A numeric expression is one that does not
+;require the use of variables for evaluation.
+;(an expression that has no variables)
+;
+;A numeric expression is either
+;1. a number or
+;2. a structure (make-oper ne2 ne2) where make-oper
+;corresponds to the make for the four different structures
+;add, sub, mul, div (make-add, make-sub etc.) and ne1, ne2
+;are numeric expressions.
+
+;Template
+;(define (fun-for-numeric a-data)
+; (cond
+; [(number? a-data) ...]
+; [(add? a-data) ... (fun-for-numeric (add-left a-data)) ...
+; ... (fun-for-numeric (add-right a-data)) ...]
+; [(sub? a-data) ... (fun-for-numeric (sub-left a-data)) ...
+; ... (fun-for-numeric (sub-right a-data)) ...]
+; [(mul? a-data) ... (fun-for-numeric (mul-left a-data)) ...
+; ... (fun-for-numeric (mul-right a-data)) ...]
+; [(div? a-data) ... (fun-for-numeric (div-left a-data)) ...
+; ... (fun-for-numeric (div-right a-data)) ...]))
+
+
+;
+;
+;numeric? : SchemeData -> boolean
+;Given a-data, determine if the expression it
+;represents is numeric. That is,
+;numeric? evaluates true if the SchemeData lacks symbols,
+;which represents an expression which
+;lacks variables.
+
+(define (numeric? a-data)
+ (cond
+ [(number? a-data) true]
+ [(add? a-data) (and (numeric? (add-left a-data))
+ (numeric?(add-right a-data)))]
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+ (numeric? (sub-right a-data)))]
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+ (numeric? (mul-right a-data)))]
+ [(div? a-data) (and (numeric? (div-left a-data))
+ (numeric? (div-right a-data)))]
+ [else false]))
+
+;
+;
+;evaluate-expression : SchemeData -> number
+;Given a-data, evaluates the numeric expression it represents
+;and returns the value.
+
+(define (evaluate-expression a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+ (evaluate-expression (add-right a-data)))]
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+ (evaluate-expression (sub-right a-data)))]
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+ (evaluate-expression (mul-right a-data)))]
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+ (evaluate-expression (div-right a-data)))]))
+
+;Examples
+;(evaluate-expression 5)
+;5
+;(evaluate-expression (make-add 3 4))
+;7
+;(evaluate-expression (make-add (make-add 4 9) (make-add -2 4)))
+;15
+;(evaluate-expression (make-mul (make-add 4 5) (make-div 2 3)))
+;(* 9 2/3)
+;
+;checked-evaluate-expression : SchemeData -> number
+;Given a-data, check to see if the expression is numeric.
+;If so, evaluate the expression. Return error if a-data
+;is not numeric.
+
+(define (checked-evaluate-expression a-data)
+ (cond
+ [(numeric? a-data) (evaluate-expression a-data)]
+ [else (error 'checked-evaluate-expression "expected arg: numeric expression")]))
+
+;Test
+;(checked-evaluate-expression (make-mul (make-add 9 4)
+; (make-div (make-add 4 5) 2)))
+;(* (+ 9 4)
+; (/ (+ 4 5) 2))
+;(checked-evaluate-expression (make-mul 4 'c))
+
+;subst : symbol number SchemeData -> SchemeData
+;Given the representation of a variable V (symbol),
+;the number N, and a SchemeData which represents an expression,
+;produce a new SchemeData representing an expression
+;where all occurrences of the variable V (symbol)
+;have been replaced with the number N.
+
+(define (subst V N a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(symbol? a-data) (cond
+ [(symbol=? a-data V) N]
+ [else a-data])]
+ [(add? a-data) (make-add (subst V N (add-left a-data))
+ (subst V N (add-right a-data)))]
+ [(sub? a-data) (make-sub (subst V N (sub-left a-data))
+ (subst V N (sub-right a-data)))]
+ [(mul? a-data) (make-mul (subst V N (mul-left a-data))
+ (subst V N (mul-right a-data)))]
+ [(div? a-data) (make-div (subst V N (div-left a-data))
+ (subst V N (div-right a-data)))]
+ [else a-data]))
+;Test
+(evaluate-expression (subst 'number 5 (make-add (make-mul (make-div 'number 4)
+ (make-div 'number 2))
+ (make-mul (make-sub 'number 2)
+ (make-add 'number 3)))))
+(+ (* (/ 5 4)
+ (/ 5 2))
+ (* (- 5 2)
+ (+ 5 3)))
\ No newline at end of file
blob - /dev/null
blob + 4bbb8b7738c387ef6928dc44be7608342b5d38ea (mode 644)
--- /dev/null
+++ 15.1.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 15.1.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")))))
+A parent structure is
+(make-parent children name date eyes)
+where name and eyes are symbols,
+date is a number, and children is a
+list-of-parents.
+
+A list-of-parents is
+(
+
blob - /dev/null
blob + 1bab076ef35f2d6c4d7d8d1c48b6861ac4aaec2e (mode 644)
--- /dev/null
+++ 15.1.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 15.1.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")))))
+;A parent structure is
+;(make-parent children name date eyes)
+;where name and eyes are symbols,
+;date is a number, and children is a
+;list-of-children.
+
+(define-struct parent (children name date eyes))
+;
+;A list-of-children is either
+;1. an empty list or
+;2. (cons p loc) where p is a parent
+;and loc is a list-of-children.
+
+;
+;fun-for-parent: parent -> ???
+;Template
+;(define (fun-for-parent a-parent)
+; ... (parent-children a-parent) ...
+; ... (parent-name a-parent) ...
+; ... (parent-date a-parent) ...
+; ... (parent-eyes a-parent) ...)
+
+;
+;fun-for-loc : list-of-children -> ???
+;(define (fun-for-loc a-loc)
+; (cond
+; [(empty? a-loc) ...]
+; [else ... (first a-loc) ...
+; ... (fun-for-loc (rest a-loc)) ...]))
+
+;blue-eyed-descendant? : parent -> boolean
+;Given a-parent, determines whether the parent
+;or any of its descendants have blue eyes.
+
+
+(define (blue-eyed-descendant? a-parent)
+ (cond
+ [(symbol=? (parent-eyes a-parent) 'blue) true]
+ [else (blue-eyed-children? (parent-children a-parent))]))
+;
+;blue-eyed-children? : list-of-children -> boolean
+;Given a-loc (list-of-children), return true if
+;any parent structure within the list-of-children have blue eyes
+;or if any of their descendants have blue eyes.
+
+(define (blue-eyed-children? a-loc)
+ (cond
+ [(empty? a-loc) false]
+ [else (or (blue-eyed-descendant? (first a-loc))
+ (blue-eyed-children? (rest a-loc)))]))
+
+;Third Generation
+(define Gustav (make-parent empty 'Gustav 1988 'brown))
+
+;Second Generation
+(define Fred (make-parent (list Gustav) 'Fred 1966 'pink))
+(define Eva (make-parent (list Gustav) 'Eva 1965 'blue))
+(define Dave (make-parent empty 'Dave 1955 'black))
+(define Adam (make-parent empty 'Adam 1950 'yellow))
+
+;First Generation
+(define Bettina (make-parent (list Adam Dave Eva) 'Bettina 1926 'green))
+(define Carl (make-parent (list Adam Dave Eva) 'Carl 1926 'green))
+
+;Test - All should return true
+;(blue-eyed-descendant? Bettina)
+;(blue-eyed-descendant? Eva)
+;(not (blue-eyed-descendant? Gustav))
+;(not (blue-eyed-descendant? Adam))
+;
+;how-far-removed : parent -> number/false
+;Determine how many generations removed
+;a parent is from a blue-eyed child. If
+;the parent himself has blue eyes, return 0.
+;If there is no blue-eyed child within
+;the parent's descendants, return false.
+
+(define (how-far-removed a-parent)
+ (cond
+ [(symbol=? (parent-eyes a-parent) 'blue) 0]
+ [else
+ (cond
+ [(false? (how-far-removed-children (parent-children a-parent))) false]
+ [else (+ 1
+ (how-far-removed-children (parent-children a-parent)))])]))
+
+;how-far-removed-children : list-of-children -> number/false
+;Given a-loc, determine how many generations removed
+;the children are from blue-eyed descendants. Return
+;false if there are no descendants with blue eyes, and
+;0 if one of the parent structures in a-loc has blue eyes.
+;If multiple descendants have blue-eyes, return the lowest number.
+
+(define (how-far-removed-children a-loc)
+ (cond
+ [(empty? a-loc) false]
+ [else
+ (cond
+ [(and (false? (how-far-removed (first a-loc)))
+ (false? (how-far-removed-children (rest a-loc)))) false]
+ [(false? (how-far-removed (first a-loc))) (how-far-removed-children (rest a-loc))]
+ [(false? (how-far-removed-children (rest a-loc))) (how-far-removed (first a-loc))]
+ [else (min (how-far-removed (first a-loc))
+ (how-far-removed-children (rest a-loc)))])]))
+;
+;count-descendants : parent -> number
+;Given a-parent, compute the number of descendants.
+;The parent himself is included,
+;so only nonzero natural numbers should be returned.
+;
+(define (count-descendants a-parent)
+ (+ 1
+ (count-descendants-children (parent-children a-parent))))
+
+;count-descendants-children : list-of-children -> number
+;Given a-loc, determine the number of descendants
+;of the children. The children are themselves included.
+
+(define (count-descendants-children a-loc)
+ (cond
+ [(empty? a-loc) 0]
+ [else (+ (count-descendants (first a-loc))
+ (count-descendants-children (rest a-loc)))]))
+
+;count-proper-descendants : parent -> number
+;Given a-parent, determine the number
+;of proper descendants. The parent himself
+;is not included.
+
+(define (count-proper-descendants a-parent)
+ (- (count-descendants a-parent)
+ 1))
+;
+;A list of symbols is either
+;1. an empty list or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+
+;eye-colors : parent -> list-of-symbols
+;Given a-parent, finds the eye colors of all
+;the descendants and returns them as a
+;list-of-symbols.
+
+(define (eye-colors a-parent)
+ (append (list (parent-eyes a-parent))
+ (eye-colors-children (parent-children a-parent))))
+
+;eye-colors-children : list-of-children -> list-of-symbols
+;Given a-loc, determine the eye colors
+;of the list-of-children and their descendants and return
+;them as a list-of-symbols.
+
+(define (eye-colors-children a-loc)
+ (cond
+ [(empty? a-loc) empty]
+ [else (append (eye-colors (first a-loc))
+ (eye-colors-children (rest a-loc)))]))
blob - /dev/null
blob + 8f9efe4824a567ba7b0266028fd5a06664417ef3 (mode 644)
--- /dev/null
+++ 15.3.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 15.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")))))
+A web-page (WP) is a structure:
+(make-WP header body)
\ No newline at end of file
blob - /dev/null
blob + 6f8f2ba364b0c528c84b90aad1ce7afac37484db (mode 644)
--- /dev/null
+++ 15.3.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 15.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")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+;
+;Template
+;fun-for-wp : wp -> ???
+;(define (fun-for-wp a-wp)
+; ... (wp-header a-wp) ...
+; ... (fun-for-doc (wp-doc a-wp)) ...)
+;
+;fun-for-doc : doc -> ???
+;(define (fun-for-doc a-doc)
+; (cond
+; [(empty? a-doc) ...]
+; [(symbol? (first a-doc))
+; ... (first a-doc) ...
+; ... (fun-for-doc (rest a-doc)) ...]
+; [(wp? (first a-doc))
+; ... (fun-for-wp (first a-doc)) ...
+; ... (fun-for-doc (rest a-doc)) ...]))
+;
+
+;size : wp -> number
+;Given a-wp, determine the number of
+;symbols it contains.
+
+(define (size a-wp)
+ (+ 1
+ (size-doc (wp-doc a-wp))))
+;
+;size-doc : doc -> number
+;Given a-doc, determine the size
+;of the doc, which is the number
+;of symbols it contains.
+;
+(define (size-doc a-doc)
+ (cond
+ [(empty? a-doc) 0]
+ [(symbol? (first a-doc)) (+ 1
+ (size-doc (rest a-doc)))]
+ [(wp? (first a-doc)) (+ (size (first a-doc))
+ (size-doc (rest a-doc)))]))
+;Tests
+;
+(define DOC7 (cons 'ImADoc empty))
+(define DOC6 (cons 'ImADocToo empty))
+(define WP3 (make-wp 'ImAPage empty))
+(define DOC5 (cons WP3 DOC6))
+(define WP2 (make-wp 'AmIAPageToo? DOC5))
+(define DOC4 (cons 'MaybeADoc DOC7))
+(define DOC3 (cons WP2 DOC4))
+(define DOC2 (cons 'ADoctor? DOC3))
+(define DOC1 (cons 'OrADocument? DOC2))
+(define WP1 (make-wp 'NoAWebPage DOC1))
+;
+;(size WP1)
+;8
+
+;wp-to-file : wp -> list-of-symbols
+;Given a-wp, produces a list-of-symbols containing
+;all the symbols in the headers of all web pages
+;and all the symbols within the body of a-wp,
+;excluding the bodies of immediately embedded
+;webpages.
+;
+;Examples:
+
+(define WP-6 (make-wp 'ThisIsARepeat empty))
+(define DOC-8 (cons WP-6 empty))
+(define DOC-7 (cons 'ThisIsARepeat empty))
+(define WP-5 (make-wp 'RepetionSuccess DOC-8))
+(define DOC-6 (cons WP-5 DOC-7))
+(define WP-4 (make-wp 'ThisIsARepeat DOC-6))
+(define DOC-5.5 (cons WP-4 empty))
+(define DOC-5 (cons 'NotIncluded DOC-5.5))
+(define DOC-4 (cons 'ThisIsAnExample empty))
+(define WP-3 (make-wp 'MyHeader empty))
+(define DOC-2 (cons WP-3 DOC-4))
+(define WP-2 (make-wp 'ThisIsAHeader DOC-5))
+(define DOC-1 (cons WP-2 DOC-2))
+(define WP-1 (make-wp 'TheHighestWP DOC-1))
+
+;(wp-to-file WP-1)
+;'(TheHighestWP ThisIsAHeader MyHeader ThisIsAnExample))
+;Notice that 'NotIncluded does not show up because
+;it is the body of an embedded web-page.
+;
+;wp-to-file : wp -> list-of-symbols
+(define (wp-to-file a-wp)
+ (append (list (wp-header a-wp))
+ (wp-to-file-for-doc (wp-doc a-wp))))
+;
+;wp-to-file-for-doc : doc -> list-of-symbols
+;Given a-doc, produces a list-of-symbols containing all the
+;symbols found within the body of the document as well
+;as the headers of embedded web pages. It does not
+;return the symbols of the bodies of the embedded
+;web pages, however.
+
+(define (wp-to-file-for-doc a-doc)
+ (cond
+ [(empty? a-doc) empty]
+ [(symbol? (first a-doc))
+ (append (list (first a-doc))
+ (wp-to-file-for-doc (rest a-doc)))]
+ [(wp? (first a-doc))
+ (append (list (wp-header (first a-doc)))
+ (wp-to-file-for-doc (rest a-doc)))]))
+
+
+;occurs : symbol wp -> boolean
+;Given a-symbol and a-wp, determine if
+;a-symbol appears anywhere in the webpage,
+;including in embedded webpages.
+
+(define (occurs a-symbol a-wp)
+ (cond
+ [(symbol=? a-symbol (wp-header a-wp)) true]
+ [else (occurs-doc a-symbol (wp-doc a-wp))]))
+
+;occurs-doc : symbol doc -> boolean
+;Given a-symbol and a-doc, determine if
+;a-symbol is anywhere within a-doc, including
+;in embedded web pages.
+
+(define (occurs-doc a-symbol a-doc)
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) true]
+ [else (occurs-doc a-symbol (rest a-doc))])]
+ [(wp? (first a-doc))
+ (or
+ (occurs a-symbol (first a-doc))
+ (occurs-doc a-symbol (rest a-doc)))]))
+
+;Test
+;(wp-to-file WP-1)
+
+;find-for-wp : wp symbol -> list-of-symbols/false
+;Given a-wp and a-symbol, returns a list-of-symbols containing
+;all the headers encountered on the way to find the symbol.
+;Returns empty if the symbol does not occur.
+
+;find-for-wp : wp symbol -> list-of-symbols/false
+(define (find-for-wp a-wp a-symbol)
+ (cond
+ [(occurs a-symbol a-wp) (append (list (wp-header a-wp))
+ (find-for-doc (wp-doc a-wp) a-symbol))]
+ [else empty]))
+
+;find-for-doc : doc -> list-of-symbols/false
+;Given a-doc and a-symbol, returns a list-of-symbols containing
+;all the headers encountered on the way to find a symbol.
+;Returns empty if the symbol does not occur.
+
+(define (find-for-doc a-doc a-symbol)
+ (cond
+ [(empty? a-doc) empty]
+ [(symbol? (first a-doc))
+ (find-for-doc (rest a-doc) a-symbol)]
+ [(wp? (first a-doc)) (append (find-for-wp (first a-doc) a-symbol)
+ (find-for-doc (rest a-doc) a-symbol))]))
+
+;find : wp symbol -> list-of-symbols/false
+;Given a-wp and a-symbol, return the headers
+;of the web-pages that are accessed on the way
+;to locating a-symbol. Returns false
+;if a-symbol never occurs.
+
+(define (find a-wp a-symbol)
+ (cond
+ [(empty? (find-for-wp a-wp a-symbol)) false]
+ [else (find-for-wp a-wp a-symbol)]))
\ No newline at end of file
blob - /dev/null
blob + 9bcd7210f1a8dcb2219948fdbd881c0f93b8bcda (mode 644)
--- /dev/null
+++ 16.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.2.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")))))
+A file is a symbol.
+
+A directory is either
+1. empty,
+2. (cons f dir) where f is a file
+and dir is a directory, or
+3. (cons dir1 dir2) where dir1, dir2
+are directories.
+
blob - /dev/null
blob + c7b4f58d0fb320666d2e8e4c2113cd761b35c84b (mode 644)
--- /dev/null
+++ 16.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.2.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")))))
+;A file is a symbol.
+;
+;A directory (dir) is either
+;1. empty,
+;2. (cons f dir) where f is a file
+;and dir is a directory, or
+;3. (cons dir1 dir2) where dir1, dir2
+;are directories.
+
+;Template
+;(define (fun-for-dir a-dir)
+; (cond
+; [(empty? a-dir) ...]
+; [(symbol? (first a-dir)) ... (first a-dir) ...
+; ... (fun-for-dir (rest a-dir)) ...]
+; [(cons? (first a-dir)) ... (first a-dir) ...
+; ... (fun-for-dir (rest a-dir)) ...]))
+
+;(define TS (cons 'read! (cons Text (cons Libs empty))))
+;(define Text (cons 'part1 (cons 'part2 (cons 'part3 empty))))
+(define Docs '(read!))
+(define Code '(hang draw))
+(define Libs (list Code Docs))
+(define Text '(part1 part2 part3))
+(define TS (list 'read! Text Libs))
+
+;how-many : dir -> number
+;Given a-dir, determines the number of files
+;in the directory tree.
+
+(define (how-many a-dir)
+ (cond
+ [(empty? a-dir) 0]
+ [(symbol? (first a-dir)) (+ 1
+ (how-many (rest a-dir)))]
+ [(cons? (first a-dir)) (+ (how-many (first a-dir))
+ (how-many (rest a-dir)))]))
\ No newline at end of file
blob - /dev/null
blob + e9de1e9ab38ca60e1806b6cf0daccef0edc1d5be (mode 644)
--- /dev/null
+++ 16.2.3-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.2.3-2) (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")))))
+(define-struct file (name size content))
+
+A file is a structure
+(make-file name size content) where name
+is a symbol, size is a number, and content
+is a Scheme datum.
+
blob - /dev/null
blob + 525611fface90ee0934b3059fbb5349bd9e167b7 (mode 644)
--- /dev/null
+++ 16.2.3-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.2.3-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes directories do not take up space.
+
+(define (du-dir a-dir)
+ (+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
blob - /dev/null
blob + 57cd0c62809508b96ca3a17e4e8337ee9c926d94 (mode 644)
--- /dev/null
+++ 16.2.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.2.3) (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")))))
+A directory (dir) is a structure
+(make-dir name content) where name is a symbol
+and content is a list-of-files-and-directories (LOFD).
+
+A list-of-files-and-directories (LOFD) is either
+1. empty,
+2. (cons file lofd)
+3. (cons dir lofd),
+where file is a symbol, dir is a directory,
+and lofd is a LOFD (list-of-files-and-directories).
\ No newline at end of file
blob - /dev/null
blob + de348639664cf1c860d2d68db20178864a50feeb (mode 644)
--- /dev/null
+++ 16.2.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.2.3) (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")))))
+;A directory (dir) is a structure
+;(make-dir name content size systems) where name, systems are symbols,
+;size is a number, and content is a list-of-files-and-directories (LOFD).
+;
+;A list-of-files-and-directories (LOFD) is either
+;1. empty,
+;2. (cons file lofd)
+;3. (cons dir lofd),
+;where file is a symbol, dir is a directory,
+;and lofd is a LOFD (list-of-files-and-directories).
+
+(define-struct dir (name content size systems))
+
+;Template
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lofd (dir-content a-dir)) ...))
+;
+;
+;fun-for-lofd : lofd -> ???
+;(define (fun-for-lofd a-lofd)
+; (cond
+; [(empty? a-lofd) ...]
+; [(symbol? (first a-lofd)) ... (first a-lofd) ...
+; ... (fun-for-lofd (rest a-lofd)) ...]
+; [(dir? (first a-lofd)) ... (fun-for-dir (first a-lofd)) ...
+; ... (fun-for-lofd (rest a-lofd)) ...]))
+
+;Examples:
+(define Code (make-dir 'Code '(hang draw) 5 'ReadOnly))
+(define Docs (make-dir 'Docs '(read!) 5 'ReadWrite))
+(define Libs (make-dir 'Libs (list Code Docs) 5 'Executable))
+(define Text (make-dir 'Text '(part1 part2 part3) 5 'ReadOnly))
+(define TS (make-dir 'TS (list Text Libs 'read!) 5 'None))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of
+;files in the dir tree.
+
+(define (how-many a-dir)
+ (how-many-lofd (dir-content a-dir)))
+
+
+;how-many-lofd : lofd -> number
+;Given a-lofd, determine the number of files
+;in the lofd (search within subdirectories as well).
+
+(define (how-many-lofd a-lofd)
+ (cond
+ [(empty? a-lofd) 0]
+ [(symbol? (first a-lofd)) (+ 1
+ (how-many-lofd (rest a-lofd)))]
+ [(dir? (first a-lofd)) (+ (how-many (first a-lofd))
+ (how-many-lofd (rest a-lofd)))]))
blob - /dev/null
blob + a834bb8c8c13116fbda00ddd5dbed128f59f7869 (mode 644)
--- /dev/null
+++ 16.3.2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text) (list read!-2)))
\ No newline at end of file
blob - /dev/null
blob + 72d35bd5b95fed7feb444ed05827825c8d8e0798 (mode 644)
--- /dev/null
+++ 16.3.3-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.3-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes directories do not take up space.
+
+(define (du-dir a-dir)
+ (+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
blob - /dev/null
blob + 0a056705f9d963999efc873f85df0f08ace3f9c4 (mode 644)
--- /dev/null
+++ 16.3.3-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.3-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes that for a given directory, storing a file or a directory costs 1 unit of storage space.
+
+(define (du-dir a-dir)
+ (+ (length (dir-dirs a-dir))
+ (length (dir-files a-dir))
+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
blob - /dev/null
blob + 2b728ce819d2acf43d3074ed60ee74d1509a85f0 (mode 644)
--- /dev/null
+++ 16.3.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes directories do not take up space.
+
+(define (du-dir a-dir)
+ (+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
blob - /dev/null
blob + 424aaf5ea6d318a82ec74167c70c25454277a67d (mode 644)
--- /dev/null
+++ 16.3.4-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.4-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes that for a given directory, storing a file or a directory costs 1 unit of storage space.
+
+(define (du-dir a-dir)
+ (+ (length (dir-dirs a-dir))
+ (length (dir-files a-dir))
+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
+
+;find? : dir symbol -> boolean
+;Given a-dir and a-filename, determine if the file is located within the dir tree.
+(define (find? a-dir a-filename)
+ (or (find?-for-lod (dir-dirs a-dir) a-filename)
+ (find?-for-lof (dir-files a-dir) a-filename)))
+
+;find?-for-lof : lof symbol -> boolean
+(define (find?-for-lof a-lof a-filename)
+ (cond
+ [(empty? a-lof) false]
+ [(cons? a-lof) (or
+ (symbol=? a-filename (file-name (first a-lof)))
+ (find?-for-lof (rest a-lof) a-filename))]))
+
+;find?-for-lod : lod symbol -> boolean
+(define (find?-for-lod a-lod a-filename)
+ (cond
+ [(empty? a-lod) false]
+ [(cons? a-lod) (or (find? (first a-lod) a-filename)
+ (find?-for-lod (rest a-lod) a-filename))]))
+;Data Definition:
+;A path is a list of directory names (list-of-symbols). In this instance, a path is a list which contains the name of the directory being searched as well as the sub-directory (or subdirectories) containing the file.
+;
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+
+;find : dir symbol -> path/false
+;Given a-dir and a-filename, find the subdirectory of a-dir which contains the file with the corresponding name. Return a path containing a-dir as well as the subdirectory (or subdirectories) containing a-filename. If the file is not present in the dir tree, return false.
+
+(define (find a-dir a-filename)
+ (cond
+ [(find?-for-lof (dir-files a-dir) a-filename)
+ (find-path-for-dir a-dir a-filename)]
+ [(find? a-dir a-filename) (append (list (dir-name a-dir))
+ (find-path-for-dir a-dir a-filename))]
+ [else false]))
+
+;find-path-for-dir : dir symbol -> path (list-of-symbols)
+;Given a-dir and a-filename, return the name of the subdirectory (or subdirectories) that contains a-filename as a list-of-symbols. If the file is not present in the dir tree, return empty.
+
+(define (find-path-for-dir a-dir a-filename)
+ (cond
+ [(find?-for-lof (dir-files a-dir) a-filename)
+ (append (list (dir-name a-dir))
+ (find-path-for-lod (dir-dirs a-dir) a-filename))]
+ [else (find-path-for-lod (dir-dirs a-dir) a-filename)]))
+
+;find-path-for-lod : lod symbol -> path (list-of-symbols)
+;Given a-lod and a-filename, return the name of the subdirectory (or subdirectories) that contains a-filename as a list-of-symbols. If the file is not present in the dir trees of the list-of-directories, return empty.
+
+(define (find-path-for-lod a-lod a-filename)
+ (cond
+ [(empty? a-lod) empty]
+ [(cons? a-lod) (append (find-path-for-dir (first a-lod) a-filename)
+ (find-path-for-lod (rest a-lod) a-filename))]))
+(find (create-dir "C:\\Documents and Settings\\Aaron Lin\\Desktop\\Scheme Test") '|file A.txt|)
\ No newline at end of file
blob - /dev/null
blob + 424aaf5ea6d318a82ec74167c70c25454277a67d (mode 644)
--- /dev/null
+++ 16.3.4-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.4-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes that for a given directory, storing a file or a directory costs 1 unit of storage space.
+
+(define (du-dir a-dir)
+ (+ (length (dir-dirs a-dir))
+ (length (dir-files a-dir))
+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
+
+;find? : dir symbol -> boolean
+;Given a-dir and a-filename, determine if the file is located within the dir tree.
+(define (find? a-dir a-filename)
+ (or (find?-for-lod (dir-dirs a-dir) a-filename)
+ (find?-for-lof (dir-files a-dir) a-filename)))
+
+;find?-for-lof : lof symbol -> boolean
+(define (find?-for-lof a-lof a-filename)
+ (cond
+ [(empty? a-lof) false]
+ [(cons? a-lof) (or
+ (symbol=? a-filename (file-name (first a-lof)))
+ (find?-for-lof (rest a-lof) a-filename))]))
+
+;find?-for-lod : lod symbol -> boolean
+(define (find?-for-lod a-lod a-filename)
+ (cond
+ [(empty? a-lod) false]
+ [(cons? a-lod) (or (find? (first a-lod) a-filename)
+ (find?-for-lod (rest a-lod) a-filename))]))
+;Data Definition:
+;A path is a list of directory names (list-of-symbols). In this instance, a path is a list which contains the name of the directory being searched as well as the sub-directory (or subdirectories) containing the file.
+;
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+
+;find : dir symbol -> path/false
+;Given a-dir and a-filename, find the subdirectory of a-dir which contains the file with the corresponding name. Return a path containing a-dir as well as the subdirectory (or subdirectories) containing a-filename. If the file is not present in the dir tree, return false.
+
+(define (find a-dir a-filename)
+ (cond
+ [(find?-for-lof (dir-files a-dir) a-filename)
+ (find-path-for-dir a-dir a-filename)]
+ [(find? a-dir a-filename) (append (list (dir-name a-dir))
+ (find-path-for-dir a-dir a-filename))]
+ [else false]))
+
+;find-path-for-dir : dir symbol -> path (list-of-symbols)
+;Given a-dir and a-filename, return the name of the subdirectory (or subdirectories) that contains a-filename as a list-of-symbols. If the file is not present in the dir tree, return empty.
+
+(define (find-path-for-dir a-dir a-filename)
+ (cond
+ [(find?-for-lof (dir-files a-dir) a-filename)
+ (append (list (dir-name a-dir))
+ (find-path-for-lod (dir-dirs a-dir) a-filename))]
+ [else (find-path-for-lod (dir-dirs a-dir) a-filename)]))
+
+;find-path-for-lod : lod symbol -> path (list-of-symbols)
+;Given a-lod and a-filename, return the name of the subdirectory (or subdirectories) that contains a-filename as a list-of-symbols. If the file is not present in the dir trees of the list-of-directories, return empty.
+
+(define (find-path-for-lod a-lod a-filename)
+ (cond
+ [(empty? a-lod) empty]
+ [(cons? a-lod) (append (find-path-for-dir (first a-lod) a-filename)
+ (find-path-for-lod (rest a-lod) a-filename))]))
+(find (create-dir "C:\\Documents and Settings\\Aaron Lin\\Desktop\\Scheme Test") '|file A.txt|)
\ No newline at end of file
blob - /dev/null
blob + f303b7b9d5d0ba26a16d2f6a5adb2c719c79822f (mode 644)
--- /dev/null
+++ 16.3.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes that for a given directory, storing a file or a directory costs 1 unit of storage space.
+
+(define (du-dir a-dir)
+ (+ (length (dir-dirs a-dir))
+ (length (dir-files a-dir))
+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
blob - /dev/null
blob + a724c18076475b699aefdc9b43815ba9f3ba9613 (mode 644)
--- /dev/null
+++ 16.3.4.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 16.3.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;(define-struct file (name size content))
+
+;A file is a structure
+;(make-file name size content) where name is a symbol, size is a number, and content is a Scheme datum.
+
+;A list-of-files (lof) is either
+;1. empty or
+;2. (cons f lof) where f is a file and lof is a list-of-files.
+
+;(define-struct dir (name dirs files))
+
+;A directory (dir) is a structure (make-dir n d f) where n is a symbol, d is a list-of-dirs, and f is a list-of-files.
+;
+;A list-of-dirs (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a dir and lod is a list-of-dirs.
+
+;Template
+;fun-for-file : file -> ???
+;(define (fun-for-file a-file)
+; (... (file-name a-file) ...
+; ... (file-size a-file) ...
+; ... (file-content a-file) ...))
+;
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lod (dir-dirs a-dir)) ...
+; ... (fun-for-lof (dir-files a-dir)) ...))
+;
+;fun-for-lof : lof -> ???
+;(define (fun-for-lof a-lof)
+; (cond
+; [(empty? a-lof) ...]
+; [(cons? a-lof) ... (first a-lof) ...
+; ... (fun-for-lof (rest a-lof)) ...]))
+;
+;fun-for-lod : lod -> ???
+;(define (fun-for-lod a-lod)
+; (cond
+; [(empty? a-lod) ...]
+; [(cons? a-lod) ... (fun-for-dir (first a-lod)) ...
+; ... (fun-for-lod (rest a-lod)) ...]))
+
+(define hang (make-file 'hang 8 empty))
+(define draw-1 (make-file 'draw 2 empty))
+(define read!-1 (make-file 'read! 19 empty))
+(define part1 (make-file 'part1 99 empty))
+(define part2 (make-file 'part2 52 empty))
+(define part3 (make-file 'part3 17 empty))
+(define read!-2 (make-file 'read! 10 empty))
+(define Code (make-dir 'Code empty (list hang draw-1)))
+(define Docs (make-dir 'Docs empty (list read!-1)))
+(define Libs (make-dir 'Libs (list Code Docs) empty))
+(define Text (make-dir 'Text empty (list part1 part2 part3)))
+(define TS (make-dir 'TS (list Text Libs) (list read!-2)))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of files in the dir tree.
+(define (how-many a-dir)
+ (+ (length (dir-files a-dir))
+ (how-many-lod (dir-dirs a-dir))))
+
+;how-many-lod : lod -> number
+;Given a-lod, determine the number of files in the list of directories, counting files contained in all subdirectories.
+(define (how-many-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (how-many (first a-lod))
+ (how-many-lod (rest a-lod)))]))
+
+;du-dir : dir -> number
+;Given a-dir, computes the total size (disk usage, du) of all files in the directory tree. Assumes that for a given directory, storing a file or a directory costs 1 unit of storage space.
+
+(define (du-dir a-dir)
+ (+ (length (dir-dirs a-dir))
+ (length (dir-files a-dir))
+ (du-lod (dir-dirs a-dir))
+ (du-lof (dir-files a-dir))))
+
+;du-lof : lof -> number
+;Given a-lof, compute the disk usage of the list-of-files.
+(define (du-lof a-lof)
+ (cond
+ [(empty? a-lof) 0]
+ [(cons? a-lof) (+ (file-size (first a-lof))
+ (du-lof (rest a-lof)))]))
+
+;du-lod : lod -> number
+(define (du-lod a-lod)
+ (cond
+ [(empty? a-lod) 0]
+ [(cons? a-lod) (+ (du-dir (first a-lod))
+ (du-lod (rest a-lod)))]))
+
+;find? : dir symbol -> boolean
+;Given a-dir and a-filename, determine if the file is located within the dir tree.
+(define (find? a-dir a-filename)
+ (or (find?-for-lod (dir-dirs a-dir) a-filename)
+ (find?-for-lof (dir-files a-dir) a-filename)))
+
+;find?-for-lof : lof symbol -> boolean
+(define (find?-for-lof a-lof a-filename)
+ (cond
+ [(empty? a-lof) false]
+ [(cons? a-lof) (or
+ (symbol=? a-filename (file-name (first a-lof)))
+ (find?-for-lof (rest a-lof) a-filename))]))
+
+;find?-for-lod : lod symbol -> boolean
+(define (find?-for-lod a-lod a-filename)
+ (cond
+ [(empty? a-lod) false]
+ [(cons? a-lod) (or (find? (first a-lod) a-filename)
+ (find?-for-lod (rest a-lod) a-filename))]))
+;Data Definition:
+;A path is a list of directory names (list-of-symbols). In this instance, a path is a list which contains the name of the directory being searched as well as the sub-directory (or subdirectories) containing the file.
+;
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+
+;find : dir symbol -> path/false
+;Given a-dir and a-filename, find the subdirectory of a-dir which contains the file with the corresponding name. Return a path containing a-dir as well as the subdirectory (or subdirectories) containing a-filename. If the file is not present in the dir tree, return false.
+
+(define (find a-dir a-filename)
+ (cond
+ [(find?-for-lof (dir-files a-dir) a-filename)
+ (find-path-for-dir a-dir a-filename)]
+ [(find? a-dir a-filename) (append (list (dir-name a-dir))
+ (find-path-for-dir a-dir a-filename))]
+ [else false]))
+
+;find-path-for-dir : dir symbol -> path (list-of-symbols)
+;Given a-dir and a-filename, return the name of the subdirectory (or subdirectories) that contains a-filename as a list-of-symbols. If the file is not present in the dir tree, return empty.
+
+(define (find-path-for-dir a-dir a-filename)
+ (cond
+ [(find?-for-lof (dir-files a-dir) a-filename)
+ (append (list (dir-name a-dir))
+ (find-path-for-lod (dir-dirs a-dir) a-filename))]
+ [else (find-path-for-lod (dir-dirs a-dir) a-filename)]))
+
+;find-path-for-lod : lod symbol -> path (list-of-symbols)
+;Given a-lod and a-filename, return the name of the subdirectory (or subdirectories) that contains a-filename as a list-of-symbols. If the file is not present in the dir trees of the list-of-directories, return empty.
+
+(define (find-path-for-lod a-lod a-filename)
+ (cond
+ [(empty? a-lod) empty]
+ [(cons? a-lod) (append (find-path-for-dir (first a-lod) a-filename)
+ (find-path-for-lod (rest a-lod) a-filename))]))
+(find (create-dir "C:\\Documents and Settings\\Aaron Lin\\Desktop\\Scheme Test") '|file A.txt|)
\ No newline at end of file
blob - /dev/null
blob + 4d5b99bd811b830b2d689b262ebe4759ea4bf6c1 (mode 644)
--- /dev/null
+++ 17.1.0.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.1.0) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+A list-of-data is either
+1. empty or
+2. (cons d lod) where d is a Scheme datum and lod is a list-of-data.
+
+replace-eol-with : list-of-data list-of-data -> list-of-data
+Given lod1 and lod2, append lod2 to the end of lod1.
+
+(define (replace-eol-with lod1 lod2)
+ (
+ )
\ No newline at end of file
blob - /dev/null
blob + 9d91efe3c759b773a8418ecc367064dcc20502e1 (mode 644)
--- /dev/null
+++ 17.1.0.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.1.0) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;A list-of-data (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a Scheme datum and lod is a list-of-data.
+;
+;replace-eol-with : list-of-data list-of-data -> list-of-data
+;Given lod1 and lod2, append lod2 to the end of lod1.
+
+(define (replace-eol-with lod1 lod2)
+ (cond
+ [(empty? lod1) lod2]
+ [(cons? lod1) (cons (first lod1) (replace-eol-with (rest lod1) lod2))]))
+;Tests
+;(define LIST-1 '(happy birthday to you now that you are 21))
+;(define LIST-2 '(15 and 13 equal 28))
+;(replace-eol-with LIST-1 LIST-2)
+
+;our-append : lod lod lod -> lod
+;Given lod1, lod2, and lod3, append lod3 to lod2, and append this resulting list to lod1.
+
+(define (our-append lod1 lod2 lod3)
+ (replace-eol-with lod1 (replace-eol-with lod2 lod3)))
+
+(define LIST1 '(I am))
+(define LIST2 '(6 years old))
+(define LIST3 '(on 3 1 2009))
+(our-append LIST1 LIST2 LIST3)
+
+;A list-of-symbols (los) is either
+;1. empty or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols (los).
+;
+;A list-of-numbers (lon) is either
+;1. empty or
+;2. (cons n lon) where n is a number and lon is a list-of-numbers (lon).
+;
+;cross : los lon -> lod
+;Given a-los and a-lon, find all possible cross combinations of a single symbol with a single number (a list-of-data with 2 elements). Return the possible combinations as a list of list-of-data.
+;
+;Example
+;(cross '(a b c) '(1 2))
+;'((a 1)
+; (a 2)
+; (b 1)
+; (b 2)
+; (c 1)
+; (c 2))
+
+(define (cross a-los a-lon)
+ (cond
+ [(empty? a-los) empty]
+ [(cons? a-los) (append (produce-list (first a-los) a-lon)
+ (cross (rest a-los) a-lon))]))
+
+;produce-list : symbol lon -> list of lod
+;Given a-symbol and a-lon, produce a list where a-symbol is matched with
+;every number in a-lon to form a list of two-element lists.
+
+(define (produce-list a-symbol a-lon)
+ (cond
+ [(empty? a-lon) empty]
+ [(cons? a-lon) (append (list (list a-symbol (first a-lon)))
+ (produce-list a-symbol (rest a-lon)))]))
+
+(define LIST-A '(a b c d e))
+(define LIST-B '(5 6 7 8))
+(cross LIST-A LIST-B)
\ No newline at end of file
blob - /dev/null
blob + a8d1ffcfa4c8e8fa9f8bef0b348e3d103acb1641 (mode 644)
--- /dev/null
+++ 17.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;A list-of-data (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a Scheme datum and lod is a list-of-data.
+;
+;replace-eol-with : list-of-data list-of-data -> list-of-data
+;Given lod1 and lod2, append lod2 to the end of lod1.
+
+(define (replace-eol-with lod1 lod2)
+ (cond
+ [(empty? lod1) lod2]
+ [(cons? lod1) (cons (first lod1) (replace-eol-with (rest lod1) lod2))]))
+;Tests
+;(define LIST-1 '(happy birthday to you now that you are 21))
+;(define LIST-2 '(15 and 13 equal 28))
+;(replace-eol-with LIST-1 LIST-2)
+
+;our-append : lod lod lod -> lod
+;Given lod1, lod2, and lod3, append lod3 to lod2, and append this resulting list to lod1.
+
+(define (our-append lod1 lod2 lod3)
+ (replace-eol-with lod1 (replace-eol-with lod2 lod3)))
+
+(define LIST1 '(I am))
+(define LIST2 '(6 years old))
+(define LIST3 '(on 3 1 2009))
+(our-append LIST1 LIST2 LIST3)
+
+;A list-of-symbols (los) is either
+;1. empty or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols (los).
+;
+;A list-of-numbers (lon) is either
+;1. empty or
+;2. (cons n lon) where n is a number and lon is a list-of-numbers (lon).
+;
+;cross : los lon -> lod
+;Given a-los and a-lon, find all possible cross combinations of a single symbol with a single number (a list-of-data with 2 elements). Return the possible combinations as a list of list-of-data.
+;
+;Example
+;(cross '(a b c) '(1 2))
+;'((a 1)
+; (a 2)
+; (b 1)
+; (b 2)
+; (c 1)
+; (c 2))
+
+(define (cross a-los a-lon)
+ (cond
+ [(empty? a-los) empty]
+ [(cons? a-los) (append (produce-list (first a-los) a-lon)
+ (cross (rest a-los) a-lon))]))
+
+;produce-list : symbol lon -> list of lod
+;Given a-symbol and a-lon, produce a list where a-symbol is matched with
+;every number in a-lon to form a list of two-element lists.
+
+(define (produce-list a-symbol a-lon)
+ (cond
+ [(empty? a-lon) empty]
+ [(cons? a-lon) (append (list (list a-symbol (first a-lon)))
+ (produce-list a-symbol (rest a-lon)))]))
+
+(define LIST-A '(a b c d e))
+(define LIST-B '(5 6 7 8))
+(cross LIST-A LIST-B)
\ No newline at end of file
blob - /dev/null
blob + b59675527e12195746a41160d7d917aa87c09ae8 (mode 644)
--- /dev/null
+++ 17.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;An employee is a structure
+;(make-employee name ssn rate)
+;where name is a symbol and ssn and rate are numbers.
+;
+;Work is a structure
+;(make-work name hours)
+;where name is a symbol and hours is a number.
+;
+(define-struct employee (name ssn rate))
+(define-struct work (name hours))
+;
+;A list-of-employees is either
+;1. empty or
+;2. (cons e loe)
+;where e is a employee structure and loe is a list-of-employees.
+
+;A list-of-work is either
+;1. empty or
+;2. (cons w low)
+;where w is a work structure and low is a list-of-work.
+
+;
+;Template
+;fun-for-employee : employee -> ???
+;(define (fun-for-employee an-employee)
+; ... (employee-name an-employee) ...
+; ... (employee-ssn an-employee) ...
+; ... (employee-rate an-employee) ...)
+;
+;fun-for-work : work -> ???
+;(define (fun-for-work a-work)
+; ... (work-name a-work) ...
+; ... (work-hours a-work) ...)
+
+;fun-for-loe-low : loe low -> ???
+;(define (fun-for-loe-low loe low)
+; (cond
+; [(empty? loe) ...]
+; [(cons? loe)
+; ... (employee-rate (first loe)) ...
+; ... (work-hours (first low)) ...
+; ... (fun-for-loe-low (rest loe) (rest low)) ...]))
+
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;Template
+;fun-for-2lon : lon lon -> ???
+;(define (fun-for-2lon lon1 lon2)
+; (cond
+; [(empty? lon1) ...]
+; [(cons? lon1) ... (first lon1) (first lon2) ...
+; ... (fun-for-lon (rest lon1) (rest lon2)) ...]))
+;
+;hours->wages : lon lon -> number
+;Given hours and rate, both list-of-numbers, compute the wages and return it as a list-of-numbers.
+
+(define (hours->wages hours rate)
+ (cond
+ [(empty? hours) empty]
+ [(cons? hours) (cons (* (first hours) (first rate))
+ (hours->wages (rest hours) (rest rate)))]))
+(define list1 '(4 5 6 7 8 9 10))
+(define list2 '(8.5 2.5 5.5 6.5 7.5 4.5 3.5))
+
+;employees-and-work->wages : loe low -> number
+(define (employees-and-work->wages loe low)
+ (cond
+ [(empty? loe) empty]
+ [(cons? loe)
+ (cons (* (employee-rate (first loe))
+ (work-hours (first low)))
+ (employees-and-work->wages (rest loe) (rest low)))]))
+
+(define loe1 (list (make-employee 'Mark 621 13.50)
+ (make-employee 'Zack 345 18.50)
+ (make-employee 'Ronald 224 9.50)))
+(define low1 (list (make-work 'Mark 30)
+ (make-work 'Zack 60)
+ (make-work 'Ronald 55)))
blob - /dev/null
blob + 390785bf00ee0e393ea8783c8e29f18fd91bd2e5 (mode 644)
--- /dev/null
+++ 17.2.2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.2.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+(define-struct phone-record (name number))
+
+A phone-record is a structure
+(make-phone-record s n)
+where s is a symbol and n is a number.
\ No newline at end of file
blob - /dev/null
blob + a4f54dccb5346fb67d368dbaa71aa0ab2587d2f9 (mode 644)
--- /dev/null
+++ 17.2.2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.2.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+(define-struct phone-record (name number))
+
+;A phone-record is a structure
+;(make-phone-record s n)
+;where s is a symbol and n is a number.
+;
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los)
+;where s is a symbol and los is a list-of-symbols.
+;
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;A list-of-phone-records is either
+;1. empty or
+;2. (cons pr lopr)
+;where pr is a phone-record and lopr is a list-of-phone-records.
+;
+;zip : list-of-symbols list-of-numbers -> list-of-phone-records
+;Given los (list-of-symbols representing a list of names) and lon (list-of-numbers representing a list of phone numbers), produces a list-of-phone-records.
+;ASSUMPTION: Both lists are assumed to be of the same length.
+
+(define (zip los lon)
+ (cond
+ [(empty? los) empty]
+ [(cons? los) (cons (make-phone-record (first los) (first lon))
+ (zip (rest los) (rest lon)))]))
+
+(define list-names '(Joe Sam Bill Hank Frank Ronald))
+(define list-numbers '(595 393 232 521 423 094))
+(zip list-names list-numbers)
\ No newline at end of file
blob - /dev/null
blob + 68d50a46fabcd7b22c0083dcbabfdb623ef29623 (mode 644)
--- /dev/null
+++ 17.3.0.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.3.0) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+(define-struct phone-record (name number))
+
+;A phone-record is a structure
+;(make-phone-record s n)
+;where s is a symbol and n is a number.
+;
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los)
+;where s is a symbol and los is a list-of-symbols.
+;
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;A list-of-phone-records is either
+;1. empty or
+;2. (cons pr lopr)
+;where pr is a phone-record and lopr is a list-of-phone-records.
+;
+;zip : list-of-symbols list-of-numbers -> list-of-phone-records
+;Given los (list-of-symbols representing a list of names) and lon (list-of-numbers representing a list of phone numbers), produces a list-of-phone-records.
+;ASSUMPTION: Both lists are assumed to be of the same length.
+
+(define (zip los lon)
+ (cond
+ [(empty? los) empty]
+ [(cons? los) (cons (make-phone-record (first los) (first lon))
+ (zip (rest los) (rest lon)))]))
+
+(define list-names '(Joe Sam Bill Hank Frank Ronald))
+(define list-numbers '(595 393 232 521 423 094))
+(zip list-names list-numbers)
\ No newline at end of file
blob - /dev/null
blob + 8cad3669ddd0ca13a031eecfc5ea524b7b0cbd0a (mode 644)
--- /dev/null
+++ 17.3.0.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.3.0) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los)
+;where s is a symbol and los is a list-of-symbols.
+;
+;A natural-number [>=1] (N[>=1]) is either
+;1. 1 or
+;2. (add1 n) where n is [N(>=1)]
+
+;list-pick : list-of-symbols N[>=1] -> symbol
+;Given a-los and n, find the nth symbol in a-los. The first symbol in a-los has an index of 1.
+
+(define (list-pick a-los n)
+ (cond
+ [(and (= n 1)
+ (empty? a-los)) (error 'list-pick "list too short")]
+ [(and (= n 1)
+ (cons? a-los)) (first a-los)]
+ [(and (> n 1)
+ (empty? a-los)) (error 'list-pick "list too short")]
+ [(and (> n 1)
+ (cons? a-los)) (list-pick (rest a-los) (sub1 n))]))
+
+(define los '(Fred Ted Bill Bob Joe))
+
+;A natural-number [>=0] (N[>=0]) is either
+;1. 0 or
+;2. (add1 n) where n is [N(>=0)].
+
+;list-pick : list-of-symbols N[>=1] -> symbol
+;Given a-los and n, find the nth symbol in a-los. The first symbol in a-los has an index of 0.
+;(define (list-pick0 a-los n)
+; (cond
+; [(and (= n 0)
+; (empty? a-los)) (error 'list-pick0 "list too short")]
+; [(and (= n 0)
+; (cons? a-los)) (first a-los)]
+; [(and (> n 0)
+; (empty? a-los)) (error 'list-pick0 "list too short")]
+; [(and (> n 0)
+; (cons? a-los)) (list-pick0 (rest a-los) (sub1 n))]))
+(define (list-pick0 a-los n)
+ (cond
+ [(empty? a-los) (error 'list-pick0 "list too short")]
+ [(= n 0) (first a-los)]
+ [(> n 0) (list-pick0 (rest a-los) (sub1 n))]))
+
+
+;
+;Data Definition
+;A list-of-data is either
+;1. empty or
+;2. (cons d lod)
+;where d is a Scheme datum and lod is a list-of-data.
+;
+;replace-eol-with : list-of-data list-of-data -> list-of-data
+;(define (replace-eol-with lod1 lod2)
+; (cond
+; [(empty? lod1)
+; (cond
+; [(empty? lod2) empty]
+; [(cons? lod2) lod2])]
+; [(cons? lod1)
+; (cond
+; [(empty? lod2) lod1]
+; [(cons? lod2) (append (list (first lod1))
+; (replace-eol-with (rest lod1) lod2))])]))
+
+(define (replace-eol-with lod1 lod2)
+ (cond
+ [(and (empty? lod1)
+ (empty? lod2)) empty]
+ [(and (empty? lod1)
+ (cons? lod2)) lod2]
+ [(empty? lod2) lod1]
+ [(cons? lod2) (append (list (first lod1))
+ (replace-eol-with (rest lod1) lod2))]))
+
blob - /dev/null
blob + 01e4035cca57f35db8796fbd89ee9cf6ec7899a1 (mode 644)
--- /dev/null
+++ 17.6.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+A list-of-numbers (lon) is either
+1. empty or
+2. (cons n lon)
+where n is a number and lon is a list-of-numbers (lon).
+
+merge : lon lon -> lon
+Given lon1 and lon2,
\ No newline at end of file
blob - /dev/null
blob + 9667489d47313d59ec958cdafb64de00a1fe3e85 (mode 644)
--- /dev/null
+++ 17.6.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
+;A list-of-numbers (lon) is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers (lon).
+;
+;merge : lon lon -> lon
+;Given lon1 and lon2, both lists-of-numbers arranged in ascending order, merge combines the two lists in ascending order and returns the list-of-numbers.
+
+(define (merge lon1 lon2)
+ (cond
+ [(and (empty? lon1)
+ (empty? lon2)) empty]
+ [(and (cons? lon1)
+ (empty? lon2)) lon1]
+ [(and (empty? lon1)
+ (cons? lon2)) lon2]
+ [(<= (first lon1) (first lon2)) (cons (first lon1)
+ (merge (rest lon1) lon2))]
+ [(> (first lon1) (first lon2)) (cons (first lon2)
+ (merge lon1 (rest lon2)))]))
+
+(define list-1 '(1 3 5 7 9 21 23 25 27 29 31))
+(define list-2 '(2 4 6 8 10 12 14 16))
\ No newline at end of file
blob - /dev/null
blob + 188af897f8e8b69b16cc9d4b9dc6c1c846205893 (mode 644)
--- /dev/null
+++ 17.6.2-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A word is either
+;1. empty or
+;2. (cons s w)
+;where s is a one-letter symbol ('a, 'b, ...) and '_, and w is a word.
+;
+;reveal-list : word word symbol -> word
+;Given chosen (word), status (word), and guess (one-letter symbol), return the new status word. A status word represents the progress of the hangman game. If guess matches a letter in chosen, replace '_ in status with the letter. Otherwise, return the same status word.
+;ASSUMPTION: both chosen and status are the same length.
+
+;Examples
+;(reveal-list '(b r e a d) '(b r e _ _) 'a)
+;'(b r e a _)
+;
+;(reveal-list '(b r e a d) '(b r e _ _) 'x)
+;'(b r e _ _)
+;
+;(reveal-list '(m o o n) '(_ _ _ n) 'o)
+;'(_ o o n)
+
+(define (reveal-list chosen status guess)
+ (cond
+ [(empty? chosen) empty]
+ [(cons? chosen)
+ (cond
+ [(symbol=? guess (first chosen))
+ (cons (first chosen) (reveal-list (rest chosen) (rest status) guess))]
+ [else (cons (first status) (reveal-list (rest chosen) (rest status) guess))])]))
\ No newline at end of file
blob - /dev/null
blob + 5c5d77a04852c1a8d69f8e8c7e20c5f4b116ba1c (mode 644)
--- /dev/null
+++ 17.6.2-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A word is either
+;1. empty or
+;2. (cons s w)
+;where s is a one-letter symbol ('a, 'b, ...) and '_, and w is a word.
+;
+;reveal-list : word word symbol -> word
+;Given chosen (word), status (word), and guess (one-letter symbol), return the new status word. A status word represents the progress of the hangman game. If guess matches a letter in chosen, replace '_ in status with the letter. Otherwise, return the same status word.
+;ASSUMPTION: both chosen and status are the same length.
+
+;Examples
+;(reveal-list '(b r e a d) '(b r e _ _) 'a)
+;'(b r e a _)
+;
+;(reveal-list '(b r e a d) '(b r e _ _) 'x)
+;'(b r e _ _)
+;
+;(reveal-list '(m o o n) '(_ _ _ n) 'o)
+;'(_ o o n)
+
+(define (reveal-list chosen status guess)
+ (cond
+ [(empty? chosen) empty]
+ [(cons? chosen)
+ (cond
+ [(symbol=? guess (first chosen))
+ (cons (first chosen) (reveal-list (rest chosen) (rest status) guess))]
+ [else (cons (first status) (reveal-list (rest chosen) (rest status) guess))])]))
+
+; Defines canvas width (CWIDTH) and canvas height (CHEIGHT)
+; Defines center of x-axis
+(define CWIDTH 600)
+(define CHEIGHT 600)
+(define XCENTER (/ CWIDTH 2))
+(define COLORHEAD 'brown)
+(define COLORBODY 'purple)
+(define COLORARMS 'brown)
+(define COLORLEGS 'red)
+
+; draw-noose : symbol -> boolean
+; Draws the corresponding part and returns true if evaluation succeeds, false
+; if the part to be drawn does not match this function.
+
+(define (draw-noose part)
+ (cond
+ [(symbol=? part 'noose)
+ (and
+ (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5))))]
+ [else false]))
+
+; draw-head : symbol -> boolean
+
+(define (draw-head part)
+ (cond
+ [(symbol=? part 'head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD)]
+ [else false]))
+
+; draw-body : symbol -> boolean
+
+(define (draw-body part)
+ (cond
+ [(symbol=? part 'body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY)]
+ [else false]))
+
+; draw-right-arm : symbol -> boolean
+(define (draw-right-arm part)
+ (cond
+ [(symbol=? part 'right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS)]
+ [else false]))
+
+; draw-left-arm : symbol -> boolean
+(define (draw-left-arm part)
+ (cond
+ [(symbol=? part 'left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS)]
+ [else false]))
+
+; draw-right-leg : symbol -> boolean
+(define (draw-right-leg part)
+ (cond
+ [(symbol=? part 'right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS)]
+ [else false]))
+
+; draw-left-leg : symbol -> boolean
+(define (draw-left-leg part)
+ (cond
+ [(symbol=? part 'left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)]
+ [else false]))
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (cond
+ [(symbol=? part 'noose) (draw-noose part)]
+ [(symbol=? part 'head) (draw-head part)]
+ [(symbol=? part 'body) (draw-body part)]
+ [(symbol=? part 'right-arm) (draw-right-arm part)]
+ [(symbol=? part 'left-arm) (draw-left-arm part)]
+ [(symbol=? part 'right-leg) (draw-right-leg part)]
+ [(symbol=? part 'left-leg) (draw-left-leg part)]))
+
+(start CWIDTH CHEIGHT)
+(hangman-list reveal-list draw-next-part)
\ No newline at end of file
blob - /dev/null
blob + 175af3221bd2fceb57cf1741ef99098a4e077c35 (mode 644)
--- /dev/null
+++ 17.6.2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 3ab0fe4b954fab3d808c848a2f33b6bdd2390714 (mode 644)
--- /dev/null
+++ 17.6.2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A word is either
+;1. empty or
+;2. (cons s w)
+;where s is a one-letter symbol ('a, 'b, ...) and '_, and w is a word.
+;
+;reveal-list : word word symbol -> word
+;Given chosen (word), status (word), and guess (one-letter symbol), return the new status word. A status word represents the progress of the hangman game. If guess matches a letter in chosen, replace '_ in status with the letter. Otherwise, return the same status word.
+;ASSUMPTION: both chosen and status are the same length.
+
+;Examples
+;(reveal-list '(b r e a d) '(b r e _ _) 'a)
+;'(b r e a _)
+;
+;(reveal-list '(b r e a d) '(b r e _ _) 'x)
+;'(b r e _ _)
+;
+;(reveal-list '(m o o n) '(_ _ _ n) 'o)
+;'(_ o o n)
+
+(define (reveal-list chosen status guess)
+ (cond
+ [(empty? chosen) empty]
+ [(cons? chosen)
+ (cond
+ [(symbol=? guess (first chosen))
+ (cons (first chosen) (reveal-list (rest chosen) (rest status) guess))]
+ [else (cons (first status) (reveal-list (rest chosen) (rest status) guess))])]))
\ No newline at end of file
blob - /dev/null
blob + dfebb9efabd5de18e7af976519dd338765cb7749 (mode 644)
--- /dev/null
+++ 17.6.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(define-struct punch-card (id hours))
+
+A punch-card is a structure
+(make-punch-card n1 n2)
+where both n1 and n2 are numbers.
+
\ No newline at end of file
blob - /dev/null
blob + f6510a3394c59a58dc397578323017ef8e21b51c (mode 644)
--- /dev/null
+++ 17.6.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(define-struct punch-card (id hours))
+
+;A punch-card is a structure
+;(make-punch-card n1 n2)
+;where both n1 and n2 are numbers.
+
+(define-struct employee (name id rate))
+
+;An employee is a structure
+;(make-employee s n1 n2)
+;where s is a symbol and id, rate are numbers.
+;
+;A list-of-punch-cards is either
+;1. empty or
+;2. (cons pc lopc)
+;where pc is a punch-card and lopc is a list-of-punch-cards.
+;
+;A list-of-employees is either
+;1. empty or
+;2. (cons e loe)
+;where e is an employee and loe is a list-of-employees.
+;
+;A list-of-payroll is either
+;1. empty or
+;2. (cons (list id wages) lop)
+;where id, wages are numbers and lop is a list-of-payroll.
+
+;hours->wages2 : list-of-employees list-of-punch-cards -> list-of-payroll
+;Given loe and lopc, return a list-of-payroll which represent the weekly wage for each employee. Each element within the list-of-payroll is a 2 element list, the first number representing the employee-id and the second number representing that employee's wages.
+;
+(define (hours->wages2 loe lopc)
+ (cond
+ [(or (not (cons? loe))
+ (not (cons? lopc))) (error 'hours->wages2 "expected arg: two lists")]
+ [(= (length loe) (length lopc))
+ (hours->wages2-sorted (sort-employee loe) (sort-punch-card lopc))]
+ [else (error 'hours->wages2 "lists need to be of equal length")]))
+;
+;hours->wages2-sorted : list-of-employees list-of-punch-cards -> list-of-payroll
+;Given loe and lopc, sorted by id, returns a list-of-payroll which represent the weekly wage for each employee. Each element within the list-of-payroll is a 2 element list, the first number representing the employee-id and the second number representing that employee's wages.
+
+(define (hours->wages2-sorted loe lopc)
+ (cond
+ [(empty? loe) empty]
+ [(cons? loe) (cons (list (employee-id (first loe))
+ (* (employee-rate (first loe))
+ (punch-card-hours (first lopc))))
+ (hours->wages2-sorted (rest loe) (rest lopc)))]))
+
+;sort-employee : list-of-employees -> list-of-employees
+;Given loe, sort loe by employee-id.
+
+(define (sort-employee loe)
+ (cond
+ [(empty? loe) empty]
+ [(cons? loe) (insert-employee (first loe) (sort-employee (rest loe)))]))
+
+;insert-employee : employee list-of-employees -> list-of-employees
+;Given an-employee and loe (sorted by id in ascending order), insert an-employee in the proper position in loe and return the resulting list-of-employees.
+
+(define (insert-employee an-employee loe)
+ (cond
+ [(empty? loe) (list an-employee)]
+ [(< (employee-id an-employee) (employee-id (first loe))) (cons an-employee loe)]
+ [else (cons (first loe)
+ (insert-employee an-employee (rest loe)))]))
+
+;sort-punch-card : list-of-punch-cards -> list-of-punch-cards
+;Given lopc, sort lopc by punch-card-id.
+
+(define (sort-punch-card lopc)
+ (cond
+ [(empty? lopc) empty]
+ [(cons? lopc) (insert-punch-card (first lopc) (sort-punch-card (rest lopc)))]))
+
+;insert-punch-card : punch-card list-of-punch-cards -> list-of-punch-cards
+;Given a-punch-card and lopc (sorted by id in ascending order), insert a-punch-card in the proper position in lopc and return the resulting list-of-punch-cards.
+
+(define (insert-punch-card a-punch-card lopc)
+ (cond
+ [(empty? lopc) (list a-punch-card)]
+ [(< (punch-card-id a-punch-card) (punch-card-id (first lopc)))
+ (cons a-punch-card lopc)]
+ [else (cons (first lopc)
+ (insert-punch-card a-punch-card (rest lopc)))]))
+
+;Test sort-employee, sort-punch-card, and hours->wages2
+(define emp-list (list (make-employee 'Sam 542 15.50)
+ (make-employee 'Joe 234 24.50)
+ (make-employee 'Jill 132 14.75)
+ (make-employee 'Bob 953 35.25)
+ (make-employee 'Amy 222 20.00)
+ (make-employee 'Will 100 8.75)))
+(define punch-list (list (make-punch-card 542 20)
+ (make-punch-card 234 15)
+ (make-punch-card 132 25)
+ (make-punch-card 953 35)
+ (make-punch-card 222 37)
+ (make-punch-card 100 28)))
+
+;Test insert-employee and insert-punch-card:
+;(define emp-list (list (make-employee 'Will 100 8.75)
+; (make-employee 'Jill 132 14.75)
+; (make-employee 'Amy 222 20.00)
+; (make-employee 'Joe 234 24.50)
+; (make-employee 'Sam 542 15.50)
+; (make-employee 'Bob 953 35.25)))
+;(define punch-list (list (make-punch-card 100 28)
+; (make-punch-card 132 25)
+; (make-punch-card 222 37)
+; (make-punch-card 234 15)
+; (make-punch-card 542 20)
+; (make-punch-card 953 35)))
+;
+;(define new-guy (make-employee 'Newbie 435 13.25))
+;(define new-punch (make-punch-card 435 35))
+;(insert-employee new-guy emp-list)
+
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;value : list-of-numbers list-of-numbers -> number
+;Computes the sum of all the products of an element in list1 by an element in list2 with the same index.
+;ASSUMPTION: list1 and list2 are the same length.
+;
+;Example:
+;(value '(4 5 6) '(1 2 3))
+;(+ (* 4 1)
+; (* 5 2)
+; (* 6 3))
+
+(define (value list1 list2)
+ (cond
+ [(empty? list1) 0]
+ [(cons? list1) (+ (* (first list1) (first list2))
+ (value (rest list1) (rest list2)))]))
\ No newline at end of file
blob - /dev/null
blob + ebabf587ac6930324048c1e5acdb6ff9adb73fa0 (mode 644)
--- /dev/null
+++ 17.6.5.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.5) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+A name is either
+1. empty or
+2.
+
+gift-pick : list-of-names -> list-of-names
+Given alon
\ No newline at end of file
blob - /dev/null
blob + fdcd29493c709e122939742af74ba71713ee18d9 (mode 644)
--- /dev/null
+++ 17.6.5.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.5) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A list-of-names is either
+;1. empty or
+;2. (cons s lon)
+;where s is a symbol and lon is a list-of-names.
+;
+;A list-of-list-of-names is either
+;1. empty, or
+;2. (cons lon lolon)
+;where lon is a list-of-names and lolon is a list-of-list-of-names.
+
+;gift-pick : list-of-names -> list-of-names
+;Given names, return a randomly picked re-arrangement of list-of-names where not a single name is found in an identical position in the new list as in alon.
+
+(define (gift-pick names)
+ (random-pick
+ (non-same names (arrangements names))))
+
+;random-pick : list-of-list-of-names -> list-of-names
+;Given a-lolon, pick one list-of-names randomly.
+
+(define (random-pick a-lolon)
+ (pick-nth a-lolon (+ 1 (random (length a-lolon)))))
+
+;pick-nth : list-of-list-of-names N[>=1] -> list-of-names
+;Given a-lolon, pick the n-th list-of-names. The first list-of-names has an index of 1.
+
+(define (pick-nth a-lolon n)
+ (cond
+ [(empty? a-lolon) (error 'pick-nth "Unexpected error")]
+ [(= n 1) (first a-lolon)]
+ [(> n 1) (pick-nth (rest a-lolon) (sub1 n))]))
+
+;non-same : list-of-names list-of-list-of-names -> list-of-list-of-names
+;Given a-lon and a-lolon, return all list-of-names within a-lolon for those list-of-names where not a single name occupies the same position in the index as in a-lon.
+
+(define (non-same a-lon a-lolon)
+ (cond
+ [(empty? a-lolon) empty]
+ [(no-common-index? (first a-lolon) a-lon) (append (list (first a-lolon))
+ (non-same a-lon (rest a-lolon)))]
+ [else (non-same a-lon (rest a-lolon))]))
+
+;no-common-index? : list-of-names list-of-names -> boolean
+;Given lon1 and lon2, return true if not a single name occupies the same index in lon1 and lon2. False otherwise.
+;ASSUMPTION: Both lists are of the same length.
+
+(define (no-common-index? lon1 lon2)
+ (cond
+ [(empty? lon1) true]
+ [(symbol=? (first lon1) (first lon2)) false]
+ [else (no-common-index? (rest lon1) (rest lon2))]))
+
+;arrangements : list-of-names -> list-of-list-of-names
+;Given names (a list-of-names), return all permutations of the names.
+
+(define (arrangements names)
+ (cond
+ [(empty? names) (list empty)]
+ [else (insert-in-lolon (first names) (arrangements (rest names)))]))
+
+;insert-in-lolon : symbol list-of-list-of-names -> list-of-list-of-names
+;Given a-symbol and a-lolon, insert a-symbol into every position in each list-of-names element within a-lolon to return a new list-of-list-of-names.
+
+(define (insert-in-lolon a-symbol a-lolon)
+ (cond
+ [(empty? a-lolon) empty]
+ [(cons? a-lolon)
+ (append (insert-name a-symbol (first a-lolon) (length (first a-lolon)))
+ (insert-in-lolon a-symbol (rest a-lolon)))]))
+
+;insert-name : symbol list-of-names N[>=0] -> list-of-list-of-names
+;Given a-symbol, insert it into every position in names starting at the n-th position, continuing to the very beginning of the list-of-names (n=0), to return a list-of-list-of-names.
+
+(define (insert-name a-symbol names n)
+ (cond
+ [(= n 0) (list (insert-name-at-posn a-symbol names n))]
+ [(cons? names) (append (list (insert-name-at-posn a-symbol names n))
+ (insert-name a-symbol names (sub1 n)))]
+ [(empty? names) (error 'insert-name "unexpected error")]))
+
+;insert-name-at-posn : symbol list-of-names N[>=0] -> list-of-names
+;Given a-symbol (symbol), names (list-of-names), and n (N[>=0]), insert a-symbol into names at the n-th position and return the list-of-names.
+
+(define (insert-name-at-posn a-symbol names n)
+ (cond
+ [(= n 0) (append (list a-symbol) names)]
+ [(cons? names) (append (list (first names))
+ (insert-name-at-posn a-symbol (rest names) (sub1 n)))]
+ [(empty? names) (error 'insert-name-at-posn "list too short")]))
\ No newline at end of file
blob - /dev/null
blob + 897b921a1ea62577d36d04ad14257eef0f20c023 (mode 644)
--- /dev/null
+++ 17.6.6.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.6) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+A list-of-symbols is either
+1. empty or
+2. (cons s los)
+where s is a one-letter symbol and los is a list-of-symbols.
+
+DNAprefix : list-of-symbols list-of-symbols -> boolean
+Given pattern and search-string, determine if pattern occurs in search-string.
+
+(define (DNAprefix pattern search-string)
+ (
\ No newline at end of file
blob - /dev/null
blob + c60a9d70868fd81b13c75c4e0c81034aa6be909a (mode 644)
--- /dev/null
+++ 17.6.6.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.6) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los)
+;where s is a one-letter symbol and los is a list-of-symbols.
+;
+;DNAprefix : list-of-symbols list-of-symbols -> boolean
+;Given pattern and search-string, determine if pattern is a prefix in search-string.
+
+;(define (DNAprefix pattern search-string)
+; (cond
+; [(> (length pattern) (length search-string)) false]
+; [(empty? pattern) true]
+; [else (and (symbol=? (first pattern)
+; (first search-string))
+; (DNAprefix (rest pattern) (rest search-string)))]))
+
+;(define (DNAprefix pattern search-string)
+; (cond
+; [(and (empty? pattern)
+; (empty? search-string)) true]
+; [(and (empty? pattern)
+; (cons? search-string)) true]
+; [(and (cons? pattern)
+; (empty? search-string)) false]
+; [(and (cons? pattern)
+; (cons? search-string)) (and (symbol=? (first pattern) (first search-string))
+; (DNAprefix (rest pattern) (rest search-string)))]))
+
+(define (DNAprefix pattern search-string)
+ (cond
+ [(empty? pattern) true]
+ [(empty? search-string) false]
+ [else (and (symbol=? (first pattern) (first search-string))
+ (DNAprefix (rest pattern) (rest search-string)))]))
+
+;properDNAprefix : list-of-symbols list-of-symbols -> symbol/boolean
+;Given pattern and search-string, return the first symbol in search-string right after pattern if pattern is a proper prefix of search-string. However, if pattern and search-string are identical lists, then simply return true. If pattern is not a prefix, return false.
+
+;(define (properDNAprefix pattern search-string)
+; (cond
+; [(> (length pattern) (length search-string)) false]
+; [(empty? pattern)
+; (cond
+; [(empty? search-string) true]
+; [else (first search-string)])]
+; [else
+; (cond
+; [(symbol=? (first pattern)
+; (first search-string))
+; (properDNAprefix (rest pattern) (rest search-string))]
+; [else false])]))
+
+(define (properDNAprefix pattern search-string)
+ (cond
+ [(and (empty? pattern)
+ (empty? search-string)) true]
+ [(and (empty? pattern)
+ (cons? search-string)) (first search-string)]
+ [(and (cons? search-string)
+ (symbol=? (first pattern) (first search-string)))
+ (properDNAprefix (rest pattern) (rest search-string))]
+ [else false]))
+
+(properDNAprefix empty empty)
+(properDNAprefix empty '(a))
+(properDNAprefix '(a) empty)
+(properDNAprefix '(a) '(a))
+(properDNAprefix '(a) '(a b))
\ No newline at end of file
blob - /dev/null
blob + a3020a00e564bd763067fc3dc75ef9b52857d5d4 (mode 644)
--- /dev/null
+++ 17.7.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.7.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A operator structure is a sturcture
+;(operator left right) where operator represents
+;one of the primitive operators mul (multiplication),
+;add (addition), sub (subtraction), and div
+;(division). Left and right are numbers or symbols
+;(symbols represent variables, which ultimately
+;represent numbers).
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+;
+;(+ 10 -10)
+;(make-add 10 -10)
+;
+;(+ (* 20 3) 33)
+;(make-add (make-mul 20 3) 33)
+;
+;(* 3.14 (* r r))
+;(make-mul 3.14 (make-mul 'r 'r))
+;
+;(+ (* 9/5 c) 32)
+;(make-add (make-mul 9/5 'c) 32)
+;
+;(+ (* 3.14 (* o o))
+; (* 3.14 (* i i)))
+;(make-add (make-mul 3.14 (make-mul 'o 'o))
+; (make-mul 3.14 (make-mul 'i 'i)))
+
+(define struct1 (make-add (make-mul 3.14 (make-mul 'o 'o))
+ (make-mul 3.14 (make-mul 'i 'i))))
+(define struct2 (make-add (make-mul 3.14 (make-mul 4 5))
+ (make-mul 3.14 (make-mul 9 2))))
+
+;The SchemeData that we consider are
+;1. numbers
+;2. symbols, and
+;3. the structures add, mul, div, sub.
+
+;Definition
+;A numeric expression is one that does not
+;require the use of variables for evaluation.
+;(an expression that has no variables)
+;
+;A numeric expression is either
+;1. a number or
+;2. a structure (make-oper ne2 ne2) where make-oper
+;corresponds to the make for the four different structures
+;add, sub, mul, div (make-add, make-sub etc.) and ne1, ne2
+;are numeric expressions.
+
+;Template
+;(define (fun-for-numeric a-data)
+; (cond
+; [(number? a-data) ...]
+; [(add? a-data) ... (fun-for-numeric (add-left a-data)) ...
+; ... (fun-for-numeric (add-right a-data)) ...]
+; [(sub? a-data) ... (fun-for-numeric (sub-left a-data)) ...
+; ... (fun-for-numeric (sub-right a-data)) ...]
+; [(mul? a-data) ... (fun-for-numeric (mul-left a-data)) ...
+; ... (fun-for-numeric (mul-right a-data)) ...]
+; [(div? a-data) ... (fun-for-numeric (div-left a-data)) ...
+; ... (fun-for-numeric (div-right a-data)) ...]))
+
+
+;
+;
+;numeric? : SchemeData -> boolean
+;Given a-data, determine if the expression it
+;represents is numeric. That is,
+;numeric? evaluates true if the SchemeData lacks symbols,
+;which represents an expression which
+;lacks variables.
+
+(define (numeric? a-data)
+ (cond
+ [(number? a-data) true]
+ [(add? a-data) (and (numeric? (add-left a-data))
+ (numeric?(add-right a-data)))]
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+ (numeric? (sub-right a-data)))]
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+ (numeric? (mul-right a-data)))]
+ [(div? a-data) (and (numeric? (div-left a-data))
+ (numeric? (div-right a-data)))]
+ [else false]))
+
+;
+;
+;evaluate-expression : SchemeData -> number
+;Given a-data, evaluates the numeric expression it represents
+;and returns the value.
+
+(define (evaluate-expression a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+ (evaluate-expression (add-right a-data)))]
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+ (evaluate-expression (sub-right a-data)))]
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+ (evaluate-expression (mul-right a-data)))]
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+ (evaluate-expression (div-right a-data)))]))
+
+;Examples
+;(evaluate-expression 5)
+;5
+;(evaluate-expression (make-add 3 4))
+;7
+;(evaluate-expression (make-add (make-add 4 9) (make-add -2 4)))
+;15
+;(evaluate-expression (make-mul (make-add 4 5) (make-div 2 3)))
+;(* 9 2/3)
+;
+;checked-evaluate-expression : SchemeData -> number
+;Given a-data, check to see if the expression is numeric.
+;If so, evaluate the expression. Return error if a-data
+;is not numeric.
+
+(define (checked-evaluate-expression a-data)
+ (cond
+ [(numeric? a-data) (evaluate-expression a-data)]
+ [else (error 'checked-evaluate-expression "expected arg: numeric expression")]))
+
+;Test
+;(checked-evaluate-expression (make-mul (make-add 9 4)
+; (make-div (make-add 4 5) 2)))
+;(* (+ 9 4)
+; (/ (+ 4 5) 2))
+;(checked-evaluate-expression (make-mul 4 'c))
+
+;subst : symbol number SchemeData -> SchemeData
+;Given the representation of a variable V (symbol),
+;the number N, and a SchemeData which represents an expression,
+;produce a new SchemeData representing an expression
+;where all occurrences of the variable V (symbol)
+;have been replaced with the number N.
+
+(define (subst V N a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(symbol? a-data) (cond
+ [(symbol=? a-data V) N]
+ [else a-data])]
+ [(add? a-data) (make-add (subst V N (add-left a-data))
+ (subst V N (add-right a-data)))]
+ [(sub? a-data) (make-sub (subst V N (sub-left a-data))
+ (subst V N (sub-right a-data)))]
+ [(mul? a-data) (make-mul (subst V N (mul-left a-data))
+ (subst V N (mul-right a-data)))]
+ [(div? a-data) (make-div (subst V N (div-left a-data))
+ (subst V N (div-right a-data)))]
+ [else a-data]))
+;Test
+;(evaluate-expression (subst 'number 5 (make-add (make-mul (make-div 'number 4)
+; (make-div 'number 2))
+; (make-mul (make-sub 'number 2)
+; (make-add 'number 3)))))
+;(+ (* (/ 5 4)
+; (/ 5 2))
+; (* (- 5 2)
+; (+ 5 3)))
\ No newline at end of file
blob - /dev/null
blob + f897707b4c9ee0501ae994cd048180627d7f7dc7 (mode 644)
--- /dev/null
+++ 17.7.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.7.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A SchemeData (a representation of a Scheme expression) is either
+;1. a number,
+;2. a symbol,
+;3. an operator structure, or
+;4. a function.
+
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+
+;An operator is a structure
+;(make-operator left right)
+;where operator is replaced by one of the four operators:
+;1. add (addition)
+;2. sub (subtraction)
+;3. mul (multiplication)
+;4. div (division)
+;and left and right are SchemeData.
+;
+;An operator structure
+;(make-operator left right)
+;represents the expression
+;(operator left right)
+;in Scheme.
+
+(define-struct function (name arg))
+
+;A function is a structure
+;(make-function name arg)
+;where name is a symbol and arg is a SchemeData.
+;
+;A function structure
+;(make-function name arg)
+;represents the expression
+;(name arg)
+;
+;Examples:
+;
+;(f (+ 1 1))
+;(make-function 'f (make-add (1 1)))
+;
+;(* 3 (g 2))
+;(make-mul 3 (make-function 'g 2))
+
+(define-struct definition (function parameter body))
+
+;A definition is a structure
+;(make-definition function parameter body)
+;where function and parameter are symbols and body is a SchemeData.
+
+;Examples:
+;(define (f x) (+ 3 x))
+;(make-definition ('f 'x (make-add 3 'x)))
+;
+;(define (g x) (* 3 x))
+;(make-definition ('g 'x (make-mul 3 'x)))
+;
+;(define (h u) (f (* 2 u)))
+;(make-definition ('h 'u (make-function 'f (make-mul 2 u))))
+;
+;(define (i v) (+ (* v v) (* v v)))
+;(make-definition ('i 'v (make-add (make-mul v v)
+; (make-mul v v))))
+;
+;(define (k w) (* (h w) (i w)))
+;(make-definition ('k 'w (make-mul (make-function 'h 'w)
+; (make-function 'i 'w))))
+
+;numeric? : SchemeData -> boolean
+;Given a-data, determine if the expression it
+;represents is numeric. That is,
+;numeric? evaluates true if the SchemeData lacks symbols,
+;which represents an expression which
+;lacks variables.
+
+(define (numeric? a-data)
+ (cond
+ [(number? a-data) true]
+ [(add? a-data) (and (numeric? (add-left a-data))
+ (numeric?(add-right a-data)))]
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+ (numeric? (sub-right a-data)))]
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+ (numeric? (mul-right a-data)))]
+ [(div? a-data) (and (numeric? (div-left a-data))
+ (numeric? (div-right a-data)))]
+ [else false]))
+
+;evaluate-expression : SchemeData -> number
+;Given a-data, evaluates the numeric expression it represents
+;and returns the value.
+
+(define (evaluate-expression a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+ (evaluate-expression (add-right a-data)))]
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+ (evaluate-expression (sub-right a-data)))]
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+ (evaluate-expression (mul-right a-data)))]
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+ (evaluate-expression (div-right a-data)))]))
+
+;subst : symbol number SchemeData -> SchemeData
+;Given the representation of a variable V (symbol),
+;the number N, and a SchemeData which represents an expression,
+;produce a new SchemeData representing an expression
+;where all occurrences of the variable V (symbol)
+;have been replaced with the number N.
+
+(define (subst V N a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(symbol? a-data) (cond
+ [(symbol=? a-data V) N]
+ [else a-data])]
+ [(add? a-data) (make-add (subst V N (add-left a-data))
+ (subst V N (add-right a-data)))]
+ [(sub? a-data) (make-sub (subst V N (sub-left a-data))
+ (subst V N (sub-right a-data)))]
+ [(mul? a-data) (make-mul (subst V N (mul-left a-data))
+ (subst V N (mul-right a-data)))]
+ [(div? a-data) (make-div (subst V N (div-left a-data))
+ (subst V N (div-right a-data)))]
+ [else a-data]))
+
+;evaluate-with-one-def : SchemeData definition -> number
+;Given an-exp and P, evaluate the argument an-exp, substitute that for the parameter in P, and then evaluate the body of P.
+
+(define (evaluate-with-one-def an-exp P)
+ (cond
+ [(and (definition? P)
+ (numeric? an-exp)) (evaluate-expression (subst (definition-parameter P)
+ (evaluate-expression an-exp)
+ (definition-body P)))]
+ [else (error 'evaluate-with-one-def "unexpected error")]))
+
+;evaluate-with-defs : SchemeData list-of-definitions -> list-of-numbers
+;Given an-exp and defs, evaluate an-exp, substitute this value in the body for each definition in the list-of-definitions in place of each one's parameter and evaluate the resulting body.
+(define (evaluate-with-defs an-exp defs)
+ (cond
+ [(empty? defs) empty]
+ [(cons? defs) (cons (evaluate-with-one-def an-exp (first defs))
+ (evaluate-with-defs an-exp (rest defs)))]))
+
+;mydefine : number -> number
+;(define (mydefine x)
+; (* (* (+ 4 x)
+; (/ 3 x))
+; (- x 1)))
+;(define (myotherdefine x)
+; (/ (+ (* 5 x)
+; (* x 4))
+; (* (+ 4 x)
+; (+ 3 x))))
+;
+;(define mydefine! (make-definition 'mydefine
+; 'x
+; (make-mul (make-mul (make-add 4 'x)
+; (make-div 3 'x))
+; (make-sub 'x 1))))
+;(define myotherdefine!
+; (make-definition 'myotherdefine!
+; 'x
+; (make-div (make-add (make-mul 5 'x)
+; (make-mul 'x 4))
+; (make-mul (make-add 4 'x)
+; (make-add 3 'x)))))
+;(define myexp (+ (* 3 4)
+; (/ 6 3)))
+;(define myexp! (make-add (make-mul 3 4)
+; (make-div 6 3)))
+;
+;(evaluate-with-defs myexp! (list mydefine! myotherdefine!))
+;(list (mydefine myexp) (myotherdefine myexp))
\ No newline at end of file
blob - /dev/null
blob + 458351c07b95bf20c8cd30c89cb0c6c74779d2ac (mode 644)
--- /dev/null
+++ 17.8.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.8.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+A list-of-numbers is either
+1. empty or
+2. (cons n lon)
+where n is a number and lon is a list-of-numbers.
+
+list=?
\ No newline at end of file
blob - /dev/null
blob + de58247f1393c71e07baeff14d65d57eaeaf80f6 (mode 644)
--- /dev/null
+++ 17.8.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.8.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;list=?-1 and list=?-2 : list-of-numbers list-of-numbers -> boolean
+;Given lon1 and lon2, return true if the two lists are equal, false otherwise.
+
+;(define (list=?-1 lon1 lon2)
+; (cond
+; [(and (empty? lon1)
+; (empty? lon2)) true]
+; [(and (cons? lon1)
+; (empty? lon2)) false]
+; [(and (empty? lon1)
+; (cons? lon2)) false]
+; [(and (cons? lon1)
+; (cons? lon2)) (and (= (first lon1) (first lon2))
+; (list=?-1 (rest lon1) (rest lon2)))]))
+
+(define (list=?-1 lon1 lon2)
+ (cond
+ [(and (empty? lon1)
+ (empty? lon2)) true]
+ [(and (cons? lon1)
+ (cons? lon2)) (and (= (first lon1) (first lon2))
+ (list=?-1 (rest lon1) (rest lon2)))]
+ [else false]))
+
+
+(define (list=?-2 lon1 lon2)
+ (cond
+ [(empty? lon1) (empty? lon2)]
+ [(cons? lon1) (and (cons? lon2)
+ (= (first lon1) (first lon2))
+ (list=?-2 (rest lon1) (rest lon2)))]))
+
+;Test
+;(list=?-2 empty empty)
+;(list=?-2 empty '(1))
+;(list=?-2 '(1) empty)
+;(list=?-2 '(1) '(1))
+;(list=?-2 '(1) '(1 2))
+
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los)
+;where s is a symbol and los is a list-of-symbols.
+;
+;sym-list=? : list-of-symbols list-of-symbols -> boolean
+(define (sym-list=? los1 los2)
+ (cond
+ [(and (empty? los1)
+ (empty? los2)) true]
+ [(and (cons? los1)
+ (cons? los2)) (and (symbol=? (first los1) (first los2))
+ (sym-list=? (rest los1) (rest los2)))]
+ [else false]))
+
+;sort-lon : list-of-numbers -> list-of-numbers
+;Given a-lon, sort lon.
+
+(define (sort-lon a-lon)
+ (cond
+ [(empty? a-lon) empty]
+ [(cons? a-lon) (insert-number (first a-lon) (sort-lon (rest a-lon)))]))
+
+;insert-number : number list-of-numbers -> list-of-numbers
+;Given a-number and a-lon (sorted in ascending order), insert a-number in the proper position in lon to return the resulting sorted list-of-numbers.
+
+(define (insert-number a-number a-lon)
+ (cond
+ [(empty? a-lon) (list a-number)]
+ [(< a-number (first a-lon)) (append (list a-number)
+ a-lon)]
+ [else (append (list (first a-lon))
+ (insert-number a-number (rest a-lon)))]))
+
+;contains-same-numbers : list-of-numbers list-of-numbers -> boolean
+;Given lon1 and lon2, return true if the two lists have the same numbers, regardless of order.
+
+(define (contains-same-numbers lon1 lon2)
+ (list=?-1 (sort-lon lon1) (sort-lon lon2)))
+
+;Data Definition
+;
+;An atom is either
+;1. a number,
+;2. a symbol, or
+;3. a boolean.
+;
+;A list-of-atoms is either
+;1. empty or
+;2. (cons a loa)
+;where a is an atom and loa is a list-of-atoms.
+;
+;list-equal? : list-of-atoms list-of-atoms -> boolean
+;Given loa1 and loa2, determine if the two lists are equal (corresponding elements within the list have equivalent atoms).
+
+(define (list-equal? loa1 loa2)
+ (cond
+ [(and (empty? loa1)
+ (empty? loa2)) true]
+ [(and (cons? loa1)
+ (empty? loa2)) false]
+ [(and (empty? loa1)
+ (cons? loa2)) false]
+ [(and (cons? loa1)
+ (cons? loa2)) (and (atoms-equal? (first loa1) (first loa2))
+ (list-equal? (rest loa1) (rest loa2)))]))
+
+;atoms-equal? : atom atom -> boolean
+;Given atom1 and atom2, determine if the two atoms are equal.
+
+(define (atoms-equal? atom1 atom2)
+ (cond
+ [(and (number? atom1)
+ (number? atom2)) (= atom1 atom2)]
+ [(and (boolean? atom1)
+ (boolean? atom2)) (boolean=? atom1 atom2)]
+ [(and (symbol? atom1)
+ (symbol? atom2)) (symbol=? atom1 atom2)]
+ [else false]))
+
+;(define atomic1 (list 5 'hi 'joe true false))
+;(define atomic2 (list 5 'hi 'joe true false))
+
+;A web-page (wp) is either
+;1. empty,
+;2. (cons s wp), or
+;3. (cons ewp wp)
+;where s is a symbol, wp is a web-page (wp), and ewp is a web-page (wp).
+
+;wp=? : wp wp -> boolean
+;Given wp1 and wp2, determine if the two web-pages are identical.
+
+(define (wp=? wp1 wp2)
+ (cond
+ [(empty? wp1) (empty? wp2)]
+ [(symbol? (first wp1)) (and (cons? wp2) (symbol? (first wp2))
+ (symbol=? (first wp1) (first wp2))
+ (wp=? (rest wp1) (rest wp2)))]
+ [(list? (first wp1)) (and (cons? wp2) (list? (first wp2))
+ (wp=? (first wp1) (first wp2))
+ (wp=? (rest wp1) (rest wp2)))]))
+
+;(define empwp empty)
+;(define swpwp (cons 'firstPage (cons 'secondPage empty)))
+;(define ewpwp (cons (cons 'firstPage empty) (cons 'secondPage empty)))
+;
+;(wp=? empwp empwp)
+;(not (wp=? swpwp empwp))
+;(not (wp=? ewpwp empwp))
+;(not (wp=? empwp swpwp))
+;(wp=? swpwp swpwp)
+;(not (wp=? ewpwp swpwp))
+;(not (wp=? empwp ewpwp))
+;(not (wp=? swpwp ewpwp))
+;(wp=? ewpwp ewpwp)
+
+;posn=? : posn posn -> boolean
+;Given posn1 and posn2, determine if they are equal.
+
+(define (posn=? posn1 posn2)
+ (and (posn? posn1) (posn? posn2)
+ (= (posn-x posn1) (posn-x posn2))
+ (= (posn-y posn1) (posn-y posn2))))
+
+(define-struct node (name left right))
+
+;A binary tree (BT) either
+;1. empty or
+;2. (make-node name left right)
+;(make-node name left right)
+;where name is a symbol and left, right are binary trees (BT).
+
+;tree=? : BT BT -> boolean
+(define (tree=? bt1 bt2)
+ (cond
+ [(empty? bt1) (empty? bt2)]
+ [(node? bt1) (and (node? bt2)
+ (tree=? (node-left bt1) (node-left bt2))
+ (tree=? (node-right bt1) (node-right bt2)))]))
+#|
+Test
+(define five (make-node 'five empty empty))
+(define four (make-node 'four empty empty))
+(define three (make-node 'three empty empty))
+(define two (make-node 'two four five))
+(define one (make-node 'one two three))
+
+(tree=? one one)
+(not (tree=? one two))
+(not (tree=? one three))
+(not (tree=? two four))
+
+|#
+
+;An Slist is either
+;1. empty or
+;2. (cons s sl)
+;where s is a Sexpr and sl is a Slist.
+;
+;An Sexpr is either
+;1. a number
+;2. a boolean
+;3. a symbol
+;4. a Slist.
+;
+;Slist=? Slist Slist -> boolean
+;Given Slist1 and Slist2, determines if the two Slists are identical.
+
+(define (Slist=? Slist1 Slist2)
+ (cond
+ [(empty? Slist1) (empty? Slist2)]
+ [(cons? Slist1) (and (cons? Slist2)
+ (Sexpr=? (first Slist1) (first Slist2))
+ (Slist=? (rest Slist1) (rest Slist2)))]))
+
+;Sexpr=? Sexpr Sexpr -> boolean
+;Given Sexpr1 and Sexpr2, determines if the two Sexprs are identical.
+
+(define (Sexpr=? Sexpr1 Sexpr2)
+ (cond
+ [(number? Sexpr1) (and (number? Sexpr2)
+ (= Sexpr1 Sexpr2))]
+ [(boolean? Sexpr1) (and (boolean? Sexpr2)
+ (boolean=? Sexpr1 Sexpr2))]
+ [(symbol? Sexpr1) (and (symbol? Sexpr2)
+ (symbol=? Sexpr1 Sexpr2))]
+ [(cons? Sexpr1) (and (cons? Sexpr2)
+ (Slist=? Sexpr1 Sexpr2))]))
+
+;An Slist is either
+;1. empty or
+;2. (cons s sl)
+;where s is a Sexpr and sl is a Slist.
+;
+;An Sexpr is either
+;1. a number
+;2. a boolean
+;3. a symbol
+;4. a Slist.
+
+;(define Sexpr6 true)
+;(define Sexpr5 15)
+;(define Slist4 (cons Sexpr5 empty))
+;(define Sexpr2 Slist4)
+;(define Slist3 (cons Sexpr6 empty))
+;(define Slist2 (cons Sexpr2 Slist3))
+;(define Sexpr1 'FirstExpr)
+;(define Slist1 (cons Sexpr1 Slist2))
+;
+;(Slist=? empty empty)
+;(not (Slist=? empty (cons 15 empty)))
+;(not (Slist=? (cons 15 empty) empty))
+;(not (Slist=? (cons true empty) (cons false empty)))
+;(Slist=? Slist1 Slist1)
+;(not (Slist=? Slist2 Slist1))
+;(not (Slist=? Slist4 Slist2))
+
+;A list-of-data (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a Scheme datum and lod is a list-of-data.
+;
+;replace-eol-with : list-of-data list-of-data -> list-of-data
+;Given lod1 and lod2, append lod2 to the end of lod1.
+
+(define (replace-eol-with lod1 lod2)
+ (cond
+ [(empty? lod1) lod2]
+ [(cons? lod1) (cons (first lod1) (replace-eol-with (rest lod1) lod2))]))
+
+;test-replace-eol-with : list-of-data list-of-data list-of-data -> boolean
+;Given lod1, lod2, and expected-result, append lod2 to the end of lod1 and see if it matches the expected result.
+
+(define (test-replace-eol-with lod1 lod2 expected-result)
+ (equal? (replace-eol-with lod1 lod2) expected-result))
+
+;(test-replace-eol-with '(Hi My Name Is Joe) '(Nice To Meet You Joe) '(Hi My Name Is Joe Nice To Meet You Joe))
+;(not (test-replace-eol-with '(Hi My Name Is Joe) '(Nice To Meet You Joe) '(Hi My Name Is Joe Nice To Meet You Joey)))
+
+;list-pick : list-of-symbols N[>=1] -> symbol
+;Given a-los and n, find the nth symbol in a-los. The first symbol in a-los has an index of 1.
+
+(define (list-pick a-los n)
+ (cond
+ [(and (= n 1)
+ (empty? a-los)) (error 'list-pick "list too short")]
+ [(and (= n 1)
+ (cons? a-los)) (first a-los)]
+ [(and (> n 1)
+ (empty? a-los)) (error 'list-pick "list too short")]
+ [(and (> n 1)
+ (cons? a-los)) (list-pick (rest a-los) (sub1 n))]))
+
+(define los '(Fred Ted Bill Bob Joe))
+
+;test-list-pick : list-of-symbols N[>=1] symbol -> boolean
+
+;Given a-los, n, and expected-result, pick the n-th symbol from a-los using list-pick and see if it matches our expected-result.
+
+(define (test-list-pick a-los n expected-result)
+ (equal? expected-result (list-pick a-los n)))
+
+;(test-list-pick los 3 'Bill)
+;(not (test-list-pick los 4 'Bill))
+
+test-evaluate
\ No newline at end of file
blob - /dev/null
blob + f261d9de236b70d6b202e6cc9f41e1d4b920faaa (mode 644)
--- /dev/null
+++ 17.8.12.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.8.12) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A list-of-numbers is either
+;1. empty or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;list=?-1 and list=?-2 : list-of-numbers list-of-numbers -> boolean
+;Given lon1 and lon2, return true if the two lists are equal, false otherwise.
+
+;(define (list=?-1 lon1 lon2)
+; (cond
+; [(and (empty? lon1)
+; (empty? lon2)) true]
+; [(and (cons? lon1)
+; (empty? lon2)) false]
+; [(and (empty? lon1)
+; (cons? lon2)) false]
+; [(and (cons? lon1)
+; (cons? lon2)) (and (= (first lon1) (first lon2))
+; (list=?-1 (rest lon1) (rest lon2)))]))
+
+(define (list=?-1 lon1 lon2)
+ (cond
+ [(and (empty? lon1)
+ (empty? lon2)) true]
+ [(and (cons? lon1)
+ (cons? lon2)) (and (= (first lon1) (first lon2))
+ (list=?-1 (rest lon1) (rest lon2)))]
+ [else false]))
+
+
+(define (list=?-2 lon1 lon2)
+ (cond
+ [(empty? lon1) (empty? lon2)]
+ [(cons? lon1) (and (cons? lon2)
+ (= (first lon1) (first lon2))
+ (list=?-2 (rest lon1) (rest lon2)))]))
+
+;Test
+;(list=?-2 empty empty)
+;(list=?-2 empty '(1))
+;(list=?-2 '(1) empty)
+;(list=?-2 '(1) '(1))
+;(list=?-2 '(1) '(1 2))
+
+;A list-of-symbols is either
+;1. empty or
+;2. (cons s los)
+;where s is a symbol and los is a list-of-symbols.
+;
+;sym-list=? : list-of-symbols list-of-symbols -> boolean
+(define (sym-list=? los1 los2)
+ (cond
+ [(and (empty? los1)
+ (empty? los2)) true]
+ [(and (cons? los1)
+ (cons? los2)) (and (symbol=? (first los1) (first los2))
+ (sym-list=? (rest los1) (rest los2)))]
+ [else false]))
+
+;sort-lon : list-of-numbers -> list-of-numbers
+;Given a-lon, sort lon.
+
+(define (sort-lon a-lon)
+ (cond
+ [(empty? a-lon) empty]
+ [(cons? a-lon) (insert-number (first a-lon) (sort-lon (rest a-lon)))]))
+
+;insert-number : number list-of-numbers -> list-of-numbers
+;Given a-number and a-lon (sorted in ascending order), insert a-number in the proper position in lon to return the resulting sorted list-of-numbers.
+
+(define (insert-number a-number a-lon)
+ (cond
+ [(empty? a-lon) (list a-number)]
+ [(< a-number (first a-lon)) (append (list a-number)
+ a-lon)]
+ [else (append (list (first a-lon))
+ (insert-number a-number (rest a-lon)))]))
+
+;contains-same-numbers : list-of-numbers list-of-numbers -> boolean
+;Given lon1 and lon2, return true if the two lists have the same numbers, regardless of order.
+
+(define (contains-same-numbers lon1 lon2)
+ (list=?-1 (sort-lon lon1) (sort-lon lon2)))
+
+;Data Definition
+;
+;An atom is either
+;1. a number,
+;2. a symbol, or
+;3. a boolean.
+;
+;A list-of-atoms is either
+;1. empty or
+;2. (cons a loa)
+;where a is an atom and loa is a list-of-atoms.
+;
+;list-equal? : list-of-atoms list-of-atoms -> boolean
+;Given loa1 and loa2, determine if the two lists are equal (corresponding elements within the list have equivalent atoms).
+
+(define (list-equal? loa1 loa2)
+ (cond
+ [(and (empty? loa1)
+ (empty? loa2)) true]
+ [(and (cons? loa1)
+ (empty? loa2)) false]
+ [(and (empty? loa1)
+ (cons? loa2)) false]
+ [(and (cons? loa1)
+ (cons? loa2)) (and (atoms-equal? (first loa1) (first loa2))
+ (list-equal? (rest loa1) (rest loa2)))]))
+
+;atoms-equal? : atom atom -> boolean
+;Given atom1 and atom2, determine if the two atoms are equal.
+
+(define (atoms-equal? atom1 atom2)
+ (cond
+ [(and (number? atom1)
+ (number? atom2)) (= atom1 atom2)]
+ [(and (boolean? atom1)
+ (boolean? atom2)) (boolean=? atom1 atom2)]
+ [(and (symbol? atom1)
+ (symbol? atom2)) (symbol=? atom1 atom2)]
+ [else false]))
+
+;(define atomic1 (list 5 'hi 'joe true false))
+;(define atomic2 (list 5 'hi 'joe true false))
+
+;A web-page (wp) is either
+;1. empty,
+;2. (cons s wp), or
+;3. (cons ewp wp)
+;where s is a symbol, wp is a web-page (wp), and ewp is a web-page (wp).
+
+;wp=? : wp wp -> boolean
+;Given wp1 and wp2, determine if the two web-pages are identical.
+
+(define (wp=? wp1 wp2)
+ (cond
+ [(empty? wp1) (empty? wp2)]
+ [(symbol? (first wp1)) (and (cons? wp2) (symbol? (first wp2))
+ (symbol=? (first wp1) (first wp2))
+ (wp=? (rest wp1) (rest wp2)))]
+ [(list? (first wp1)) (and (cons? wp2) (list? (first wp2))
+ (wp=? (first wp1) (first wp2))
+ (wp=? (rest wp1) (rest wp2)))]))
+
+;(define empwp empty)
+;(define swpwp (cons 'firstPage (cons 'secondPage empty)))
+;(define ewpwp (cons (cons 'firstPage empty) (cons 'secondPage empty)))
+;
+;(wp=? empwp empwp)
+;(not (wp=? swpwp empwp))
+;(not (wp=? ewpwp empwp))
+;(not (wp=? empwp swpwp))
+;(wp=? swpwp swpwp)
+;(not (wp=? ewpwp swpwp))
+;(not (wp=? empwp ewpwp))
+;(not (wp=? swpwp ewpwp))
+;(wp=? ewpwp ewpwp)
+
+;posn=? : posn posn -> boolean
+;Given posn1 and posn2, determine if they are equal.
+
+(define (posn=? posn1 posn2)
+ (and (posn? posn1) (posn? posn2)
+ (= (posn-x posn1) (posn-x posn2))
+ (= (posn-y posn1) (posn-y posn2))))
+
+(define-struct node (name left right))
+
+;A binary tree (BT) either
+;1. empty or
+;2. (make-node name left right)
+;(make-node name left right)
+;where name is a symbol and left, right are binary trees (BT).
+
+;tree=? : BT BT -> boolean
+(define (tree=? bt1 bt2)
+ (cond
+ [(empty? bt1) (empty? bt2)]
+ [(node? bt1) (and (node? bt2)
+ (tree=? (node-left bt1) (node-left bt2))
+ (tree=? (node-right bt1) (node-right bt2)))]))
+#|
+Test
+(define five (make-node 'five empty empty))
+(define four (make-node 'four empty empty))
+(define three (make-node 'three empty empty))
+(define two (make-node 'two four five))
+(define one (make-node 'one two three))
+
+(tree=? one one)
+(not (tree=? one two))
+(not (tree=? one three))
+(not (tree=? two four))
+
+|#
+
+;An Slist is either
+;1. empty or
+;2. (cons s sl)
+;where s is a Sexpr and sl is a Slist.
+;
+;An Sexpr is either
+;1. a number
+;2. a boolean
+;3. a symbol
+;4. a Slist.
+;
+;Slist=? Slist Slist -> boolean
+;Given Slist1 and Slist2, determines if the two Slists are identical.
+
+(define (Slist=? Slist1 Slist2)
+ (cond
+ [(empty? Slist1) (empty? Slist2)]
+ [(cons? Slist1) (and (cons? Slist2)
+ (Sexpr=? (first Slist1) (first Slist2))
+ (Slist=? (rest Slist1) (rest Slist2)))]))
+
+;Sexpr=? Sexpr Sexpr -> boolean
+;Given Sexpr1 and Sexpr2, determines if the two Sexprs are identical.
+
+(define (Sexpr=? Sexpr1 Sexpr2)
+ (cond
+ [(number? Sexpr1) (and (number? Sexpr2)
+ (= Sexpr1 Sexpr2))]
+ [(boolean? Sexpr1) (and (boolean? Sexpr2)
+ (boolean=? Sexpr1 Sexpr2))]
+ [(symbol? Sexpr1) (and (symbol? Sexpr2)
+ (symbol=? Sexpr1 Sexpr2))]
+ [(cons? Sexpr1) (and (cons? Sexpr2)
+ (Slist=? Sexpr1 Sexpr2))]))
+
+;An Slist is either
+;1. empty or
+;2. (cons s sl)
+;where s is a Sexpr and sl is a Slist.
+;
+;An Sexpr is either
+;1. a number
+;2. a boolean
+;3. a symbol
+;4. a Slist.
+
+;(define Sexpr6 true)
+;(define Sexpr5 15)
+;(define Slist4 (cons Sexpr5 empty))
+;(define Sexpr2 Slist4)
+;(define Slist3 (cons Sexpr6 empty))
+;(define Slist2 (cons Sexpr2 Slist3))
+;(define Sexpr1 'FirstExpr)
+;(define Slist1 (cons Sexpr1 Slist2))
+;
+;(Slist=? empty empty)
+;(not (Slist=? empty (cons 15 empty)))
+;(not (Slist=? (cons 15 empty) empty))
+;(not (Slist=? (cons true empty) (cons false empty)))
+;(Slist=? Slist1 Slist1)
+;(not (Slist=? Slist2 Slist1))
+;(not (Slist=? Slist4 Slist2))
+
+;A list-of-data (lod) is either
+;1. empty or
+;2. (cons d lod) where d is a Scheme datum and lod is a list-of-data.
+;
+;replace-eol-with : list-of-data list-of-data -> list-of-data
+;Given lod1 and lod2, append lod2 to the end of lod1.
+
+(define (replace-eol-with lod1 lod2)
+ (cond
+ [(empty? lod1) lod2]
+ [(cons? lod1) (cons (first lod1) (replace-eol-with (rest lod1) lod2))]))
+
+;test-replace-eol-with : list-of-data list-of-data list-of-data -> boolean
+;Given lod1, lod2, and expected-result, append lod2 to the end of lod1 and see if it matches the expected result.
+
+(define (test-replace-eol-with lod1 lod2 expected-result)
+ (equal? (replace-eol-with lod1 lod2) expected-result))
+
+;(test-replace-eol-with '(Hi My Name Is Joe) '(Nice To Meet You Joe) '(Hi My Name Is Joe Nice To Meet You Joe))
+;(not (test-replace-eol-with '(Hi My Name Is Joe) '(Nice To Meet You Joe) '(Hi My Name Is Joe Nice To Meet You Joey)))
+
+;list-pick : list-of-symbols N[>=1] -> symbol
+;Given a-los and n, find the nth symbol in a-los. The first symbol in a-los has an index of 1.
+
+(define (list-pick a-los n)
+ (cond
+ [(and (= n 1)
+ (empty? a-los)) (error 'list-pick "list too short")]
+ [(and (= n 1)
+ (cons? a-los)) (first a-los)]
+ [(and (> n 1)
+ (empty? a-los)) (error 'list-pick "list too short")]
+ [(and (> n 1)
+ (cons? a-los)) (list-pick (rest a-los) (sub1 n))]))
+
+(define los '(Fred Ted Bill Bob Joe))
+
+;test-list-pick : list-of-symbols N[>=1] symbol -> boolean
+
+;Given a-los, n, and expected-result, pick the n-th symbol from a-los using list-pick and see if it matches our expected-result.
+
+(define (test-list-pick a-los n expected-result)
+ (equal? expected-result (list-pick a-los n)))
+
+;(test-list-pick los 3 'Bill)
+;(not (test-list-pick los 4 'Bill))
+
+test-evaluate
+
+;A SchemeData (a representation of a Scheme expression) is either
+;1. a number,
+;2. a symbol,
+;3. an operator structure, or
+;4. a function.
+
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+
+;An operator is a structure
+;(make-operator left right)
+;where operator is replaced by one of the four operators:
+;1. add (addition)
+;2. sub (subtraction)
+;3. mul (multiplication)
+;4. div (division)
+;and left and right are SchemeData.
+;
+;An operator structure
+;(make-operator left right)
+;represents the expression
+;(operator left right)
+;in Scheme.
+
+(define-struct function (name arg))
+
+;A function is a structure
+;(make-function name arg)
+;where name is a symbol and arg is a SchemeData.
+;
+;A function structure
+;(make-function name arg)
+;represents the expression
+;(name arg)
\ No newline at end of file
blob - /dev/null
blob + e2776f9c7b535904dd20c446507f424f1f63929c (mode 644)
--- /dev/null
+++ 17.8.12.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.8.12) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;A SchemeData (a representation of a Scheme expression) is either
+;1. a number,
+;2. a symbol,
+;3. an operator structure, or
+;4. a function.
+
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+
+;An operator is a structure
+;(make-operator left right)
+;where operator is replaced by one of the four operators:
+;1. add (addition)
+;2. sub (subtraction)
+;3. mul (multiplication)
+;4. div (division)
+;and left and right are SchemeData.
+;
+;An operator structure
+;(make-operator left right)
+;represents the expression
+;(operator left right)
+;in Scheme.
+
+(define-struct function (name arg))
+
+;A function is a structure
+;(make-function name arg)
+;where name is a symbol and arg is a SchemeData.
+;
+;A function structure
+;(make-function name arg)
+;represents the expression
+;(name arg)
+
+(define-struct definition (function parameter body))
+
+;A definition is a structure
+;(make-definition function parameter body)
+;where function and parameter are symbols and body is a SchemeData.
+;numeric? : SchemeData -> boolean
+;Given a-data, determine if the expression it
+;represents is numeric. That is,
+;numeric? evaluates true if the SchemeData lacks symbols,
+;which represents an expression which
+;lacks variables.
+
+(define (numeric? a-data)
+ (cond
+ [(number? a-data) true]
+ [(add? a-data) (and (numeric? (add-left a-data))
+ (numeric?(add-right a-data)))]
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+ (numeric? (sub-right a-data)))]
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+ (numeric? (mul-right a-data)))]
+ [(div? a-data) (and (numeric? (div-left a-data))
+ (numeric? (div-right a-data)))]
+ [else false]))
+
+;evaluate-expression : SchemeData -> number
+;Given a-data, evaluates the numeric expression it represents
+;and returns the value.
+
+(define (evaluate-expression a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+ (evaluate-expression (add-right a-data)))]
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+ (evaluate-expression (sub-right a-data)))]
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+ (evaluate-expression (mul-right a-data)))]
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+ (evaluate-expression (div-right a-data)))]))
+
+;subst : symbol number SchemeData -> SchemeData
+;Given the representation of a variable V (symbol),
+;the number N, and a SchemeData which represents an expression,
+;produce a new SchemeData representing an expression
+;where all occurrences of the variable V (symbol)
+;have been replaced with the number N.
+
+(define (subst V N a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(symbol? a-data) (cond
+ [(symbol=? a-data V) N]
+ [else a-data])]
+ [(add? a-data) (make-add (subst V N (add-left a-data))
+ (subst V N (add-right a-data)))]
+ [(sub? a-data) (make-sub (subst V N (sub-left a-data))
+ (subst V N (sub-right a-data)))]
+ [(mul? a-data) (make-mul (subst V N (mul-left a-data))
+ (subst V N (mul-right a-data)))]
+ [(div? a-data) (make-div (subst V N (div-left a-data))
+ (subst V N (div-right a-data)))]
+ [else a-data]))
+
+;evaluate-with-one-def : SchemeData definition -> number
+;Given an-exp and P, evaluate the argument an-exp, substitute that for the parameter in P, and then evaluate the body of P.
+
+(define (evaluate-with-one-def an-exp P)
+ (cond
+ [(and (definition? P)
+ (numeric? an-exp)) (evaluate-expression (subst (definition-parameter P)
+ (evaluate-expression an-exp)
+ (definition-body P)))]
+ [else (error 'evaluate-with-one-def "unexpected error")]))
+
+;evaluate-with-defs : SchemeData list-of-definitions -> list-of-numbers
+;Given an-exp and defs, evaluate an-exp, substitute this value in the body for each definition in the list-of-definitions in place of each one's parameter and evaluate the resulting body.
+(define (evaluate-with-defs an-exp defs)
+ (cond
+ [(empty? defs) empty]
+ [(cons? defs) (cons (evaluate-with-one-def an-exp (first defs))
+ (evaluate-with-defs an-exp (rest defs)))]))
+
+
+;test-evaluate SchemeData list-of-definitions list-of-numbers -> boolean
+;Given an-exp, defs, and expected-result, evaluate an-exp, substitute it for the parameter for the body of each of the function definitions in defs, evaluate the resulting expressions, and compare that with expected-result. Return true if the two list-of-numbers are identical, false otherwise.
+
+(define (test-evaluate an-exp defs expected-result)
+ (equal? (evaluate-with-defs an-exp defs) expected-result))
+
+;mydefine : number -> number
+(define (mydefine x)
+ (* (* (+ 4 x)
+ (/ 3 x))
+ (- x 1)))
+(define (myotherdefine x)
+ (/ (+ (* 5 x)
+ (* x 4))
+ (* (+ 4 x)
+ (+ 3 x))))
+
+(define mydefine! (make-definition 'mydefine
+ 'x
+ (make-mul (make-mul (make-add 4 'x)
+ (make-div 3 'x))
+ (make-sub 'x 1))))
+(define myotherdefine!
+ (make-definition 'myotherdefine!
+ 'x
+ (make-div (make-add (make-mul 5 'x)
+ (make-mul 'x 4))
+ (make-mul (make-add 4 'x)
+ (make-add 3 'x)))))
+(define myexp (+ (* 3 4)
+ (/ 6 3)))
+(define myexp! (make-add (make-mul 3 4)
+ (make-div 6 3)))
+
+(test-evaluate myexp! (list mydefine! myotherdefine!) (list (mydefine myexp) (myotherdefine myexp)))
+
\ No newline at end of file
blob - /dev/null
blob + f3fbc9da55b6e558158765f633dc0a217ba4a2e8 (mode 644)
--- /dev/null
+++ 18.1.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(local (
+ (define x (* y 3))
+ )
+
+ (* x x))
+
+(local (
+
+ (define (odd an)
+ (cond
+ [(zero? an) false]
+ [else (even (sub1 an))]))
+
+
+ (define (even an)
+ (cond
+ [(zero? an) true]
+ [else (odd (sub1 an))])))
+
+
+ (even a-nat-num))
+
+(local (
+
+ (define (f x) (g x (+ x 1)))
+ (define (g x y) (f (+ x y)))
+
+ )
+
+
+ (+ (f 10) (g 10 20))
+
+ )
+
+(local (
+ (define x 10)
+ (y (+ x x)))
+ y)
+
+(local (
+
+ (define (f x) (+ (* x x) (* 3 x) 15))
+ (define x 100)
+ (define f@100 (f x))
+
+ )
+
+
+ f@100 x)
+
+(local (
+ (define (f x) (+ (* x x) (* 3 x) 14))
+ (define x 100)
+ (define f (f x)))
+ f)
+
+1. (define A-CONSTANT
+ (not
+
+
+ (local (
+
+ (define (odd an)
+ (cond
+ [(= an 0) false]
+ [else (even (- an 1))]))
+
+
+ (define (even an)
+ (cond
+ [(= an 0) true]
+ [else (odd (- an 1))]))
+
+ )
+
+
+ (even a-nat-num)
+
+ )
+
+ ))
+2. (+
+
+
+ (local (
+
+
+
+ (define (f x) (+ (* x x) (* 3 x) 15))
+ (define x 100)
+ (define f@100 (f x))
+
+
+
+ )
+ f@100)
+
+
+
+ 1000)
+3. (local (
+
+
+ (define CONST 100)
+ (define f x (+ x CONST))
+
+
+
+ )
+
+
+ (define (g x y z) (f (+ x (* y z))))
+
+
+ )
+
+
+= (define (D x y)
+ (local ((define x2 (* x x))
+ (define y2 (* y y)))
+ (sqrt (+ x2 y2))))
+ (+ (local ((define x2 (* 0 0))
+ (define y2 (* 1 1)))
+ (sqrt (+ x2 y2)))
+ (D 3 4))
+
+;; sort : list-of-numbers -> list-of-numbers
+(define (sort alon)
+ (local (
+
+ (define (sort alon)
+ (cond
+ [(empty? alon) empty]
+ [(cons? alon) (insert (first alon)
+ (sort (rest alon)))]))
+
+
+ (define (insert an alon)
+ (cond
+ [(empty? alon) (list an)]
+ [else (cond
+ [(> an (first alon)) (cons an alon)]
+ [else (cons (first alon)
+ (insert an (rest alon)))])]))
+
+ )
+ (sort alon)))
\ No newline at end of file
blob - /dev/null
blob + c109f1e105adfff289e315cc231dbceb83a27ce8 (mode 644)
--- /dev/null
+++ 18.1.10.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.10) (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")))))
+;A parent structure is
+;(make-parent children name date eyes)
+;where name and eyes are symbols,
+;date is a number, and children is a
+;list-of-children.
+
+(define-struct parent (children name date eyes))
+;
+;A list-of-children is either
+;1. an empty list or
+;2. (cons p loc) where p is a parent
+;and loc is a list-of-children.
+
+;
+;fun-for-parent: parent -> ???
+;Template
+;(define (fun-for-parent a-parent)
+; ... (parent-children a-parent) ...
+; ... (parent-name a-parent) ...
+; ... (parent-date a-parent) ...
+; ... (parent-eyes a-parent) ...)
+
+;
+;fun-for-loc : list-of-children -> ???
+;(define (fun-for-loc a-loc)
+; (cond
+; [(empty? a-loc) ...]
+; [else ... (first a-loc) ...
+; ... (fun-for-loc (rest a-loc)) ...]))
+
+;blue-eyed-descendant? : parent -> boolean
+;Given a-parent, determines whether the parent
+;or any of its descendants have blue eyes.
+
+
+(define (blue-eyed-descendant? a-parent)
+ (cond
+ [(symbol=? (parent-eyes a-parent) 'blue) true]
+ [else (blue-eyed-children? (parent-children a-parent))]))
+;
+;blue-eyed-children? : list-of-children -> boolean
+;Given a-loc (list-of-children), return true if
+;any parent structure within the list-of-children have blue eyes
+;or if any of their descendants have blue eyes.
+
+(define (blue-eyed-children? a-loc)
+ (cond
+ [(empty? a-loc) false]
+ [else (or (blue-eyed-descendant? (first a-loc))
+ (blue-eyed-children? (rest a-loc)))]))
+
+;Third Generation
+(define Gustav (make-parent empty 'Gustav 1988 'brown))
+
+;Second Generation
+(define Fred (make-parent (list Gustav) 'Fred 1966 'pink))
+(define Eva (make-parent (list Gustav) 'Eva 1965 'blue))
+(define Dave (make-parent empty 'Dave 1955 'black))
+(define Adam (make-parent empty 'Adam 1950 'yellow))
+
+;First Generation
+(define Bettina (make-parent (list Adam Dave Eva) 'Bettina 1926 'green))
+(define Carl (make-parent (list Adam Dave Eva) 'Carl 1926 'green))
+
+;Test - All should return true
+;(blue-eyed-descendant? Bettina)
+;(blue-eyed-descendant? Eva)
+;(not (blue-eyed-descendant? Gustav))
+;(not (blue-eyed-descendant? Adam))
+;
+;how-far-removed : parent -> number/false
+;Determine how many generations removed
+;a parent is from a blue-eyed child. If
+;the parent himself has blue eyes, return 0.
+;If there is no blue-eyed child within
+;the parent's descendants, return false.
+
+(define (how-far-removed a-parent)
+ (cond
+ [(symbol=? (parent-eyes a-parent) 'blue) 0]
+ [else
+ (cond
+ [(false? (how-far-removed-children (parent-children a-parent))) false]
+ [else (+ 1
+ (how-far-removed-children (parent-children a-parent)))])]))
+
+;how-far-removed-children : list-of-children -> number/false
+;Given a-loc, determine how many generations removed
+;the children are from blue-eyed descendants. Return
+;false if there are no descendants with blue eyes, and
+;0 if one of the parent structures in a-loc has blue eyes.
+;If multiple descendants have blue-eyes, return the lowest number.
+
+(define (how-far-removed-children a-loc)
+ (cond
+ [(empty? a-loc) false]
+ [else
+ (cond
+ [(and (false? (how-far-removed (first a-loc)))
+ (false? (how-far-removed-children (rest a-loc)))) false]
+ [(false? (how-far-removed (first a-loc))) (how-far-removed-children (rest a-loc))]
+ [(false? (how-far-removed-children (rest a-loc))) (how-far-removed (first a-loc))]
+ [else (min (how-far-removed (first a-loc))
+ (how-far-removed-children (rest a-loc)))])]))
+;
+;count-descendants : parent -> number
+;Given a-parent, compute the number of descendants.
+;The parent himself is included,
+;so only nonzero natural numbers should be returned.
+;
+(define (count-descendants a-parent)
+ (+ 1
+ (count-descendants-children (parent-children a-parent))))
+
+;count-descendants-children : list-of-children -> number
+;Given a-loc, determine the number of descendants
+;of the children. The children are themselves included.
+
+(define (count-descendants-children a-loc)
+ (cond
+ [(empty? a-loc) 0]
+ [else (+ (count-descendants (first a-loc))
+ (count-descendants-children (rest a-loc)))]))
+
+;count-proper-descendants : parent -> number
+;Given a-parent, determine the number
+;of proper descendants. The parent himself
+;is not included.
+
+(define (count-proper-descendants a-parent)
+ (- (count-descendants a-parent)
+ 1))
+;
+;A list of symbols is either
+;1. an empty list or
+;2. (cons s los) where s is a symbol and los is a list-of-symbols.
+
+;eye-colors : parent -> list-of-symbols
+;Given a-parent, finds the eye colors of all
+;the descendants and returns them as a
+;list-of-symbols.
+
+(define (eye-colors a-parent)
+ (append (list (parent-eyes a-parent))
+ (eye-colors-children (parent-children a-parent))))
+
+;eye-colors-children : list-of-children -> list-of-symbols
+;Given a-loc, determine the eye colors
+;of the list-of-children and their descendants and return
+;them as a list-of-symbols.
+
+(define (eye-colors-children a-loc)
+ (cond
+ [(empty? a-loc) empty]
+ [else (append (eye-colors (first a-loc))
+ (eye-colors-children (rest a-loc)))]))
blob - /dev/null
blob + e2bcbd42c7065ac56f657c4c59baf56d5c502782 (mode 644)
--- /dev/null
+++ 18.1.10.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.10) (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")))))
+;A parent structure is
+;(make-parent children name date eyes)
+;where name and eyes are symbols,
+;date is a number, and children is a
+;list-of-children.
+
+(define-struct parent (children name date eyes))
+;
+;A list-of-children is either
+;1. an empty list or
+;2. (cons p loc) where p is a parent
+;and loc is a list-of-children.
+
+;fun-for-parent: parent -> ???
+;Template
+;(define (fun-for-parent a-parent)
+; ... (parent-children a-parent) ...
+; ... (parent-name a-parent) ...
+; ... (parent-date a-parent) ...
+; ... (parent-eyes a-parent) ...)
+
+;
+;fun-for-loc : list-of-children -> ???
+;(define (fun-for-loc a-loc)
+; (cond
+; [(empty? a-loc) ...]
+; [else ... (first a-loc) ...
+; ... (fun-for-loc (rest a-loc)) ...]))
+
+
+;Third Generation
+(define Gustav (make-parent empty 'Gustav 1988 'brown))
+
+;Second Generation
+(define Fred (make-parent (list Gustav) 'Fred 1966 'pink))
+(define Eva (make-parent (list Gustav) 'Eva 1965 'blue))
+(define Dave (make-parent empty 'Dave 1955 'black))
+(define Adam (make-parent empty 'Adam 1950 'yellow))
+
+;First Generation
+(define Bettina (make-parent (list Adam Dave Eva) 'Bettina 1926 'green))
+(define Carl (make-parent (list Adam Dave Eva) 'Carl 1926 'green))
+
+;Test - All should return true
+;(blue-eyed-descendant? Bettina)
+;(blue-eyed-descendant? Eva)
+;(not (blue-eyed-descendant? Gustav))
+;(not (blue-eyed-descendant? Adam))
+
+;blue-eyed-descendant? : parent -> boolean
+;Given a-parent, determines whether the parent
+;or any of its descendants have blue eyes.
+
+;blue-eyed-children? : list-of-children -> boolean
+;Given a-loc (list-of-children), return true if
+;any parent structure within the list-of-children have blue eyes
+;or if any of their descendants have blue eyes.
+
+(define (blue-eyed-descendant a-parent)
+ (local ((define (blue-eyed-descendant? a-parent)
+ (cond
+ [(symbol=? (parent-eyes a-parent) 'blue) true]
+ [else (blue-eyed-children? (parent-children a-parent))]))
+
+ (define (blue-eyed-children? a-loc)
+ (cond
+ [(empty? a-loc) false]
+ [else (or (blue-eyed-descendant? (first a-loc))
+ (blue-eyed-children? (rest a-loc)))])))
+ (blue-eyed-descendant a-parent)))
\ No newline at end of file
blob - /dev/null
blob + dc17a3f6bf51c453eacafa75099691797bb9a1c7 (mode 644)
--- /dev/null
+++ 18.1.11-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.11-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct star (name instrument))
+
+;A star is a structure
+;(make-star name instrument)
+;where both name and instrument are symbols.
+
+(define alos
+ (list (make-star 'Chris 'saxophone)
+ (make-star 'Robby 'trumpet)
+ (make-star 'Matt 'violin)
+ (make-star 'Wen 'guitar)
+ (make-star 'Matt 'radio)))
+
+;A list-of-stars is either
+;1. empty or
+;2. (cons s los)
+;where s is a star structure and los is a list-of-stars.
+;
+;last-occurrence : symbol list-of-star -> star/false
+;Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure. Return false if there is no star with a-name.
+
+(define (last-occurrence a-name a-los)
+ (cond
+ [(empty? a-los) false]
+ [else (local ((define r (last-occurrence a-name (rest a-los))))
+ (cond
+ [(star? r) r]
+ [(symbol=? a-name (star-name (first a-los))) (first a-los)]
+ [else false]))]))
+
+(last-occurrence 'Matt
+ (list (make-star 'Matt 'violin)
+ (make-star 'Matt 'radio)))
+
+(cond
+ [false false]
+ [else (local ((define r (last-occurrence 'Matt (list (make-star 'Matt 'radio)))))
+ (cond
+ [(star? r) r]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'violin))) (make-star 'Matt 'violin)]
+ [else false]))])
+
+(define r-1 (last-occurrence 'Matt (list (make-star 'Matt 'radio))))
+
+(cond
+ [false false]
+ [else (cond
+ [(star? r-1) r-1]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'violin))) (make-star 'Matt 'violin)]
+ [else false])])
+#|
+Now, we know that r-1 is
+(last-occurrence 'Matt (list (make-star 'Matt 'radio)))
+
+(last-occurrence 'Matt (list (make-star 'Matt 'radio)))
+
+(cond
+ [false false]
+ [else (local ((define r-2 (last-occurrence 'Matt empty)))
+ (cond
+ [(star? r-2) r-2]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'radio))) (make-star 'Matt 'radio)]
+ [else false]))])
+
+(define r-2 (last-occurrence 'Matt empty))
+
+(cond
+ [false false]
+ [else (cond
+ [(star? r-2) r-2]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'radio))) (make-star 'Matt 'radio)]
+ [else false])])
+
+Now, we know that r-2 is
+(last-occurrence 'Matt empty)
+which is false, so r-2 is
+false
+
+(cond
+ [false false]
+ [else (cond
+ [false r-2]
+ [(symbol=? 'Matt 'Matt) (make-star 'Matt 'radio)]
+ [else false])])
+
+(cond
+ [false false]
+ [else (cond
+ [false r-2]
+ [true (make-star 'Matt 'radio)]
+ [else false])])
+
+Hence, r-1 is
+(make-star 'Matt 'radio)
+|#
+
+(define r-1 (make-star 'Matt 'radio))
+
+(cond
+ [false false]
+ [else (cond
+ [true (make-star 'Matt 'radio)]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'violin))) (make-star 'Matt 'violin)]
+ [else false])])
+
+(make-star 'Matt 'radio)
blob - /dev/null
blob + 1817cddd0bf418e3138d4491066ea676832db2c1 (mode 644)
--- /dev/null
+++ 18.1.11-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.11-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct star (name instrument))
+
+;A star is a structure
+;(make-star name instrument)
+;where both name and instrument are symbols.
+
+(define alos
+ (list (make-star 'Chris 'saxophone)
+ (make-star 'Robby 'trumpet)
+ (make-star 'Matt 'violin)
+ (make-star 'Wen 'guitar)
+ (make-star 'Matt 'radio)))
+
+;A list-of-stars is either
+;1. empty or
+;2. (cons s los)
+;where s is a star structure and los is a list-of-stars.
+;
+;last-occurrence : symbol list-of-star -> star/false
+;Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure. Return false if there is no star with a-name.
+
+(define (last-occurrence a-name a-los)
+ (cond
+ [(empty? a-los) false]
+ [else (local ((define r (last-occurrence a-name (rest a-los))))
+ (cond
+ [(star? r) r]
+ [(symbol=? a-name (star-name (first a-los))) (first a-los)]
+ [else false]))]))
+
+(last-occurrence 'Matt
+ (list (make-star 'Matt 'violin)
+ (make-star 'Matt 'radio)))
+
+;; maxi : non-empty-lon -> number
+;; to determine the largest number on alon
+(define (maxi alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(> (first alon) (maxi (rest alon))) (first alon)]
+ [else (maxi (rest alon))])]))
+
+(list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
\ No newline at end of file
blob - /dev/null
blob + 364f90efe7d6a43cf05a5deb2ecd9ac69de7d0f8 (mode 644)
--- /dev/null
+++ 18.1.11.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.11) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct star (name instrument))
+
+A star is a structure
+(make-star name instrument)
+where both name and instrument are symbols.
+
+(define alos
+ (list (make-star 'Chris 'saxophone)
+ (make-star 'Robby 'trumpet)
+ (make-star 'Matt 'violin)
+ (make-star 'Wen 'guitar)
+ (make-star 'Matt 'radio)))
+
+last-occurrence : symbol list-of-star -> star
+Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure.
+
+(define (last-occurrence a-name a-los)
+ (cond
+ []
+ []))
\ No newline at end of file
blob - /dev/null
blob + 50bb90da31ada504a95f6f9da9dd79a2185b1b72 (mode 644)
--- /dev/null
+++ 18.1.11.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.11) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct star (name instrument))
+
+;A star is a structure
+;(make-star name instrument)
+;where both name and instrument are symbols.
+
+(define alos
+ (list (make-star 'Chris 'saxophone)
+ (make-star 'Robby 'trumpet)
+ (make-star 'Matt 'violin)
+ (make-star 'Wen 'guitar)
+ (make-star 'Matt 'radio)))
+
+;A list-of-stars is either
+;1. empty or
+;2. (cons s los)
+;where s is a star structure and los is a list-of-stars.
+;
+;last-occurrence : symbol list-of-star -> star/false
+;Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure. Return false if there is no star with a-name.
+
+(define (last-occurrence a-name a-los)
+ (cond
+ [(empty? a-los) false]
+ [else (local ((define r (last-occurrence a-name (rest a-los))))
+ (cond
+ [(star? r) r]
+ [(symbol=? a-name (star-name (first a-los))) (first a-los)]
+ [else false]))]))
+
+(last-occurrence 'Matt
+ (list (make-star 'Matt 'violin)
+ (make-star 'Matt 'radio)))
+
+(cond
+ [false false]
+ [else (local ((define r (last-occurrence 'Matt (list (make-star 'Matt 'radio)))))
+ (cond
+ [(star? r) r]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'violin))) (make-star 'Matt 'violin)]
+ [else false]))])
+
+(define r-1 (last-occurrence 'Matt (list (make-star 'Matt 'radio))))
+
+(cond
+ [false false]
+ [else (cond
+ [(star? r-1) r-1]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'violin))) (make-star 'Matt 'violin)]
+ [else false])])
+#|
+Now, we know that r-1 is
+(last-occurrence 'Matt (list (make-star 'Matt 'radio)))
+
+(last-occurrence 'Matt (list (make-star 'Matt 'radio)))
+
+(cond
+ [false false]
+ [else (local ((define r-2 (last-occurrence 'Matt empty)))
+ (cond
+ [(star? r-2) r-2]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'radio))) (make-star 'Matt 'radio)]
+ [else false]))])
+
+(define r-2 (last-occurrence 'Matt empty))
+
+(cond
+ [false false]
+ [else (cond
+ [(star? r-2) r-2]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'radio))) (make-star 'Matt 'radio)]
+ [else false])])
+
+Now, we know that r-2 is
+(last-occurrence 'Matt empty)
+which is false, so r-2 is
+false
+
+(cond
+ [false false]
+ [else (cond
+ [false r-2]
+ [(symbol=? 'Matt 'Matt) (make-star 'Matt 'radio)]
+ [else false])])
+
+(cond
+ [false false]
+ [else (cond
+ [false r-2]
+ [true (make-star 'Matt 'radio)]
+ [else false])])
+
+Hence, r-1 is
+(make-star 'Matt 'radio)
+|#
+
+(define r-1 (make-star 'Matt 'radio))
+
+(cond
+ [false false]
+ [else (cond
+ [true (make-star 'Matt 'radio)]
+ [(symbol=? 'Matt (star-name (make-star 'Matt 'violin))) (make-star 'Matt 'violin)]
+ [else false])])
+
+(make-star 'Matt 'radio)
blob - /dev/null
blob + 71c694e6960af3454415134cc60821d090f5b5f3 (mode 644)
--- /dev/null
+++ 18.1.12.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.12) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct star (name instrument))
+
+;A star is a structure
+;(make-star name instrument)
+;where both name and instrument are symbols.
+
+(define alos
+ (list (make-star 'Chris 'saxophone)
+ (make-star 'Robby 'trumpet)
+ (make-star 'Matt 'violin)
+ (make-star 'Wen 'guitar)
+ (make-star 'Matt 'radio)))
+
+;A list-of-stars is either
+;1. empty or
+;2. (cons s los)
+;where s is a star structure and los is a list-of-stars.
+;
+;last-occurrence : symbol list-of-star -> star/false
+;Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure. Return false if there is no star with a-name.
+
+(define (last-occurrence a-name a-los)
+ (cond
+ [(empty? a-los) false]
+ [else (local ((define r (last-occurrence a-name (rest a-los))))
+ (cond
+ [(star? r) r]
+ [(symbol=? a-name (star-name (first a-los))) (first a-los)]
+ [else false]))]))
+
+(last-occurrence 'Matt
+ (list (make-star 'Matt 'violin)
+ (make-star 'Matt 'radio)))
+
+;; maxi : non-empty-lon -> number
+;; to determine the largest number on alon
+(define (maxi alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(> (first alon) (maxi (rest alon))) (first alon)]
+ [else (maxi (rest alon))])]))
+
+(list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
\ No newline at end of file
blob - /dev/null
blob + 8aed89025a6a95f5102dc856bd3ac9754921d7ec (mode 644)
--- /dev/null
+++ 18.1.12.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.12) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct star (name instrument))
+
+;A star is a structure
+;(make-star name instrument)
+;where both name and instrument are symbols.
+
+(define alos
+ (list (make-star 'Chris 'saxophone)
+ (make-star 'Robby 'trumpet)
+ (make-star 'Matt 'violin)
+ (make-star 'Wen 'guitar)
+ (make-star 'Matt 'radio)))
+
+;A list-of-stars is either
+;1. empty or
+;2. (cons s los)
+;where s is a star structure and los is a list-of-stars.
+;
+;last-occurrence : symbol list-of-star -> star/false
+;Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure. Return false if there is no star with a-name.
+
+(define (last-occurrence a-name a-los)
+ (cond
+ [(empty? a-los) false]
+ [else (local ((define r (last-occurrence a-name (rest a-los))))
+ (cond
+ [(star? r) r]
+ [(symbol=? a-name (star-name (first a-los))) (first a-los)]
+ [else false]))]))
+
+(last-occurrence 'Matt
+ (list (make-star 'Matt 'violin)
+ (make-star 'Matt 'radio)))
+
+;; maxi : non-empty-lon -> number
+;; to determine the largest number on alon
+(define (maxi alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(> (first alon) (maxi (rest alon))) (first alon)]
+ [else (maxi (rest alon))])]))
+
+(define (maxi2 alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (local ((define r (maxi2 (rest alon))))
+ (cond
+ [(> (first alon) r) (first alon)]
+ [else r]))]))
+
+
+
+(list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
\ No newline at end of file
blob - /dev/null
blob + fad8fd03f3ded7bc23cd9a7ac72646dff405e948 (mode 644)
--- /dev/null
+++ 18.1.13.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.13) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;; maxi : non-empty-lon -> number
+;; to determine the largest number on alon
+(define (maxi alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(> (first alon) (maxi (rest alon))) (first alon)]
+ [else (maxi (rest alon))])]))
+
+(define (maxi2 alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (local ((define r (maxi2 (rest alon))))
+ (cond
+ [(> (first alon) r) (first alon)]
+ [else r]))]))
+
+#|
+(maxi (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35))
+(maxi2 (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35))
+|#
\ No newline at end of file
blob - /dev/null
blob + eb664f4a8e753902373a40d7de76499c4a16fdf2 (mode 644)
--- /dev/null
+++ 18.1.13.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.13) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct child (father mother name date eyes))
+
+#|
+A child is a structure
+(make-child fa mo na da ec)
+where fa, mo are family-tree-nodes, name and eyes are symbol, and date is a number.
+
+A family tree node (ftn) is either
+1. empty or
+2. (make-node fa mo na da ec)
+where fa, mo are family-tree-nodes and na, ec are symbols, and da is a number.
+
+A direction is either
+1. the symbol 'father or
+2. the symbol 'mother.
+
+A path is either
+1. empty or
+2. (cons d p)
+where d is a direction and p is a path.
+
+to-blue-eyed-ancestor : ftn -> path or false
+Return the path to a blue-eyed-ancestor, by searching out the paternal family tree first. (Given two or more blue-eyed-ancestors, the path returned will be the one that follows the paternal path in any given fork). Non-proper ancestors are returned as empty paths (a-ftn itself is counted as an ancestor).
+
+|#
+
+(define (to-blue-eyed-ancestor a-ftn)
+ (cond
+ [(empty? a-ftn) false]
+ [(symbol=? 'blue (child-eyes a-ftn)) empty]
+ [else (local ((define f (to-blue-eyed-ancestor (child-father a-ftn)))
+ (define m (to-blue-eyed-ancestor (child-mother a-ftn))))
+ (cond
+ [(or
+ (cons? f)
+ (empty? f)) (cons 'father f)]
+ [(or
+ (cons? m)
+ (empty? m)) (cons 'mother m)]
+ [else false]))]))
+
+(define Carl (make-child empty empty 'Carl 1926 'green))
+(define Bettina (make-child empty empty 'Bettina 1926 'green))
+(define Adam (make-child Carl Bettina 'Adam 1950 'yellow))
+(define Dave (make-child Carl Bettina 'Dave 1955 'black))
+(define Eva (make-child Carl Bettina 'Eva 1965 'blue))
+(define Fred (make-child empty empty 'Fred 1966 'pink))
+(define Gustav (make-child Fred Eva 'Gustav 1988 'brown))
+
blob - /dev/null
blob + 5d9cb4060fec5e2d5e5f51b4e09575a9a75bc3df (mode 644)
--- /dev/null
+++ 18.1.14-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.14-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+
+;find-for-wp : wp symbol -> list-of-symbols or false. Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to web-pages before embedded web pages.
+
+(define (find-for-wp a-wp a-symbol)
+ (cond
+ [(or (cons? (find-for-doc (wp-doc a-wp) a-symbol))
+ (empty? (find-for-doc (wp-doc a-wp) a-symbol))) (cons (wp-header a-wp) (find-for-doc (wp-doc a-wp) a-symbol))]
+ [else false]))
+
+;find-for-doc : doc symbol -> list-of-symbols or false
+;Given a-doc and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-doc (a-doc inclusive). Returns false if a-symbol never occurs. Return empty if a-doc contains a-symbol. If there are 2 or more occurrences of a-symbol, find-for-doc returns the list-of-headers from only a single occurrence by following the path that gives preference to web-pages before embedded web pages.
+
+(define (find-for-doc a-doc a-symbol)
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else (find-for-doc (rest a-doc) a-symbol)])]
+ [(wp? (first a-doc))
+ (cond
+ [(or (cons? (find-for-wp (rest a-doc) a-symbol))
+ (empty? (find-for-wp (rest a-doc) a-symbol))) (find-for-wp (rest a-doc) a-symbol)]
+ [(or (cons? (find-for-wp (first a-doc) a-symbol))
+ (empty? (find-for-wp (first a-doc) a-symbol))) (find-for-wp (first a-doc) a-symbol)])]))
\ No newline at end of file
blob - /dev/null
blob + 796ffc31f61a7dd177434679e4de52a01d5a3e42 (mode 644)
--- /dev/null
+++ 18.1.14-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.14-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+
+;find-for-wp : wp symbol -> list-of-symbols or false. Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find-for-wp a-wp a-symbol)
+ (cond
+ [(or (cons? (find-for-doc (wp-doc a-wp) a-symbol))
+ (empty? (find-for-doc (wp-doc a-wp) a-symbol))) (cons (wp-header a-wp) (find-for-doc (wp-doc a-wp) a-symbol))]
+ [else false]))
+
+;find-for-doc : doc symbol -> list-of-symbols or false
+;Given a-doc and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-doc (a-doc inclusive). Returns false if a-symbol never occurs. Return empty if a-doc contains a-symbol. If there are 2 or more occurrences of a-symbol, find-for-doc returns the list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find-for-doc a-doc a-symbol)
+ (cond
+ [(empty? a-doc) false]
+ [else (local ((define firs (find-for-wp (first a-doc) a-symbol))
+ (define res (find-for-doc (rest a-doc) a-symbol)))
+ (cond
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else res])]
+ [(or (cons? res)
+ (empty? res)) res]
+ [(or (cons? firs)
+ (empty? firs)) firs]))]))
+
+
+
+(define DOC7 (cons 'ImADoc empty))
+(define DOC6 (cons 'ImADoc empty))
+(define WP3 (make-wp 'ImAPage empty))
+(define DOC5 (cons WP3 DOC6))
+(define WP2 (make-wp 'AmIAPageToo? DOC5))
+(define DOC4 (cons 'MaybeADoc DOC7))
+(define DOC3 (cons WP2 DOC4))
+(define DOC2 (cons 'ADoctor? DOC3))
+(define DOC1 (cons 'OrADocument? DOC2))
+(define WP1 (make-wp 'NoAWebPage DOC1))
+
+(find-for-wp WP1 'ImADoc)
+
+;find : wp symbol -> list-of-symbols or false.
+;Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find a-wp a-symbol)
+ (local
+ ((define (find-for-wp a-wp a-symbol)
+ (local ((define r (find-for-doc (wp-doc a-wp) a-symbol)))
+ (cond
+ [(or (cons? r)
+ (empty? r)) (cons (wp-header a-wp) r)]
+ [else false])))
+
+ (define (find-for-doc a-doc a-symbol)
+ (local ((define firs (find-for-wp (first a-doc) a-symbol))
+ (define res (find-for-doc (rest a-doc) a-symbol)))
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else res])]
+ [(wp? (first a-doc))
+ (cond
+ [(or (cons? res)
+ (empty? res)) res]
+ [(or (cons? firs)
+ (empty? firs)) firs])]))))
+ (find-for-wp a-wp a-symbol)))
\ No newline at end of file
blob - /dev/null
blob + 92250ff1d59170284c883e7a30f3f4822468e67e (mode 644)
--- /dev/null
+++ 18.1.14-3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.14-3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+
+;find-for-wp : wp symbol -> list-of-symbols or false. Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find-for-wp a-wp a-symbol)
+ (cond
+ [(or (cons? (find-for-doc (wp-doc a-wp) a-symbol))
+ (empty? (find-for-doc (wp-doc a-wp) a-symbol))) (cons (wp-header a-wp) (find-for-doc (wp-doc a-wp) a-symbol))]
+ [else false]))
+
+;find-for-doc : doc symbol -> list-of-symbols or false
+;Given a-doc and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-doc (a-doc inclusive). Returns false if a-symbol never occurs. Return empty if a-doc contains a-symbol. If there are 2 or more occurrences of a-symbol, find-for-doc returns the list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find-for-doc a-doc a-symbol)
+ (cond
+ [(empty? a-doc) false]
+ [else (local ((define firs )
+ (define res ))
+ (cond
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else (find-for-doc (rest a-doc) a-symbol)])]
+ [(or (cons? (find-for-doc (rest a-doc) a-symbol))
+ (empty? (find-for-doc (rest a-doc) a-symbol))) (find-for-doc (rest a-doc) a-symbol)]
+ [(or (cons? (find-for-wp (first a-doc) a-symbol))
+ (empty? (find-for-wp (first a-doc) a-symbol))) (find-for-wp (first a-doc) a-symbol)]))]))
+
+
+
+(define DOC7 (cons 'ImADoc empty))
+(define DOC6 (cons 'ImADoc empty))
+(define WP3 (make-wp 'ImAPage empty))
+(define DOC5 (cons WP3 DOC6))
+(define WP2 (make-wp 'AmIAPageToo? DOC5))
+(define DOC4 (cons 'MaybeADoc DOC7))
+(define DOC3 (cons WP2 DOC4))
+(define DOC2 (cons 'ADoctor? DOC3))
+(define DOC1 (cons 'OrADocument? DOC2))
+(define WP1 (make-wp 'NoAWebPage DOC1))
+
+(find-for-wp WP1 'ImADoc)
+
+;find : wp symbol -> list-of-symbols or false.
+;Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find a-wp a-symbol)
+ (local
+ ((define (find-for-wp a-wp a-symbol)
+ (local ((define r (find-for-doc (wp-doc a-wp) a-symbol)))
+ (cond
+ [(or (cons? r)
+ (empty? r)) (cons (wp-header a-wp) r)]
+ [else false])))
+
+ (define (find-for-doc a-doc a-symbol)
+ (local ((define firs (find-for-wp (first a-doc) a-symbol))
+ (define res (find-for-doc (rest a-doc) a-symbol)))
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else res])]
+ [(wp? (first a-doc))
+ (cond
+ [(or (cons? res)
+ (empty? res)) res]
+ [(or (cons? firs)
+ (empty? firs)) firs])]))))
+ (find-for-wp a-wp a-symbol)))
\ No newline at end of file
blob - /dev/null
blob + bde68732d75cb6dc3fa423ec692adfff435ceac8 (mode 644)
--- /dev/null
+++ 18.1.14-3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.14-3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+
+;find-for-wp : wp symbol -> list-of-symbols or false. Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find-for-wp a-wp a-symbol)
+ (cond
+ [(or (cons? (find-for-doc (wp-doc a-wp) a-symbol))
+ (empty? (find-for-doc (wp-doc a-wp) a-symbol))) (cons (wp-header a-wp) (find-for-doc (wp-doc a-wp) a-symbol))]
+ [else false]))
+
+;find-for-doc : doc symbol -> list-of-symbols or false
+;Given a-doc and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-doc (a-doc inclusive). Returns false if a-symbol never occurs. Return empty if a-doc contains a-symbol. If there are 2 or more occurrences of a-symbol, find-for-doc returns the list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find-for-doc a-doc a-symbol)
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else (find-for-doc (rest a-doc) a-symbol)])]
+ [(or (cons? (find-for-doc (rest a-doc) a-symbol))
+ (empty? (find-for-doc (rest a-doc) a-symbol))) (find-for-doc (rest a-doc) a-symbol)]
+ [(or (cons? (find-for-wp (first a-doc) a-symbol))
+ (empty? (find-for-wp (first a-doc) a-symbol))) (find-for-wp (first a-doc) a-symbol)]))
+
+
+
+(define DOC7 (cons 'ImADoc empty))
+(define DOC6 (cons 'ImADoc empty))
+(define WP3 (make-wp 'ImAPage empty))
+(define DOC5 (cons WP3 DOC6))
+(define WP2 (make-wp 'AmIAPageToo? DOC5))
+(define DOC4 (cons 'MaybeADoc DOC7))
+(define DOC3 (cons WP2 DOC4))
+(define DOC2 (cons 'ADoctor? DOC3))
+(define DOC1 (cons 'OrADocument? DOC2))
+(define WP1 (make-wp 'NoAWebPage DOC1))
+
+(time (find-for-wp WP1 'ImADoc))
+
+;find : wp symbol -> list-of-symbols or false.
+;Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to documents before embedded web pages.
+
+(define (find a-wp a-symbol)
+ (local
+ ((define (find-for-wp a-wp a-symbol)
+ (local ((define r (find-for-doc (wp-doc a-wp) a-symbol)))
+ (cond
+ [(or (cons? r)
+ (empty? r)) (cons (wp-header a-wp) r)]
+ [else false])))
+
+ (define (find-for-doc a-doc a-symbol)
+ (local ((define firs (find-for-wp (first a-doc) a-symbol))
+ (define res (find-for-doc (rest a-doc) a-symbol)))
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else res])]
+ [(wp? (first a-doc))
+ (cond
+ [(or (cons? res)
+ (empty? res)) res]
+ [(or (cons? firs)
+ (empty? firs)) firs])]))))
+ (find-for-wp a-wp a-symbol)))
\ No newline at end of file
blob - /dev/null
blob + e41da105ab09e499a625800e1b417228bf7b2a10 (mode 644)
--- /dev/null
+++ 18.1.14.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.14) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+
+;find : wp symbol -> list-of-symbols/false
+;Given a-wp and a-symbol, return the headers
+;of the web-pages that are accessed on the way
+;to locating a-symbol. Returns false
+;if a-symbol never occurs.
+
+(define (find a-wp a-symbol)
+ (cond
+ []
+ []
+ []))
\ No newline at end of file
blob - /dev/null
blob + e89ae24667fef97e68b71981beb7f176636ef14c (mode 644)
--- /dev/null
+++ 18.1.14.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.14) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;A web-page (wp) is a structure:
+;(make-wp header doc) where
+;header is a symbol and doc is
+;a web-document.
+;
+;A web-document (doc) is either
+;1. empty,
+;2. (cons sym doc) where sym is a symbol and
+;doc is a web-document, or
+;3. (cons wp doc) where wp is a webpage and
+;doc is a web-document.
+
+(define-struct wp (header doc))
+
+;find-for-wp : wp symbol -> list-of-symbols or false. Given a-wp and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-wp. Returns false if a-symbol never occurs. If there are 2 or more occurrences of a-symbol, find-for-wp returns a list-of-headers from only a single occurrence by following the path that gives preference to web-pages before embedded web pages.
+
+(define (find-for-wp a-wp a-symbol)
+ (cond
+ [(or (cons? (find-for-doc (wp-doc a-wp) a-symbol))
+ (empty? (find-for-doc (wp-doc a-wp) a-symbol))) (cons (wp-header a-wp) (find-for-doc (wp-doc a-wp) a-symbol))]
+ [else false]))
+
+;find-for-doc : doc symbol -> list-of-symbols or false
+;Given a-doc and a-symbol, return the headers of the web-pages that are accessed on the way to locating a-symbol within documents within a-doc (a-doc inclusive). Returns false if a-symbol never occurs. Return empty if a-doc contains a-symbol. If there are 2 or more occurrences of a-symbol, find-for-doc returns the list-of-headers from only a single occurrence by following the path that gives preference to web-pages before embedded web pages.
+
+(define (find-for-doc a-doc a-symbol)
+ (cond
+ [(empty? a-doc) false]
+ [(symbol? (first a-doc))
+ (cond
+ [(symbol=? a-symbol (first a-doc)) empty]
+ [else (find-for-doc (rest a-doc) a-symbol)])]
+ [(wp? (first a-doc))
+ (cond
+ [(or (cons? (find-for-wp (rest a-doc) a-symbol))
+ (empty? (find-for-wp (rest a-doc) a-symbol))) (find-for-wp (rest a-doc) a-symbol)]
+ [(or (cons? (find-for-wp (first a-doc) a-symbol))
+ (empty? (find-for-wp (first a-doc) a-symbol))) (find-for-wp (first a-doc) a-symbol)])]))
\ No newline at end of file
blob - /dev/null
blob + 30d90dbb11664479118a0ad998c4668d74ffee30 (mode 644)
--- /dev/null
+++ 18.1.15.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.15) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct ir (name price))
+
+;An inventory-record (ir) is a structure
+;(make-ir n p)
+;where n is a symbol and p is a number.
+
+;; extract1 : inventory -> inventory
+;; to create an inventory from an-inv for all
+;; those items that cost less than $1
+(define (extract1 an-inv)
+ (cond
+ [(empty? an-inv) empty]
+ [else (cond
+ [(<= (ir-price (first an-inv)) 1.00)
+ (cons (first an-inv) (extract1 (rest an-inv)))]
+ [else (extract1 (rest an-inv))])]))
blob - /dev/null
blob + c5944e7c4c22859d3ee277f98ac18f70d707837e (mode 644)
--- /dev/null
+++ 18.1.15.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.15) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct ir (name price))
+
+;An inventory-record (ir) is a structure
+;(make-ir n p)
+;where n is a symbol and p is a number.
+
+;An inventory is either
+;1. empty or
+;2. (cons ir inv)
+;where ir is an inventory record (ir) and inv is an inventory.
+
+;; extract1 : inventory -> inventory
+;; to create an inventory from an-inv for all
+;; those items that cost less than $1
+(define (extract1 an-inv)
+ (cond
+ [(empty? an-inv) empty]
+ [else
+ (local ((define fi (first an-inv))
+ (define ex (extract1 (rest an-inv))))
+ (cond
+ [(<= (ir-price fi) 1.00)
+ (cons fi ex)]
+ [else ex]))]))
+
+(define INV (list (make-ir 'JumpingJacks 0.75)
+ (make-ir 'LaserPen 0.99)
+ (make-ir 'BowlingPin 1.25)
+ (make-ir 'NightLite 0.45)
+ (make-ir 'Telescope 5.50)
+ (make-ir 'Pogs 0.50)))
blob - /dev/null
blob + 94939ee3d1569ba11f3b3dbde8c03f28d3ad1a08 (mode 644)
--- /dev/null
+++ 18.1.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 356943d886dc40ea8f97acff761829300eb52428 (mode 644)
--- /dev/null
+++ 18.1.4.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(local ( (define x 5))
+ x)
+
+1. (define (x-1 y) (* 3 y))
+
+ (* (x-1 2) 5)
+
+ (define (x-1 y) (* 3 y))
+
+ (* (* 3 2) 5)
+
+(* 6 5)
+
+30
+
+
+
+
+
+2.
+ (define (f-1 c) (+ (* 9/5 c) 32))
+
+
+ (- (f-1 0) (f-1 10))
+
+
+ (define (f-1 c) (+ (* 9/5 c) 32))
+
+
+ (- (+ (* 9/5 0) 32) (+ (* 9/5 10) 32))
+ (- (+ 0 32) (+ 90/5 32))
+ (- 32 50)
+ -18
+
+
+3. (local (
+
+ (define (odd?-1 n)
+ (cond
+ [(zero? n) false]
+ [else (even? (sub1 n))]))
+
+ (define (even?-1 n)
+ (cond
+ [(zero? n) true]
+ [else (odd? (sub1 n))]))
+
+ )
+ (even?-1 1)
+
+ )
+
+
+ (define (odd?-1 n)
+ (cond
+ [(zero? n) false]
+ [else (even? (sub1 n))]))
+
+ (define (even?-1 n)
+ (cond
+ [(zero? n) true]
+ [else (odd? (sub1 n))]))
+
+ (even?-1 1)
+
+ (cond
+ [false true]
+ [else (odd? 0)])
+
+
+ (cond
+ [false true]
+ [else (cond
+ [true false]
+ [else (even? (sub1 0))])])
+
+ (cond
+ [false true]
+ [else false])
+
+ false
+
+
+4. (+
+
+
+ (local ((define (f x) (g (+ x 1) 22))
+ (define (g x y) (+ x y)))
+ (f 10))
+
+
+ 555)
+
+(+
+
+
+ (local ((define (f-1 x) (g (+ x 1) 22))
+ (define (g x y) (+ x y)))
+ (f 10))
+
+
+ 555)
+
+
+5. (define (h n)
+ (cond
+ [(= n 0) empty]
+ [else (local ((define r (* n n)))
+ (cons r (h (- n 1))))]))
+ (h 2)
blob - /dev/null
blob + fbdaad5246ca574b501abedf6b73bd5ccb66e384 (mode 644)
--- /dev/null
+++ 18.1.5.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.5) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+(+ (local ((define (f x) (g (+ x 1) 22))
+ (define (g x y) (+ x y)))
+ (f 10))
+ 555)
blob - /dev/null
blob + bce4cde89af1379850169bb8344b1b737a652552 (mode 644)
--- /dev/null
+++ 18.1.6.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.6) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+A list-of-numbers is either
+1. an empty list or
+2. (cons n lon)
+where n is a number and lon is a list-of-numbers.
+
+sort : list-of-numbers -> list-of-numbers
+Given a-lon, sort the list of numbers (in ascending order) by insertion sorting.
+
+(define (sort a-lon)
+ (cond
+ []
+ []))
+
+insert : number list-of-numbers (sorted) -> list-of-numbers
\ No newline at end of file
blob - /dev/null
blob + a3bf4a035062eb8db44e5641ddd00facb08a6fbf (mode 644)
--- /dev/null
+++ 18.1.6.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.6) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+;A list-of-numbers is either
+;1. an empty list or
+;2. (cons n lon)
+;where n is a number and lon is a list-of-numbers.
+;
+;sortascend : list-of-numbers -> list-of-numbers
+;Given a-lon, sorts a-lon in ascending order.
+
+(define (sortascend a-lon)
+ (local ((define (sort a-lon)
+ (cond
+ [(empty? a-lon) empty]
+ [(cons? a-lon) (insert (first a-lon) (sort (rest a-lon)))]))
+ (define (insert a-number a-lon)
+ (cond
+ [(empty? a-lon) (list a-number)]
+ [(<= a-number (first a-lon)) (cons a-number a-lon)]
+ [else (cons (first a-lon) (insert a-number (rest a-lon)))])))
+ (sort a-lon)))
+
+
+
blob - /dev/null
blob + cb62555bdae2b0b23bbd988c98b17d0c21174213 (mode 644)
--- /dev/null
+++ 18.1.7.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 18.1.7) (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")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+;Template
+;fun-for-losh : list-of-shapes -> ???
+;Consumes a list-of-shapes.
+;
+;(define (fun-for-losh alosh)
+; (cond
+; [(empty? alosh) ...]
+; [(circle? (first alosh)) ... (first alosh) (fun-for-losh (rest alosh))]
+; [(rectangle? (first alosh)) ...(first alosh) (fun-for-losh (rest alosh))]
+; [else ...]))
+
+;draw-losh : list-of-shapes -> boolean
+;Consumes alosh and draws the shapes on the canvas,
+;returning true. If drawing fails, it returns false.
+
+(define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+;draw-a-circle : circle -> boolean?
+;Draws a circle given a-circle (struct circle).
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+; draw-a-rectangle : rectangle -> boolean
+; Returns true after drawing, consumes a-rect.
+
+(define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;translate-losh : list-of-shapes number -> list-of-shapes
+;Given alosh, returns a list-of-shapes that have translated
+;delta pixels in the x direction. This function
+;does not affect the canvas.
+
+(define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+;clear-losh : list-of-shapes -> boolean
+;Clears shapes corresponding to entries in alosh
+;and returns true. Does so by calling clear-a-rectangle
+;and clear-a-circle.
+
+(define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+; clear-a-circle : circle -> boolean
+; Clears a circle given a-circle, returns true if
+; evaluation completes successfully, false otherwise.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+; clear-a-rectangle : rectangle -> boolean
+; Clears rectangle specified by a-rect and returns true
+; if evaluation suceeds, false otherwise.
+
+(define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+;Data Definition
+;
+;A picture is a list-of-shapes?, I think.
+;
+;draw-and-clear-picture : picture -> boolean
+;Draws alosh, sleeps for a while, then clears alosh.
+;!!!CHANGE!!! Now it clears, sleeps for a while,
+;then draws alosh.
+
+(define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+; (sleep-for-a-while 2)
+ (clear-losh alosh)))
+;
+;move-picture : number picture -> picture
+;Draws a picture delta pixels to the right, sleeps for a while,
+;clears the picture, and then returns the translated picture.
+
+(define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false]))
+
+(start 500 100)
+
+(control-left-right FACE 100 move-picture draw-losh)
\ No newline at end of file
blob - /dev/null
blob + b543a29e9cd9db1ba1c992841039918ec4622657 (mode 644)
--- /dev/null
+++ 18.1.7.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.7) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+(define (move-picture delta alosh)
+ (local (;draw-losh : list-of-shapes -> boolean
+ ;Consumes alosh and draws the shapes on the canvas,
+ ;returning true. If drawing fails, it returns false.
+
+ (define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+ ;draw-a-circle : circle -> boolean?
+ ;Draws a circle given a-circle (struct circle).
+
+ (define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+ ; draw-a-rectangle : rectangle -> boolean
+ ; Returns true after drawing, consumes a-rect.
+
+ (define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+ ;translate-losh : list-of-shapes number -> list-of-shapes
+ ;Given alosh, returns a list-of-shapes that have translated
+ ;delta pixels in the x direction. This function
+ ;does not affect the canvas.
+
+ (define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+ ;clear-losh : list-of-shapes -> boolean
+ ;Clears shapes corresponding to entries in alosh
+ ;and returns true. Does so by calling clear-a-rectangle
+ ;and clear-a-circle.
+
+ (define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+ ; clear-a-circle : circle -> boolean
+ ; Clears a circle given a-circle, returns true if
+ ; evaluation completes successfully, false otherwise.
+
+ (define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+ ; clear-a-rectangle : rectangle -> boolean
+ ; Clears rectangle specified by a-rect and returns true
+ ; if evaluation suceeds, false otherwise.
+
+ (define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+ ;Data Definition
+ ;
+ ;A picture is a list-of-shapes?, I think.
+ ;
+ ;draw-and-clear-picture : picture -> boolean
+ ;Draws alosh, sleeps for a while, then clears alosh.
+ ;!!!CHANGE!!! Now it clears, sleeps for a while,
+ ;then draws alosh.
+
+ (define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+ (sleep-for-a-while 0.1)
+ (clear-losh alosh)))
+ ;
+ ;move-picture : number picture -> picture
+ ;Draws a picture delta pixels to the right, sleeps for a while,
+ ;clears the picture, and then returns the translated picture.
+
+ (define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false])))
+ (move-picture delta alosh)))
+
+(start 500 500)
+(move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 (move-picture 5 FACE)))))))))))))))))))))))))))))))))))))))))
\ No newline at end of file
blob - /dev/null
blob + 5602a71a0da82ca3fa573cf412408574638f4283 (mode 644)
--- /dev/null
+++ 18.1.8.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.8) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define MRPOLY (cons (make-posn 50 50) (cons (make-posn 50 80) (cons (make-posn 100 80) (cons (make-posn 140 230) (cons (make-posn 180 330) (cons (make-posn 240 220) (cons (make-posn 130 220) empty))))))))
+
+(define (draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (cons (last a-poly) a-poly))]))
+
+(define (connect-dots a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (and
+ (draw-solid-line (first a-poly)
+ (second a-poly)
+ 'black)
+ (connect-dots (rest a-poly)))]))
+
+(define (last a-poly)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (last (rest a-poly))]))
+(define (add-at-end a-poly first-posn)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (cons (add-at-end a-poly first-posn) (cons first-posn empty))]))
+(define (modified-draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (add-at-end a-poly))]))
\ No newline at end of file
blob - /dev/null
blob + 98dcb4cae5c54fa17560d3239bb9d0b5a6af1a6e (mode 644)
--- /dev/null
+++ 18.1.8.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.8) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define MRPOLY (list (make-posn 20 30)
+ (make-posn 30 40)
+ (make-posn 50 90)
+ (make-posn 100 40)
+ (make-posn 150 80)
+ (make-posn 240 120)
+ (make-posn 40 10)))
+
+(define (modified-draw-polygon a-poly)
+ (local ((define (draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (cons (last a-poly) a-poly))]))
+
+ (define (connect-dots a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (and
+ (draw-solid-line (first a-poly)
+ (second a-poly)
+ 'black)
+ (connect-dots (rest a-poly)))]))
+
+ (define (last a-poly)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (last (rest a-poly))]))
+ (define (add-at-end a-poly first-posn)
+ (cond
+ [(empty? (rest a-poly)) (first a-poly)]
+ [else (cons (add-at-end a-poly first-posn) (cons first-posn empty))]))
+ (define (modified-draw-polygon a-poly)
+ (cond
+ [(empty? (rest a-poly)) true]
+ [else (connect-dots (add-at-end a-poly (first a-poly)))])))
+ (modified-draw-polygon a-poly)))
+
+(start 500 500)
+(modified-draw-polygon MRPOLY)
\ No newline at end of file
blob - /dev/null
blob + 67b0db0f106301029fa52cb1acace5435e2e5586 (mode 644)
--- /dev/null
+++ 18.1.9.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 18.1.9) (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")))))
+;;Data Definition
+;;A word is either
+;;1. an empty list or
+;;2. (cons l w) where l is a symbol (one of the
+;;lowercase letters 'a, 'b, ... 'z) and w is a word.
+;;
+;;Examples
+;;empty
+;;(cons 'i empty)
+;;(cons 'h (cons 'i empty))
+;;(cons 'n (cons 'a (cons 'm (cons 'e empty))))
+;;
+;;A list-of-words is either
+;;1. (cons w empty) or
+;;2. (cons w low) where w is a word
+;;and low is a list-of-words.
+;;
+;;Examples
+;;(cons empty empty)
+;;empty empty
+;;(cons (cons 'i empty) empty)
+;;i
+;;(cons (cons 'h (cons 'i empty)) empty)
+;;hi
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty))) empty)
+;;hi joe
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty)))
+;; (cons (cons 'i (cons 't (cons 's empty)))
+;; empty)))
+;;hi joe its
+;;(cons (cons 'h (cons 'i empty))
+;; (cons (cons 'j (cons 'o (cons 'e empty)))
+;; (cons (cons 'i (cons 't (cons 's empty)))
+;; (cons (cons 'm (cons 'e empty)) empty))))
+;;hi joe its me
+;
+;;arrangements : word -> list-of-words
+;;Given a-word, return all permutations
+;;as a list-of-words. This is done
+;;by inserting the first letter into
+;;each permutation of the rest of the word.
+;
+(define (arrangements a-word)
+ (cond
+ [(empty? a-word) (cons empty empty)]
+ [else (insert-everywhere/in-all-words (first a-word)
+ (arrangements (rest a-word)))]))
+;
+;;insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+;;Given a-symbol and a-low, insert a-symbol into every possible position
+;;to generate a new list-of-words. In general, if the words in a-low
+;;contain x letters, there should be (x+1)*x words in the list-of-words output.
+;
+;
+;;Examples
+;;(define ex1 (cons empty empty))
+;;(insert-everywhere/in-all-words 'a ex1)
+;;(cons (cons 'a empty) empty)
+;;
+;;(define ex2 (cons (cons 'i empty) empty))
+;;(insert-everywhere/in-all-words 'a ex2)
+;;(cons (cons 'a (cons 'i empty))
+;; (cons (cons 'i (cons 'a empty)) empty))
+;;
+;;(define ex3 (cons (cons 'h (cons 'i empty))
+;; (cons (cons 'i (cons 'h empty)) empty)))
+;;(insert-everywhere/in-all-words 'b ex3)
+;;(cons (cons 'b (cons 'h (cons 'i empty)))
+;; (cons (cons 'h (cons 'b (cons 'i empty)))
+;; (cons (cons 'h (cons 'i (cons 'b empty)))
+;; (cons (cons 'b (cons 'i (cons 'h empty)))
+;; (cons (cons 'i (cons 'b (cons 'h empty)))
+;; (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
+;
+(define (insert-everywhere/in-all-words a-symbol a-low)
+ (cond
+ [(empty? (first a-low))
+ (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0)]
+ [(cons? (first a-low)) ;evaluates true if the first element
+ ;in a-low is a word
+ (cons (insert-everywhere/in-all-words a-symbol (rest a-low))
+ (insert-symbol-everywhere/in-single-word a-symbol (first a-low) 0))()]))
+
+;insert-symbol-everywhere/in-single-word : symbol word number -> list-of-words
+;Given a-symbol and a-word, inserts a-symbol into every possible position
+;to generate a list-of-words. Begins insertion at the nth position.
+
+(define (insert-symbol-everywhere/in-single-word a-symbol a-word n)
+ (cond
+ [(empty? a-word) (cons (cons a-symbol empty) empty)]
+ [(and
+ (cons? a-word)
+ (<= n (length a-word)))
+ (cons (insert-symbol-here a-symbol a-word n)
+ (insert-symbol-everywhere/in-single-word a-symbol a-word (add1 n)))]
+ [(> n (length a-word)) empty]
+ [else (error 'insert-symbol-everywhere/in-single-word "unexpected error")]))
+;
+;insert-symbol-here : symbol word number -> word
+;Given a-symbol and a-word and n, insert a-symbol
+;in the nth position of a-word. Right before
+;the word is the 0th position. The first position
+;is right after the first letter.
+;
+;Examples:
+;(insert-symbol-here 'a (cons 'n empty) 0)
+;(cons 'a (cons 'n empty))
+;
+;(insert-symbol-here 'a (cons 'n empty) 1)
+;(cons 'n (cons 'a empty))
+;
+
+(define (insert-symbol-here a-symbol a-word n)
+ (cond
+ [(= n 0) (cons a-symbol a-word)]
+ [(>= n 1)
+ (cons (first a-word)
+ (insert-symbol-here a-symbol (rest a-word) (sub1 n)))]))
+
+;Test insert-symbol-here
+;(define word1 empty)
+;(define word2 (cons 'a empty))
+;(define word3 (cons 'a (cons 'b empty)))
+;(define word4 (cons 'a (cons 'b (cons 'c empty))))
+;(insert-symbol-here 'x word1 0)
+;(insert-symbol-here 'x word2 0)
+;(insert-symbol-here 'x word2 1)
+;(insert-symbol-here 'x word3 0)
+;(insert-symbol-here 'x word3 1)
+;(insert-symbol-here 'x word3 2)
+
+;Examples of insert-symbol-everywhere/in-single-word
+;
+;(define ex01 empty)
+;(insert-symbol-everywhere/in-single-word 'x ex01 0)
+;(cons (cons 'x empty) empty)
+;(define ex02 (cons 'a empty))
+;(insert-symbol-everywhere/in-single-word 'x ex02 0)
+;(cons (cons 'x (cons 'a empty))
+; (cons (cons 'a (cons 'x empty)) empty))
+;(append (cons (cons 'x (cons 'a empty)) empty)
+; (cons (cons 'a (cons 'x empty)) empty))
+;(define ex03 (cons 'a (cons 'b empty)))
+;(insert-symbol-everywhere/in-single-word 'x ex03 0)
+;(cons (cons 'x (cons 'a (cons 'b empty)))
+; (cons (cons 'a (cons 'x (cons 'b empty)))
+; (cons (cons 'a (cons 'b (cons 'x empty))) empty)))
+;(define ex04 (list 'p 'a 'r 't 'y))
+;(insert-symbol-everywhere/in-single-word 'x ex04 0)
+;
+
+;Test insert-everywhere/in-all-words : symbol list-of-words -> list-of-words
+
+(define ex1 (cons empty empty))
+(insert-everywhere/in-all-words 'a ex1)
+(cons (cons 'a empty) empty)
+
+(define ex2 (cons (cons 'i empty) empty))
+(insert-everywhere/in-all-words 'a ex2)
+(cons (cons 'a (cons 'i empty))
+ (cons (cons 'i (cons 'a empty)) empty))
+
+(define ex3 (cons (cons 'h (cons 'i empty))
+ (cons (cons 'i (cons 'h empty)) empty)))
+(insert-everywhere/in-all-words 'b ex3)
+(cons (cons 'b (cons 'h (cons 'i empty)))
+ (cons (cons 'h (cons 'b (cons 'i empty)))
+ (cons (cons 'h (cons 'i (cons 'b empty)))
+ (cons (cons 'b (cons 'i (cons 'h empty)))
+ (cons (cons 'i (cons 'b (cons 'h empty)))
+ (cons (cons 'i (cons 'h (cons 'b empty))) empty))))))
blob - /dev/null
blob + 8ba679fba3ab6148a4a96fcf429d2d3226341af5 (mode 644)
--- /dev/null
+++ 18.1.9.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.9) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;arrangements : list-of-names -> list-of-list-of-names
+;Given names (a list-of-names), return all permutations of the names.
+
+;insert-in-lolon : symbol list-of-list-of-names -> list-of-list-of-names
+;Given a-symbol and a-lolon, insert a-symbol into every position in each list-of-names element within a-lolon to return a new list-of-list-of-names.
+
+;insert-name : symbol list-of-names N[>=0] -> list-of-list-of-names
+;Given a-symbol, insert it into every position in names starting at the n-th position, continuing to the very beginning of the list-of-names (n=0), to return a list-of-list-of-names.
+
+;insert-name-at-posn : symbol list-of-names N[>=0] -> list-of-names
+;Given a-symbol (symbol), names (list-of-names), and n (N[>=0]), insert a-symbol into names at the n-th position and return the list-of-names.
+(define (arrangements names)
+ (local ((define (arrangements names)
+ (cond
+ [(empty? names) (list empty)]
+ [else (insert-in-lolon (first names) (arrangements (rest names)))]))
+
+
+ (define (insert-in-lolon a-symbol a-lolon)
+ (cond
+ [(empty? a-lolon) empty]
+ [(cons? a-lolon)
+ (append (insert-name a-symbol (first a-lolon) (length (first a-lolon)))
+ (insert-in-lolon a-symbol (rest a-lolon)))]))
+
+
+ (define (insert-name a-symbol names n)
+ (cond
+ [(= n 0) (list (insert-name-at-posn a-symbol names n))]
+ [(cons? names) (append (list (insert-name-at-posn a-symbol names n))
+ (insert-name a-symbol names (sub1 n)))]
+ [(empty? names) (error 'insert-name "unexpected error")]))
+
+ (define (insert-name-at-posn a-symbol names n)
+ (cond
+ [(= n 0) (append (list a-symbol) names)]
+ [(cons? names) (append (list (first names))
+ (insert-name-at-posn a-symbol (rest names) (sub1 n)))]
+ [(empty? names) (error 'insert-name-at-posn "list too short")])))
+ (arrangements names)))
\ No newline at end of file
blob - /dev/null
blob + da1d00eaceb63a4717ed3ac6430ac5f2e80ef809 (mode 644)
--- /dev/null
+++ 18.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (p1 x y)
+ (+ (* x y)
+ (+ (* 2 x)
+ (+ (* 2 y) 22))))
+
+(define (p2 x)
+ (+ (* 55 x) (+ x 11)))
+
+(define (p3 x)
+ (+ (p1 x 0)
+ (+ (p1 x 1) (p2 x))))
\ No newline at end of file
blob - /dev/null
blob + 775e8a420c3ea9b9d902bf0937eda2efb205a104 (mode 644)
--- /dev/null
+++ 18.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (p1 a y)
+ (+ (* a y)
+ (+ (* 2 a)
+ (+ (* 2 y) 22))))
+
+(define (p2 x)
+ (+ (* 55 x) (+ x 11)))
+
+(define (p3 b)
+ (+ (p1 b 0)
+ (+ (p1 b 1) (p2 b))))
+
+(define (f x)
+ (local ((define (g x) (+ 2 (* x 2))))
+ (g x)))
+
+(define (a-function y)
+ (local ((define (f x y) (+ (* x y) (+ x y)))
+ (define (g z)
+ (local ((define (f x) (+ (* x x) 55))
+ (define (g y) (+ (f y) 10)))
+ (f z)))
+ (define (h x) (f x (g x))))
+ (h y)))
+
+;; sort : list-of-numbers -> list-of-numbers
+(define (1sort alon)
+ (local ((define (sort alon)
+ (cond
+ [(empty? alon) empty]
+ [(cons? alon) (insert (first alon) (sort (rest alon)))]))
+ (define (insert an alon)
+ (cond
+ [(empty? alon) (list an)]
+ [else (cond
+ [(> an (first alon)) (cons an alon)]
+ [else (cons (first alon) (insert an (rest alon)))])])))
+ (sort alon)))
+
+(define x (cons 1 x))
\ No newline at end of file
blob - /dev/null
blob + 7a54ffa4f209ce7f3e6f6d5e5f26d922f0a1f8a6 (mode 644)
--- /dev/null
+++ 18.8.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.8.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(local ((define x (* y 3)))
+ (* x x))
\ No newline at end of file
blob - /dev/null
blob + 898289858118abd2ed0d34a5965815332d8af742 (mode 644)
--- /dev/null
+++ 18.8.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.8.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+(local (
+ (define x (* y 3))
+ )
+
+ (* x x))
+
+(local (
+
+ (define (odd an)
+ (cond
+ [(zero? an) false]
+ [else (even (sub1 an))]))
+
+
+ (define (even an)
+ (cond
+ [(zero? an) true]
+ [else (odd (sub1 an))])))
+
+
+ (even a-nat-num))
+
+(local (
+
+ (define (f x) (g x (+ x 1)))
+ (define (g x y) (f (+ x y)))
+
+ )
+
+
+ (+ (f 10) (g 10 20))
+
+ )
+
+(local (
+ (define x 10)
+ (y (+ x x)))
+ y)
+
+(local (
+
+ (define (f x) (+ (* x x) (* 3 x) 15))
+ (define x 100)
+ (define f@100 (f x))
+
+ )
+
+
+ f@100 x)
+
+(local (
+ (define (f x) (+ (* x x) (* 3 x) 14))
+ (define x 100)
+ (define f (f x)))
+ f)
+
+1. (define A-CONSTANT
+ (not
+
+
+ (local (
+
+ (define (odd an)
+ (cond
+ [(= an 0) false]
+ [else (even (- an 1))]))
+
+
+ (define (even an)
+ (cond
+ [(= an 0) true]
+ [else (odd (- an 1))]))
+
+ )
+
+
+ (even a-nat-num)
+
+ )
+
+ ))
+2. (+ (local ((define (f x) (+ (* x x) (* 3 x) 15))
+ (define x 100)
+ (define f@100 (f x)))
+ f@100)
+ 1000)
+3. (local ((define CONST 100)
+ (define f x (+ x CONST)))
+ (define (g x y z) (f (+ x (* y z)))))
\ No newline at end of file
blob - /dev/null
blob + 4c35dd33e4e005ac7b7e61ab562005d9ae42a10c (mode 644)
--- /dev/null
+++ 19.1
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 78 0 1 #"\0"
+0 75 1 #"\0"
+0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 12 #"Courier New\0"
+0 9 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+41 #"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 33
+#"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 0 1 #"\0"
+0 75 12 #"Courier New\0"
+0.0 9 90 -1 90 -1 3 -1 0 1 0 1 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255 255
+255 1 -1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 0 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1
+ 0 760 0 17 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 68 29 1 #"\n"
+0 0 17 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 68 29 1 #"\n"
+0 0 24 3 7 #"#reader"
+0 0 22 3 1 #"("
+0 0 14 3 3 #"lib"
+0 0 68 3 1 #" "
+0 0 19 3 29 #"\"htdp-intermediate-reader.ss\""
+0 0 68 3 1 #" "
+0 0 19 3 6 #"\"lang\""
+0 0 22 3 3 #")(("
+0 0 14 3 7 #"modname"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"|19|"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 19 #"read-case-sensitive"
+0 0 68 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"teachpacks"
+0 0 68 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 14 3 3 #"lib"
+0 0 68 3 1 #" "
+0 0 19 3 9 #"\"draw.ss\""
+0 0 68 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 68 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 3 #")))"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 13 #"htdp-settings"
+0 0 68 3 1 #" "
+0 0 22 3 2 #"#("
+0 0 20 3 2 #"#t"
+0 0 68 3 1 #" "
+0 0 14 3 11 #"constructor"
+0 0 68 3 1 #" "
+0 0 14 3 17 #"repeating-decimal"
+0 0 68 3 1 #" "
+0 0 20 3 2 #"#f"
+0 0 68 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"none"
+0 0 68 3 1 #" "
+0 0 20 3 2 #"#f"
+0 0 68 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 14 3 3 #"lib"
+0 0 68 3 1 #" "
+0 0 19 3 9 #"\"draw.ss\""
+0 0 68 3 1 #" "
+0 0 19 3 11 #"\"teachpack\""
+0 0 68 3 1 #" "
+0 0 19 3 6 #"\"htdp\""
+0 0 22 3 5 #")))))"
+0 0 68 29 1 #"\n"
+0 0 17 3 27 #";; mini : nelon -> number"
+0 0 68 29 1 #"\n"
+0 0 17 3 35 #";; to determine the smallest number"
+0 0 68 29 1 #"\n"
+0 0 17 3 10 #";; on alon"
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"mini"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #"))"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #"<"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 68 29 1 #"\n"
+0 0 68 3 16 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"mini"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 68 3 13 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 29 1 #"\n"
+0 0 68 3 13 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"mini"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 7 #"))])]))"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 17 3 27 #";; maxi : nelon -> number"
+0 0 68 29 1 #"\n"
+0 0 17 3 34 #";; to determine the largest number"
+0 0 68 29 1 #"\n"
+0 0 17 3 10 #";; on alon"
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"maxi"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #"))"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 1 #">"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 16 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"maxi"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 68 3 13 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 29 1 #"\n"
+0 0 68 3 13 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"maxi"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 7 #"))])]))"
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 39 #";A non-empty-list-of-numbers (nelon) is"
+0 0 68 29 1 #"\n"
+0 0 17 3 18 #";1. (cons n empty)"
+0 0 68 29 1 #"\n"
+0 0 17 3 15 #";2. (cons n ne)"
+0 0 68 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 66
+#"where n is a number and ne is a non-empty-list-of-numbers (nelon)."
+0 0 72 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 68 29 1 #"\n"
+0 0 17 3 36 #";extrema : predicate nelon -> number"
+0 0 68 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 79
+(
+ #"Given predicate and a-lon, return the extreme value depending on the"
+ #" predicate."
+) 0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 16 #"pick-interesting"
+0 0 17 3 28 #" : predicate list-of-numbers"
+0 0 68 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 5 #"Given"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"predicate"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"a-lon"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 4 #"pick"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 11 #"interesting"
+0 0 17 3 18 #" (extreme) number."
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extrema"
+0 0 68 3 1 #" "
+0 0 14 3 9 #"predicate"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 2 #"))"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 68 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 14 3 17 #"extrema-recursion"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extrema"
+0 0 68 3 1 #" "
+0 0 14 3 9 #"predicate"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 68 3 18 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 16 #"pick-interesting"
+0 0 68 3 1 #" "
+0 0 14 3 9 #"predicate"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 20 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 9 #"predicate"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 14 3 17 #"extrema-recursion"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 14 3 17 #"extrema-recursion"
+0 0 22 3 4 #"])))"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 1 #"("
+0 0 14 3 16 #"pick-interesting"
+0 0 68 3 1 #" "
+0 0 14 3 9 #"predicate"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 5 #"))]))"
+0 0 68 29 1 #"\n"
+0 0 72 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 17 3 24 #";mini1 : nelon -> number"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 40 #";Given a-lon, returns the minimum value."
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"mini1"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extrema"
+0 0 68 3 1 #" "
+0 0 14 3 1 #"<"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 2 #"))"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 24 #";maxi1 : nelon -> number"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 40 #";Given a-lon, returns the maximum value."
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"maxi1"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"extrema"
+0 0 68 3 1 #" "
+0 0 14 3 1 #">"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lon"
+0 0 22 3 2 #"))"
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 2 #";("
+0 0 17 3 4 #"time"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 5 #"mini1"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"20"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"19"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"18"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"17"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"16"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"15"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"14"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"13"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"12"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"11"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"10"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"9"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"8"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"7"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"6"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"5"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"4"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"3"
+0 0 17 3 7 #" 2 1)))"
+0 0 68 29 1 #"\n"
+0 0 17 3 2 #";("
+0 0 17 3 4 #"time"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 5 #"maxi1"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"1"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"2"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"3"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"4"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"5"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"6"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"7"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"8"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"9"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"10"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"11"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"12"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"13"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"14"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"15"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"16"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"17"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"18"
+0 0 17 3 9 #" 19 20)))"
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 55 #";; sort : list-of-numbers predicate -> list-of-numbers"
+0 0 68 29 1 #"\n"
+0 0 17 3 80
+(
+ #";; to construct a list with all items from alon in ascending or desc"
+ #"ending order"
+) 0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"sort1"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 68 3 1 #" "
+0 0 14 3 9 #"predicate"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 68 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sort"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 6 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 6 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"insert"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sort"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 6 #")))]))"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"insert"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"an"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 6 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"an"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 0 68 3 6 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 1 68 65 1 #"\t"
+0 0 68 3 6 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 9 #"predicate"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"an"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #"))"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"an"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 1 68 65 1 #"\t"
+0 1 68 65 1 #"\t"
+0 0 68 3 6 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"insert"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"an"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 9 #")))])])))"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sort"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 30 #";sort-ascend : list-of-numbers"
+0 0 68 29 1 #"\n"
+0 0 17 3 6 #";Given"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"a-lon"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 6 #"return"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 15 #"list-of-numbers"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"sorted"
+0 0 17 3 1 #" "
+0 0 17 3 19 #"in ascending order."
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 11 #"sort-ascend"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"sort1"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 68 3 1 #" "
+0 0 14 3 1 #"<"
+0 0 22 3 2 #"))"
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 30 #"sort-descend : list-of-numbers"
+0 0 68 29 1 #"\n"
+0 0 17 3 1 #";"
+0 0 17 3 5 #"Given"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"a-lon"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 6 #"return"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 15 #"list-of-numbers"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"sorted"
+0 0 17 3 1 #" "
+0 0 17 3 20 #"in descending order."
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 12 #"sort-descend"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"sort1"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"alon"
+0 0 68 3 1 #" "
+0 0 14 3 1 #">"
+0 0 22 3 2 #"))"
+0 0
blob - /dev/null
blob + 731533f347a31dc7f90ed68ffbb60f24b0aba079 (mode 644)
--- /dev/null
+++ 19.1.0.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.1.0) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (filter1 rel-op alon t)
+ (cond
+ [(empty? alon) empty]
+ [else (cond
+ [(rel-op (first alon) t)
+ (cons (first alon)
+ (filter1 rel-op (rest alon) t))]
+ [else
+ (filter1 rel-op (rest alon) t)])]))
\ No newline at end of file
blob - /dev/null
blob + 0b5cb2396918a16bd5d34763d40681e9771a9c6b (mode 644)
--- /dev/null
+++ 19.1.0.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.1.0) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (filter1 rel-op alon t)
+ (cond
+ [(empty? alon) empty]
+ [else (cond
+ [(rel-op (first alon) t)
+ (cons (first alon)
+ (filter1 rel-op (rest alon) t))]
+ [else
+ (filter1 rel-op (rest alon) t)])]))
+
+(filter1 < (cons 6 (cons 4 empty)) 5)
+
+(cond
+ [false empty]
+ [else (cond
+ [false
+ (cons (first (cons 6 (cons 4 empty)))
+ (filter1 rel-op (rest (cons 6 (cons 4 empty))) 5))]
+ [else
+ (filter1 < (rest (cons 6 (cons 4 empty))) 5)])])
+
+(filter1 < (rest (cons 6 (cons 4 empty))) 5)
+
+(cond
+ [false empty]
+ [else (cond
+ [true
+ (cons (first (cons 4 empty))
+ (filter1 rel-op (rest (cons 4 empty)) 5))]
+ [else
+ (filter1 < (rest (cons 4 empty)) 5)])])
+
+(cons (first (cons 4 empty))
+ (filter1 rel-op (rest (cons 4 empty)) 5))
+
+(cons 4 (filter1 rel-op (rest (cons 4 empty)) 5))
+
+(cons 4 (filter1 < empty) 5)
+(cons 4 empty)
+
+(filter1 > (cons 8 (cons 6 (cons 4 empty))) 5)
+
+(cond
+ [(empty? alon) empty]
+ [else (cond
+ [(rel-op (first alon) t)
+ (cons (first alon)
+ (filter1 rel-op (rest alon) t))]
+ [else
+ (filter1 rel-op (rest alon) t)])])
+
+(cons 8 (filter1 > (cons 6 (cons 4 empty)) 5))
+(cons 8 (cons 6 (filter1 > (cons 4 empty) 5)))
+(cons 8 (cons 6 (filter1 > empty 5)))
+(cons 8 (cons 6 empty))
\ No newline at end of file
blob - /dev/null
blob + ed9ec3c2538bf86060882b7d199546f774c860b9 (mode 644)
--- /dev/null
+++ 19.1.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.1.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (squared>? x c)
+ (> (* x x) c))
+
+;filter : predicate list-of-numbers
+;Filters out all numbers in a-lon where the predicate of the number evaluates to false. Retains all numbers that evaluate to true.
+(define (filter predicate a-lon)
+ (cond
+ [(empty? a-lon) empty]
+ [(predicate (first a-lon)) (cons (first a-lon) (filter predicate (rest a-lon)))]
+ [else (filter predicate (rest a-lon))]))
+
+(filter squared>? '(5 6 7 1 3 5 0 9 3 4 2))
\ No newline at end of file
blob - /dev/null
blob + 6363bbc59129be9eda7ffe23ae21e26bcdfc2b36 (mode 644)
--- /dev/null
+++ 19.1.4.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.1.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (squared>? x c)
+ (> (* x x) c))
+
+;filter : predicate list-of-numbers
+;Filters out all numbers in a-lon where the predicate of the number evaluates to false. Retains all numbers that evaluate to true.
+(define (filter1 predicate a-lon t)
+ (cond
+ [(empty? a-lon) empty]
+ [(predicate (first a-lon) t) (cons (first a-lon)
+ (filter1 predicate (rest a-lon) t))]
+ [else (filter1 predicate (rest a-lon) t)]))
+
+#|
+(filter1 squared>? (list 4 5) 10)
+= (cons 4 (filter1 squared>? (list 5) 10))
+
+(cond
+ [(empty? (list 4 5)) empty]
+ [(squared>? (first (list 4 5)) 10) (cons (first (list 4 5))
+ (filter1 squared>? (rest (list 4 5)) 10))]
+ [else (filter squared>? (rest (list 4 5)))])
+
+(cond
+ [false empty]
+ [true (cons 4
+ (filter1 squared>? (list 5) 10))]
+ [else (filter squared>? (rest (list 4 5)))])
+
+(cons 4 (filter1 squared>? (list 5) 10))
+|#
+
+;below : list-of-numbers number -> list-of-numbers
+;Given a-lon, return all numbers below a-number as a list-of-numbers.
+
+(define (below a-lon a-number)
+ (filter1 < a-lon a-number))
+
+;above: list-of-numbers number -> list-of-numbers
+;Given a-lon, return all numbers above a-number as a list-of-numbers.
+
+(define (above a-lon a-number)
+ (filter1 > a-lon a-number))
\ No newline at end of file
blob - /dev/null
blob + 6b5782d30eadaa24cf64dd43aa2d7c8dea2744c8 (mode 644)
--- /dev/null
+++ 19.1.5.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.1.5) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;; mini : nelon -> number
+;; to determine the smallest number
+;; on alon
+(define (mini alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(< (first alon)
+ (mini (rest alon)))
+ (first alon)]
+ [else
+ (mini (rest alon))])]))
+
+;; maxi : nelon -> number
+;; to determine the largest number
+;; on alon
+(define (maxi alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(> (first alon)
+ (maxi (rest alon)))
+ (first alon)]
+ [else
+ (maxi (rest alon))])]))
blob - /dev/null
blob + f88938bf260f4274a0a14cfba0c2bfe1419fbc2c (mode 644)
--- /dev/null
+++ 19.1.5.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.1.5) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;; mini : nelon -> number
+;; to determine the smallest number
+;; on alon
+(define (mini alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(< (first alon)
+ (mini (rest alon)))
+ (first alon)]
+ [else
+ (mini (rest alon))])]))
+
+;; maxi : nelon -> number
+;; to determine the largest number
+;; on alon
+(define (maxi alon)
+ (cond
+ [(empty? (rest alon)) (first alon)]
+ [else (cond
+ [(> (first alon)
+ (maxi (rest alon)))
+ (first alon)]
+ [else
+ (maxi (rest alon))])]))
+
+;A non-empty-list-of-numbers (nelon) is
+;1. (cons n empty)
+;2. (cons n ne)
+;where n is a number and ne is a non-empty-list-of-numbers (nelon).
+;
+;extrema : predicate nelon -> number
+;Given predicate and a-lon, return the extreme value depending on the predicate.
+
+;pick-interesting : predicate list-of-numbers
+;Given predicate and a-lon, pick the interesting (extreme) number.
+
+(define (extrema predicate a-lon)
+ (cond
+ [(empty? (rest a-lon)) (first a-lon)]
+ [else (local ((define extrema-recursion (extrema predicate (rest a-lon)))
+ (define (pick-interesting predicate a-lon)
+ (cond
+ [(predicate (first a-lon) extrema-recursion) (first a-lon)]
+ [else extrema-recursion])))
+ (pick-interesting predicate a-lon))]))
+
+;mini1 : nelon -> number
+;Given a-lon, returns the minimum value.
+(define (mini1 a-lon)
+ (extrema < a-lon))
+
+;maxi1 : nelon -> number
+;Given a-lon, returns the maximum value.
+(define (maxi1 a-lon)
+ (extrema > a-lon))
+
+;(time (mini1 (list 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1)))
+;(time (maxi1 (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)))
+
+;; sort : list-of-numbers predicate -> list-of-numbers
+;; to construct a list with all items from alon in ascending or descending order
+(define (sort1 alon predicate)
+ (local ((define (sort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (insert (first alon) (sort (rest alon)))]))
+ (define (insert an alon)
+ (cond
+ [(empty? alon) (list an)]
+ [else (cond
+ [(predicate an (first alon)) (cons an alon)]
+ [else (cons (first alon) (insert an (rest alon)))])])))
+ (sort alon)))
+
+;sort-ascend : list-of-numbers
+;Given a-lon, return a list-of-numbers sorted in ascending order.
+(define (sort-ascend alon)
+ (sort1 alon <))
+
+;sort-descend : list-of-numbers
+;Given a-lon, return a list-of-numbers sorted in descending order.
+(define (sort-ascend alon)
+ (sort1 alon >))
\ No newline at end of file
blob - /dev/null
blob + a27934ca85c45b6b92bfc2d0c515a7223e7becf2 (mode 644)
--- /dev/null
+++ 19.2
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 76 0 1 #"\0"
+0 75 1 #"\0"
+0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 12 #"Courier New\0"
+0 9 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+41 #"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
+#"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 33
+#"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
+#"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
+#"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 0 1 #"\0"
+0 75 12 #"Courier New\0"
+0.0 9 90 -1 90 -1 3 -1 0 1 0 1 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255 255
+255 1 -1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 17 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+22 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 24 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 24 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+ 0 364 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 243
+(
+ #"#reader(lib \"htdp-intermediate-reader.ss\" \"lang\")((modname |19|)"
+ #" (read-case-sensitive #t) (teachpacks ((lib \"draw.ss\" \"teachpack"
+ #"\" \"htdp\"))) (htdp-settings #(#t constructor repeating-decimal #f "
+ #"#t none #f ((lib \"draw.ss\" \"teachpack\" \"htdp\")))))"
+) 0 0 4 29 1 #"\n"
+0 0 17 3 49 #";sort : (X X -> boolean) (listof X) -> (listof X)"
+0 0 68 29 1 #"\n"
+0 0 17 3 41 #";Given a-lox and op, sort the SchemeData."
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 17 3 53 #";insert : (X X -> boolean) X (listof X) -> (listof X)"
+0 0 68 29 1 #"\n"
+0 0 17 3 83
+(
+ #";Given op, an-x and a-lox, insert an-x in the proper position in a-l"
+ #"ox by using op."
+) 0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"sort-lox"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 68 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sort"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 14 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 1 #"]"
+0 0 68 29 1 #"\n"
+0 0 68 3 14 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 5 #"cons?"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"insert"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 29 1 #"\n"
+0 0 68 3 37 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 37 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sort"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 6 #")))]))"
+0 0 68 29 1 #"\n"
+0 0 68 3 10 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"insert"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"an-x"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 12 #" "
+0 0 22 3 1 #"("
+0 0 15 3 4 #"cond"
+0 0 68 29 1 #"\n"
+0 0 68 3 14 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 6 #"empty?"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"an-x"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"empty"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 14 #" "
+0 0 22 3 2 #"[("
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"an-x"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 2 #"))"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"an-x"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 2 #")]"
+0 0 68 29 1 #"\n"
+0 0 68 3 14 #" "
+0 0 22 3 1 #"["
+0 0 14 3 4 #"else"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"cons"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"first"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 1 #")"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 6 #"insert"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 14 3 4 #"an-x"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"rest"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 7 #")))])))"
+0 0 68 29 1 #"\n"
+0 0 68 3 4 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"sort"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"op"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"a-lox"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 22 3 1 #"("
+0 0 15 3 13 #"define-struct"
+0 0 68 3 1 #" "
+0 0 14 3 2 #"ir"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"name"
+0 0 68 3 1 #" "
+0 0 14 3 5 #"price"
+0 0 22 3 2 #"))"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 1 #";"
+0 0 17 3 2 #"An"
+0 0 17 3 10 #" inventory"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"record"
+0 0 17 3 2 #" ("
+0 0 17 3 2 #"ir"
+0 0 17 3 16 #") is a structure"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 1 #";"
+0 0 17 3 13 #"(make-ir n p)"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 1 #";"
+0 0 17 3 5 #"where"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"n"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"is"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"symbol"
+0 0 17 3 4 #" and"
+0 0 17 3 1 #" "
+0 0 17 3 14 #"p is a number."
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 17 3 1 #";"
+0 0 17 3 2 #"An"
+0 0 17 3 10 #" inventory"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"is"
+0 0 17 3 1 #" "
+0 0 17 3 14 #"a (listof ir)."
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 68 3 0 #""
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"<ir?"
+0 0 68 3 1 #" "
+0 0 14 3 3 #"ir1"
+0 0 68 3 1 #" "
+0 0 14 3 3 #"ir2"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"<"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 68 3 1 #" "
+0 0 14 3 3 #"ir1"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 68 3 1 #" "
+0 0 14 3 3 #"ir2"
+0 0 22 3 3 #")))"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #">ir?"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"ir1"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"ir2"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #">"
+0 0 4 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"ir1"
+0 0 22 3 1 #")"
+0 0 4 29 1 #"\n"
+0 0 4 3 5 #" "
+0 0 22 3 1 #"("
+0 0 14 3 8 #"ir-price"
+0 0 4 3 1 #" "
+0 0 14 3 3 #"ir2"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 4 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 68 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 68 3 1 #" "
+0 0 14 3 7 #"ir-list"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"list"
+0 0 68 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 2 #"Wa"
+0 0 14 3 6 #"terGun"
+0 0 68 3 1 #" "
+0 0 20 3 4 #"5.50"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 10 #"PencilCase"
+0 0 68 3 1 #" "
+0 0 20 3 4 #"1.25"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"Eraser"
+0 0 68 3 1 #" "
+0 0 20 3 4 #"0.75"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 9 #"CellPhone"
+0 0 68 3 1 #" "
+0 0 20 3 5 #"25.50"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 4 #"Doll"
+0 0 68 3 1 #" "
+0 0 20 3 4 #"8.75"
+0 0 22 3 1 #")"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 7 #"make-ir"
+0 0 68 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"Helmet"
+0 0 68 3 1 #" "
+0 0 20 3 5 #"15.75"
+0 0 22 3 3 #")))"
+0 0 68 29 1 #"\n"
+0 0 68 3 22 #" "
+0 0
blob - /dev/null
blob + 7aae772c6e7124fe530ef076dcefcf15b090086e (mode 644)
--- /dev/null
+++ 19.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;filter1 : predicate list-of-numbers
+;Filters out all numbers in a-lon where the predicate of the number evaluates to false. Retains all numbers that evaluate to true.
+(define (filter1 predicate a-lon t)
+ (cond
+ [(empty? a-lon) empty]
+ [(predicate (first a-lon) t) (cons (first a-lon)
+ (filter1 predicate (rest a-lon) t))]
+ [else (filter1 predicate (rest a-lon) t)]))
blob - /dev/null
blob + e4b7a749ef9ebb0d6d6880a653242e04852d338b (mode 644)
--- /dev/null
+++ 19.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;filter1 : predicate list-of-numbers
+;Filters out all numbers in a-lon where the predicate of the number evaluates to false. Retains all numbers that evaluate to true.
+(define (filter1 predicate a-lon t)
+ (cond
+ [(empty? a-lon) empty]
+ [(predicate (first a-lon) t) (cons (first a-lon)
+ (filter1 predicate (rest a-lon) t))]
+ [else (filter1 predicate (rest a-lon) t)]))
+
+(define-struct ir (name price))
+
+;An inventory-record (ir) is a structure
+;(make-ir n p)
+;where n is a symbol and p is a number.
+
+;An inventory is either
+;1. empty or
+;2. (cons ir inv)
+;where ir is an inventory record and inv is an inventory.
+
+;below-ir1 : number list-of-ir -> list-of-ir
+;Given n and a-loir, return a new list-of-ir with inventory records with prices below n.
+
+(define (below-ir1 n a-loir)
+ (filter1 <ir a-loir n))
+
+;<ir : ir n -> boolean
+;Given an-ir and n, determine if the price of the ir is less than n.
+
+(define (<ir an-ir n)
+ (< (ir-price an-ir) n))
+
+;Test Case
+;(below-ir1 10 (list (make-ir 'doll 8) (make-ir 'robot 12)))
+
+#| Hand Evaluation
+
+(below-ir1 10 (list (make-ir 'doll 8) (make-ir 'robot 12)))
+(filter1 <ir (list (make-ir 'doll 8) (make-ir 'robot 12)) 10)
+(cond
+ [false empty]
+ [(<ir (first (make-ir 'doll 8)) 10) (cons (first (list (make-ir 'doll 8) (make-ir 'robot 12)))
+ (filter1 predicate (rest (list (make-ir 'doll 8) (make-ir 'robot 12))) 10))]
+ [else (filter1 predicate (rest (list (make-ir 'doll 8) (make-ir 'robot 12))) 10)])
+
+(<ir (first (make-ir 'doll 8)) 10)
+(< 8 10)
+true
+
+(cond
+ [false empty]
+ [true (cons (make-ir 'doll 8)
+ (filter1 <ir (list (make-ir 'robot 12)) 10))]
+ [else (filter1 <ir (rest (list (make-ir 'doll 8) (make-ir 'robot 12))) 10)])
+
+(cons (make-ir 'doll 8)
+ (filter1 <ir (list (make-ir 'robot 12)) 10))
+
+(cond
+ [false empty]
+ [false (cons (first a-lon)
+ (filter1 predicate (rest a-lon) t))]
+ [else (filter1 <ir (empty) 10)])
+
+(cons (make-ir 'doll 8)
+ empty)
+
+|#
+
+;find : list-of-ir symbol -> boolean
+;Determine if a-loir contains an ir with the name a-symbol.
+
+(define (find a-symbol a-loir)
+ (cons? (filter1 eq-ir? a-loir a-symbol)))
+
+;eq-ir? : ir a-symbol
+;Determine if an-ir has a-symbol for its name.
+
+(define (eq-ir? an-ir a-symbol)
+ (symbol=? (ir-name an-ir) a-symbol))
+
+(find 'doll (list (make-ir 'doll 8) (make-ir 'robot 12) (make-ir 'doll 13)))
+
+(cons? (filter1 eq-ir? (list (make-ir 'doll 8) (make-ir 'robot 12) (make-ir 'doll 13)) 'doll))
+
+(filter1 eq-ir? (list (make-ir 'doll 8) (make-ir 'robot 12) (make-ir 'doll 13)) 'doll)
+
+(cons? (cons (first a-lon)
+ (filter1 eq-ir? (rest a-lon) t)))
+
+true
blob - /dev/null
blob + c1d8b9120ee3ad4e31f6ab5c7b6b9fa0ad2c3e37 (mode 644)
--- /dev/null
+++ 19.2.2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 577916e8f58c405e2b80eb4265b36e23aa8285b0 (mode 644)
--- /dev/null
+++ 19.2.2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;sort : (X X -> boolean) (listof X) -> (listof X)
+;Given a-lox and op, sort the SchemeData.
+
+;insert : (X X -> boolean) X (listof X) -> (listof X)
+;Given op, an-x and a-lox, insert an-x in the proper position in a-lox by using op.
+(define (sort-lox op a-lox)
+ (local ((define (sort op a-lox)
+ (cond
+ [(empty? a-lox) empty]
+ [(cons? a-lox) (insert op
+ (first a-lox)
+ (sort op (rest a-lox)))]))
+ (define (insert op an-x a-lox)
+ (cond
+ [(empty? a-lox) (cons an-x empty)]
+ [(op an-x (first a-lox)) (cons an-x a-lox)]
+ [else (cons (first a-lox) (insert op an-x (rest a-lox)))])))
+ (sort op a-lox)))
+
+(define-struct ir (name price))
+
+;An inventory record (ir) is a structure
+;(make-ir n p)
+;where n is a symbol and p is a number.
+
+;An inventory is a (listof ir).
+
+;<ir? : ir ir -> boolean
+;Given ir1 and ir2, returns true if the price of ir1 is less than that of ir2.
+(define (<ir? ir1 ir2)
+ (< (ir-price ir1)
+ (ir-price ir2)))
+
+;>ir? : ir ir -> boolean
+;Given ir1 and ir2, returns true if the price of ir1 is less than that of ir2.
+
+(define (>ir? ir1 ir2)
+ (> (ir-price ir1)
+ (ir-price ir2)))
+
+
+
+(define ir-list (list (make-ir 'WaterGun 5.50)
+ (make-ir 'PencilCase 1.25)
+ (make-ir 'Eraser 0.75)
+ (make-ir 'CellPhone 25.50)
+ (make-ir 'Doll 8.75)
+ (make-ir 'Helmet 15.75)))
+
\ No newline at end of file
blob - /dev/null
blob + ce3febd7d29c5957cb31b8de36d3f5ca4ba1fcf0 (mode 644)
--- /dev/null
+++ 19.2.3-19.2.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.3-19.2.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct pairs (left right))
+
+;Pairs are a structure
+;(make-pairs l r)
+;where l is an X and r is a Y.
+;
+;Some concrete examples of this abstract class of data are:
+;(listof (make-pairs number number))
+;(listof (make-pairs 5 6))
+;(listof (make-pairs symbol number))
+;(listof (make-pairs 'words 5))
+;(listof (make-pairs symbol symbol))
+;(listof (make-pairs 'leftside 'rightside))
+
+;lefts : (listof (make-pairs X Y)) -> (listof X)
+;Given alopxy, return only the left side of the pairs as a (listof X).
+
+(define (lefts alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (pairs-left (first alopxy)) (lefts (rest alopxy)))]))
+
+(define list1 (list (make-pairs 5 6)
+ (make-pairs 'false false)
+ (make-pairs true 'heyThere)
+ (make-pairs (make-pairs 5 6) (make-pairs 'hey 'me))
+ (make-pairs '(5 1 4 2) '(hey joe its me))
+ (make-pairs 1 'word)
+ (make-pairs 'last 'one)))
+
+;rights : (listof (make-pairs X Y)) -> (listof X)
+;Given alopxy, return only the right side of the pairs as a (listof X).
+
+(define (rights alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (pairs-right (first alopxy)) (rights (rest alopxy)))]))
+
+;side : ((make-pairs X Y) -> X or Y) (listof (make-pairs X Y)) -> (listof X)
+;Given which-side and alopxy, return only one side of the pairs as a (listof X). which-side should be either pairs-left or pairs-right.
+
+(define (side which-side alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (which-side (first alopxy)) (side which-side (rest alopxy)))]))
+
+(equal? (lefts list1) (side pairs-left list1))
+(equal? (rights list1) (side pairs-right list1))
+
blob - /dev/null
blob + d2caf9da4998a898b4f78d8665765dd2ee72e5e8 (mode 644)
--- /dev/null
+++ 19.2.3-19.2.4.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.3-19.2.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct pairs (left right))
+
+;Pairs are a structure
+;(make-pairs l r)
+;where l is an X and r is a Y.
+;
+;Some concrete examples of this abstract class of data are:
+;(listof (make-pairs number number))
+;(listof (make-pairs 5 6))
+;(listof (make-pairs symbol number))
+;(listof (make-pairs 'words 5))
+;(listof (make-pairs symbol symbol))
+;(listof (make-pairs 'leftside 'rightside))
+
+;lefts : (listof (make-pairs X Y)) -> (listof X)
+;Given alopxy, return only the left side of the pairs as a (listof X).
+
+(define (lefts alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (pairs-left (first alopxy)) (lefts (rest alopxy)))]))
+
+(define list1 (list (make-pairs 5 6)
+ (make-pairs 'false false)
+ (make-pairs true 'heyThere)
+ (make-pairs (make-pairs 5 6) (make-pairs 'hey 'me))
+ (make-pairs '(5 1 4 2) '(hey joe its me))
+ (make-pairs 1 'word)
+ (make-pairs 'last 'one)))
+
+;rights : (listof (make-pairs X Y)) -> (listof X)
+;Given alopxy, return only the right side of the pairs as a (listof X).
+
+(define (rights alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (pairs-right (first alopxy)) (rights (rest alopxy)))]))
+
+;side : ((make-pairs X Y) -> X or Y) (listof (make-pairs X Y)) -> (listof X)
+;Given which-side and alopxy, return only one side of the pairs as a (listof X). which-side should be either pairs-left or pairs-right.
+
+(define (side which-side alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (which-side (first alopxy)) (side which-side (rest alopxy)))]))
+
+(equal? (lefts list1) (side pairs-left list1))
+(equal? (rights list1) (side pairs-right list1))
+
+;A non-empty (listof ITEMS) (neloi) is either
+;1. (cons s empty) or
+;2. (cons s n)
+;where s is an ITEM and n is a non-empty (listof ITEMS) (neloi).
+;
+;last : neloi -> ITEM
+(define (last a-neloi)
+ (cond
+ [(empty? (rest a-neloi)) (first a-neloi)]
+ [(cons? (rest a-neloi)) (last (rest a-neloi))]))
+
+(last (list (make-posn 'dollars 5.00)
+ (make-posn 'Superman 99.55)
+ 'Invincible
+ 25
+ empty
+ false
+ 'true
+ '(5 1 2 3)
+ (make-posn 5 10)))
\ No newline at end of file
blob - /dev/null
blob + 3059a75d5dee6f0fa00e954bbbb4de027c2fd2b8 (mode 644)
--- /dev/null
+++ 19.2.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 97957af3b060f321478ac2c122e169f64926e7b1 (mode 644)
--- /dev/null
+++ 19.2.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 19.2.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define-struct pairs (left right))
+
+;Pairs are a structure
+;(make-pairs l r)
+;where l is an X and r is a Y.
+;
+;Some concrete examples of this abstract class of data are:
+;(listof (make-pairs number number))
+;(listof (make-pairs 5 6))
+;(listof (make-pairs symbol number))
+;(listof (make-pairs 'words 5))
+;(listof (make-pairs symbol symbol))
+;(listof (make-pairs 'leftside 'rightside))
+
+;lefts : (listof (make-pairs X Y)) -> (listof X)
+;Given alopxy, return only the left side of the pairs as a (listof X).
+
+(define (lefts alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (pairs-left (first alopxy)) (lefts (rest alopxy)))]))
+
+(define list1 (list (make-pairs 5 6)
+ (make-pairs 'false false)
+ (make-pairs true 'heyThere)
+ (make-pairs (make-pairs 5 6) (make-pairs 'hey 'me))
+ (make-pairs '(5 1 4 2) '(hey joe its me))
+ (make-pairs 1 'word)
+ (make-pairs 'last 'one)))
+
+;rights : (listof (make-pairs X Y)) -> (listof X)
+;Given alopxy, return only the right side of the pairs as a (listof X).
+
+(define (rights alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (pairs-right (first alopxy)) (rights (rest alopxy)))]))
+
+;side : ((make-pairs X Y) -> X or Y) (listof (make-pairs X Y)) -> (listof X)
+;Given which-side and alopxy, return only one side of the pairs as a (listof X). which-side should be either pairs-left or pairs-right.
+
+(define (side which-side alopxy)
+ (cond
+ [(empty? alopxy) empty]
+ [(cons? alopxy) (cons (which-side (first alopxy)) (side which-side (rest alopxy)))]))
+
+(equal? (lefts list1) (side pairs-left list1))
+(equal? (rights list1) (side pairs-right list1))
\ No newline at end of file
blob - /dev/null
blob + 1e89272d02fd63d6dfe3df76ede8f70073e3b1cd (mode 644)
--- /dev/null
+++ 20.1.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.1.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(define (f x) x)
\ No newline at end of file
blob - /dev/null
blob + 839aa3558cda73e2b1c26535e82136e137d1af15 (mode 644)
--- /dev/null
+++ 20.1.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.1.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+(define (f x) x)
+
+(cons f empty)
+
+(f f)
+
+(cons f (cons 10 (cons (f 10) empty)))
+
+|#
+
+(define (f x) f)
+
+#|
+Exercise 20.1.3. Develop a-function=?. The function determines whether two functions from numbers to numbers produce the same results for 1.2, 3, and -5.7.
+
+Can we hope to define function=?, which determines whether two functions (from numbers to numbers) are equal? Solution
+|#
+
+;a-function=? (number -> number) (number -> number) (listof ITEM) -> boolean
+;Determines whether func1 and func2 are equal by evaluating applying the functions to aloi (listof ITEM).
+
+(define (a-function=? func1 func2 aloi)
+ (cond
+ [(empty? aloi) true]
+ [(cons? aloi) (and (equal? (func1 (first aloi))
+ (func2 (first aloi)))
+ (a-function=? func1 func2 (rest aloi)))]))
+
+(define list1 '(1.2 3 -5.7))
+
+;function-1: number -> number
+;Returns 0 (ie, f(x) = 0).
+(define (function-1 x)
+ 0)
+
+;function-2: number -> number
+;f(x) = (x-1.2)*(x-3)(x+5.7)
+
+(define (function-2 x)
+ (* (- x 1.2)
+ (- x 3)
+ (+ x 5.7)))
+
+;function-3 : number -> number
+;f(x) = x.
+
+(define (function-3 x)
+ x)
+
+(a-function=? function-1 function-2 list1)
+(not (a-function=? function-1 function-3 list1))
+(not (a-function=? function-2 function-3 list1))
+
+;sort : (listof numbers) (number number -> boolean) -> (listof numbers)
+
+;map : (number -> number) (listof numbers) -> (listof numbers)
+
+;project : (listof (listof symbols)) ((listof symbols) -> symbols) -> symbols
\ No newline at end of file
blob - /dev/null
blob + 52f091237ce204212438f4a566d86721bb296274 (mode 644)
--- /dev/null
+++ 20.2.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.2.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+filter1 : (X Y -> boolean) (listof X) Y -> (listof X)
+
+(define (filter1 rel-op alon t)
+ (cond
+ [(empty? alon) empty]
+ [(rel-op (first alon) t)
+ (cons (first alon)
+ (filter1 rel-op (rest alon) t))]
+ [else
+ (filter1 rel-op (rest alon) t)]))
\ No newline at end of file
blob - /dev/null
blob + afebb9d35495d23d8d4290dec475bac920bc350b (mode 644)
--- /dev/null
+++ 20.2.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.2.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+Exercise 20.2.3. Use filter1 to develop a function that consumes a list of symbols and extracts all those that are not equal to 'car. Give filter1's corresponding contract.
+
+|#
+
+;filter1 : (X Y -> boolean) (listof X) Y -> (listof X)
+
+(define (filter1 rel-op alox y)
+ (cond
+ [(empty? alox) empty]
+ [(rel-op (first alox) y)
+ (cons (first alox)
+ (filter1 rel-op (rest alox) y))]
+ [else
+ (filter1 rel-op (rest alox) y)]))
+
+;not=? : Y Y -> boolean
+;Given item1 and item2, return true if the two are not equal, false if they are.
+
+(define (not=? item1 item2)
+ (not (equal? item1 item2)))
+
+(define list1 '(automobile
+ vehicle
+ motorcycle
+ van
+ truck
+ car
+ sedan
+ car
+ pick-up
+ train))
+
+(filter1 not=? list1 'car)
+(filter1 not=? list1 'automobile)
+
blob - /dev/null
blob + e17da5461e66fba1941e1e0253dca9ff7453bcd6 (mode 644)
--- /dev/null
+++ 20.2.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.2.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+Exercise 20.2.4. Formulate general contracts for the following functions:
+
+sort, which consumes a list of items and a function that consumes two items (from the list) and produces a boolean; it produces a list of items.
+
+map, which consumes a function from list items to Xs and a list; it produces a list of Xs.
+
+project, which consumes a list of lists and a function from lists to Xs; it produces a list of Xs.
+
+Compare with exercise 20.2.2. Solution
+
+;sort : (listof numbers) (number number -> boolean) -> (listof numbers)
+
+;map : (number -> number) (listof numbers) -> (listof numbers)
+
+;project : (listof (listof symbols)) ((listof symbols) -> symbols) -> symbols
+
blob - /dev/null
blob + 02c3c85807f3e01b20c389ca077a3facfd458839 (mode 644)
--- /dev/null
+++ 20.2.4.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.2.4) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+Exercise 20.2.4. Formulate general contracts for the following functions:
+
+sort, which consumes a list of items and a function that consumes two items (from the list) and produces a boolean; it produces a list of items.
+
+map, which consumes a function from list items to Xs and a list; it produces a list of Xs.
+
+project, which consumes a list of lists and a function from lists to Xs; it produces a list of Xs.
+
+Compare with exercise 20.2.2. Solution
+
+;sort : (listof X) (X X -> boolean) -> (listof X)
+;
+;map : ((listof X) -> X) (listof Y) -> (listof X)
+;
+;project : (listof (listof X)) ((listof X) -> X) -> (listof X)
+
+;sort : (listof numbers) (number number -> boolean) -> (listof numbers)
+
+;map : (number -> number) (listof numbers) -> (listof numbers)
+
+;project : (listof (listof symbols)) ((listof symbols) -> symbols) -> symbols
+
blob - /dev/null
blob + a420081cfa4190ae2f3e34046285c69f02cc2fe6 (mode 644)
--- /dev/null
+++ 21.1
+#reader(lib"read.ss""wxme")WXME0108 ##
+#|
+ This file is in plt scheme editor format.
+ Open this file in dr-scheme version 4.2 or later to read it.
+
+ Most likely, it was created by saving a program in DrScheme,
+ and it probably contains a program with non-text elements
+ (such as images or comment boxes).
+
+ http://www.plt-scheme.org
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wxmedia\0"
+4 1 8 #"wximage\0"
+2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 56
+#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 18 #"java-comment-box%\0"
+1 0 23 #"java-interactions-box%\0"
+1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 15 #"test-case-box%\0"
+2 0 1 6 #"wxloc\0"
+ 0 0 70 0 1 #"\0"
+0 75 1 #"\0"
+0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 12 #"Courier New\0"
+0 18 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 150 0 150 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 175 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 37 #"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 38 #"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 37 #"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 39 #"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 41 128 38 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 132 60 36 0
+0 0 -1 -1 2 42 #"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 132 60 36 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 36 #"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 36 #"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 81 112 203 0
+0 0 -1 -1 2 38 #"drscheme:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 81 112 203 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 68 0 203 0 0
+0 -1 -1 2 31 #"drscheme:check-syntax:imported\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 68 0 203 0 0
+0 -1 -1 2 41 #"profj:syntax-colors:scheme:block-comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:keyword\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 2 37 #"profj:syntax-colors:scheme:prim-type\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 2 38 #"profj:syntax-colors:scheme:identifier\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 38 38 128 0
+0 0 -1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 34 #"profj:syntax-colors:scheme:string\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:literal\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 34 139 34 0
+0 0 -1 -1 2 35 #"profj:syntax-colors:scheme:comment\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 194 116 31 0
+0 0 -1 -1 2 33 #"profj:syntax-colors:scheme:error\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 255 0 0 0 0
+0 -1 -1 2 35 #"profj:syntax-colors:scheme:default\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 37 #"profj:syntax-colors:scheme:uncovered\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 35 #"profj:syntax-colors:scheme:covered\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0.0 0.0 0.0 1.0 1.0 1.0 139 0 139 0
+0 0 -1 -1 4 1 #"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 8 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
+#"drscheme:text:ports err\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 22 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 15 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 14 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 20 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 22 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+15 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+14 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+20 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+17 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 255 255 255 -1 -1
+ 0 361 0 4 3 85
+(
+ #";; The first three lines of this file were inserted by DrScheme. The"
+ #"y record metadata"
+) 0 0 4 29 1 #"\n"
+0 0 4 3 85
+(
+ #";; about the language level of this file in a form that our tools ca"
+ #"n easily process."
+) 0 0 4 29 1 #"\n"
+0 0 4 3 243
+(
+ #"#reader(lib \"htdp-intermediate-reader.ss\" \"lang\")((modname |21|)"
+ #" (read-case-sensitive #t) (teachpacks ((lib \"draw.ss\" \"teachpack"
+ #"\" \"htdp\"))) (htdp-settings #(#t constructor repeating-decimal #f "
+ #"#t none #f ((lib \"draw.ss\" \"teachpack\" \"htdp\")))))"
+) 0 0 4 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"f"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"build-list"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"4"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"f"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 1 #")"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"build-list"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"4"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"f"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 10 #" "
+0 0 22 3 1 #"("
+0 0 14 3 4 #"expt"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"10"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 66 3 1 #" "
+0 0 20 3 2 #"-1"
+0 0 66 3 1 #" "
+0 0 66 29 1 #"\n"
+0 0 66 3 22 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"x"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 5 #")))))"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"build-list"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"4"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 17 3 6 #";evens"
+0 0 17 3 30 #" : N [>=0] -> (listof N [>=0])"
+0 0 66 29 1 #"\n"
+0 0 17 3 6 #";Given"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"n"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 5 #"evens"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"creates"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"the"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"first"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"n"
+0 0 17 3 14 #" even numbers."
+0 0 66 29 1 #"\n"
+0 0 66 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"evens"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 2 #" "
+0 0 22 3 1 #"("
+0 0 15 3 5 #"local"
+0 0 66 3 1 #" "
+0 0 22 3 2 #"(("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"evens"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 12 #" "
+0 0 22 3 1 #"("
+0 0 14 3 10 #"build-list"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #"))"
+0 0 66 29 1 #"\n"
+0 0 66 3 10 #" "
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 66 3 1 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"f"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 1 #")"
+0 0 66 29 1 #"\n"
+0 0 66 3 12 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"*"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"2"
+0 0 66 29 1 #"\n"
+0 0 66 3 15 #" "
+0 0 22 3 1 #"("
+0 0 14 3 1 #"+"
+0 0 66 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 4 #"))))"
+0 0 66 29 1 #"\n"
+0 0 66 3 4 #" "
+0 0 22 3 1 #"("
+0 0 14 3 5 #"evens"
+0 0 66 3 1 #" "
+0 0 14 3 1 #"n"
+0 0 22 3 3 #")))"
+0 0 66 29 1 #"\n"
+0 0 66 3 0 #""
+0 0 66 29 1 #"\n"
+0 0 66 3 0 #""
+0 0 66 29 1 #"\n"
+0 0 17 3 1 #"#"
+0 0 17 3 1 #"|"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 8 #"Exercise"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"21.2.1."
+0 0 17 3 3 #" "
+0 0 17 3 3 #"Use"
+0 0 17 3 1 #" "
+0 0 17 3 10 #"build-list"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 3 #"to "
+0 0 17 3 6 #"define"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"tabulate"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"from"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"exercise"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"21.1.1"
+0 0 17 3 5 #"; and"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 3 #"to "
+0 0 17 3 6 #"define"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"diagonal"
+0 0 17 3 1 #","
+0 0 17 3 1 #" "
+0 0 17 3 6 #"which "
+0 0 17 3 8 #"consumes"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"natural"
+0 0 17 3 1 #" "
+0 0 17 3 6 #"number"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"n"
+0 0 17 3 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"creates"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"a"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"lists"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"of"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 11 1 #" "
+0 0 17 3 3 #"and"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"1."
+0 0 17 3 1 #" "
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 8 #"Example:"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 1 #"("
+0 0 17 3 6 #"equal?"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 8 #"diagonal"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"3"
+0 0 17 3 1 #")"
+0 0 17 29 1 #"\n"
+0 0 17 3 8 #" "
+0 0 17 3 1 #"("
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 29 1 #"\n"
+0 0 17 3 9 #" "
+0 0 17 3 1 #"("
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"1"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #")"
+0 0 17 29 1 #"\n"
+0 0 17 3 9 #" "
+0 0 17 3 1 #"("
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"1"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #")"
+0 0 17 29 1 #"\n"
+0 0 17 3 9 #" "
+0 0 17 3 1 #"("
+0 0 17 3 4 #"list"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"0"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"1"
+0 0 17 3 3 #")))"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 3 #"Use"
+0 0 17 3 1 #" "
+0 0 17 3 5 #"local"
+0 0 17 3 1 #" "
+0 0 17 3 2 #"if"
+0 0 17 3 1 #" "
+0 0 17 3 8 #"function"
+0 0 17 3 1 #" "
+0 0 17 3 11 #"definitions"
+0 0 17 3 1 #" "
+0 0 17 3 7 #"require"
+0 0 17 3 1 #" "
+0 0 17 3 9 #"auxiliary"
+0 0 17 3 1 #" "
+0 0 17 3 10 #"functions."
+0 0 17 3 4 #" "
+0 0 17 3 8 #"Solution"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 44 #";; build-list : N (N -> X) -> (listof X)"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 44 #";; to construct (list (f 0) ... (f (- n 1)))"
+0 0 17 29 1 #"\n"
+0 0 17 3 0 #""
+0 0 17 3 1 #"("
+0 0 17 3 6 #"define"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"("
+0 0 17 3 10 #"build-list"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"n"
+0 0 17 3 1 #" "
+0 0 17 3 1 #"f"
+0 0 17 3 1 #")"
+0 0 17 3 1 #" "
+0 0 17 3 4 #"...)"
+0 0 17 29 1 #"\n"
+0 0 17 29 1 #"\n"
+0 0 17 3 2 #"|#"
+0 0
blob - /dev/null
blob + 98ba7e4ea7816b2fdd6cb04e29e05cda0123a621 (mode 644)
--- /dev/null
+++ 21.1.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+Exercise 21.1.1. Define tabulate, which is the abstraction of the following two functions:
+
+;; tabulate-sin : number -> lon
+;; to tabulate sin between n
+;; and 0 (inclusive) in a list
+(define (tabulate-sin n)
+ (cond
+ [(= n 0) (list (sin 0))]
+ [else
+ (cons (sin n)
+ (tabulate-sin (sub1 n)))]))
+
+;; tabulate-sqrt : number -> lon
+;; to tabulate sqrt between n
+;; and 0 (inclusive) in a list
+(define (tabulate-sqrt n)
+ (cond
+ [(= n 0) (list (sqrt 0))]
+ [else
+ (cons (sqrt n)
+ (tabulate-sqrt (sub1 n)))]))
+Be sure to define the two functions in terms of tabulate. Also use tabulate to define a tabulation function for sqr and tan. What would be a good, general contract? Solution
\ No newline at end of file
blob - /dev/null
blob + 0eb00219b73b29dbd3e33813580648bc2e0edcab (mode 644)
--- /dev/null
+++ 21.1.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+Exercise 21.1.1. Define tabulate, which is the abstraction of the following two functions:
+
+;; tabulate-sin : number -> lon
+;; to tabulate sin between n
+;; and 0 (inclusive) in a list
+(define (tabulate-sin n)
+ (cond
+ [(= n 0) (list (sin 0))]
+ [else
+ (cons (sin n)
+ (tabulate-sin (sub1 n)))]))
+
+;; tabulate-sqrt : number -> lon
+;; to tabulate sqrt between n
+;; and 0 (inclusive) in a list
+(define (tabulate-sqrt n)
+ (cond
+ [(= n 0) (list (sqrt 0))]
+ [else
+ (cons (sqrt n)
+ (tabulate-sqrt (sub1 n)))]))
+
+Be sure to define the two functions in terms of tabulate. Also use tabulate to define a tabulation function for sqr and tan. What would be a good, general contract? Solution
+
+|#
+
+;tabulate : (number -> X) number -> (listof X)
+;Given op and n, return the value of (op i) where i is an integer, for integers from n to 0, inclusive.
+
+(define (tabulate op n)
+ (cond
+ [(= n 0) (list (op 0))]
+ [else (cons (op n)
+ (tabulate op (sub1 n)))]))
+
+;tabulate-sin : number -> (listof number)
+;Tabulate the sin of all integers from n to 0 inclusive.
+(define (tabulate-sin n)
+ (tabulate sin n))
+
+;tabulate-sqrt : number -> (listof number)
+;Tabulate the sqrt of all integers from n to 0 inclusive.
+(define (tabulate-sqrt n)
+ (tabulate sqrt n))
\ No newline at end of file
blob - /dev/null
blob + f65fb2e33b2d7cf1ec524862048adf69c20f97c3 (mode 644)
--- /dev/null
+++ 21.1.2-2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+map : (X -> Y) (listof X) -> (listof Y)
+Given f and alox, map each element of type X from alox to an element in type Y according to the function f to return a (listof Y).
+
+(define (map alox)
+ (fold consf alox empty))
+
+consf : X (listof Y) -> (listof Y)
+Given f, an-x, and a-loy, map an-x to an element Y according to f and then append to the beginning of a-loy.
+(define (consf)
+ (
+
+
+(define (fold op alox base)
+ (cond
+ [(empty? alox) base]
+ [else (op (first alox) (fold op (rest alox) base))]))
+
blob - /dev/null
blob + e4bb9a8a3bcb271c8e558cfa56d7d7e398336b2e (mode 644)
--- /dev/null
+++ 21.1.2-2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+;fold : (X Y -> Y) (listof X) Y -> Y
+;Given op and alox, return the value of op applied cumulatively on every value in alox. The value base specifies a value that is the base from which fold operates upon.
+
+(define (fold op alox base)
+ (cond
+ [(empty? alox) base]
+ [else (op (first alox) (fold op (rest alox) base))]))
+
+;op : (X Y -> Y)
+;alox : (listof X)
+;base : Y
+;(first alox) : X
+;(rest alox) : (listof X)
+
+;map1 : (listof X) -> (listof Y)
+;Given alox, map1 each element of type X from alox to an element in type Y according to the function f to return a (listof Y).
+
+(define (map1 alox)
+ (fold consf alox empty))
+
+;Test
+;(map1 consf alox)
+
+;(consf (first alox) (fold consf (rest alox) empty))
+;(cons (f (first alox)) (fold f (rest alox) empty))
+;(f X)
+
+;consf : X Y -> Y
+;Given x, y, map1 x to an element Y and then append to the beginning of y.
+(define (consf x y)
+ (cons (f x) y))
+
+;f : number -> number
+;Add 5.
+(define (f x)
+ (+ x 5))
+
+#|
+(define (map1 f lon)
+ (cond
+ [(empty? lon) empty]
+ [else (cons (f (first lon))
+ (map1 f (rest lon)))]))
+
+|#
+
+(equal? (map1 '(1 3 2 5 1 4 0 2 6 8 6 9 2 3 4 5 1 8 2))
+ (list 6 8 7 10 6 9 5 7 11 13 11 14 7 8 9 10 6 13 7))
\ No newline at end of file
blob - /dev/null
blob + 64f2ba5649b61472b7bf0ceffc421330365888fb (mode 644)
--- /dev/null
+++ 21.1.2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+Exercise 21.1.1. Define tabulate, which is the abstraction of the following two functions:
+
+;; tabulate-sin : number -> lon
+;; to tabulate sin between n
+;; and 0 (inclusive) in a list
+(define (tabulate-sin n)
+ (cond
+ [(= n 0) (list (sin 0))]
+ [else
+ (cons (sin n)
+ (tabulate-sin (sub1 n)))]))
+
+;; tabulate-sqrt : number -> lon
+;; to tabulate sqrt between n
+;; and 0 (inclusive) in a list
+(define (tabulate-sqrt n)
+ (cond
+ [(= n 0) (list (sqrt 0))]
+ [else
+ (cons (sqrt n)
+ (tabulate-sqrt (sub1 n)))]))
+
+Be sure to define the two functions in terms of tabulate. Also use tabulate to define a tabulation function for sqr and tan. What would be a good, general contract? Solution
+
+|#
+
+;tabulate : (number -> X) number -> (listof X)
+;Given op and n, return the value of (op i) where i is an integer, for integers from n to 0, inclusive.
+
+(define (tabulate op n)
+ (cond
+ [(= n 0) (list (op 0))]
+ [else (cons (op n)
+ (tabulate op (sub1 n)))]))
+
+;tabulate-sin : number -> (listof number)
+;Tabulate the sin of all integers from n to 0 inclusive.
+(define (tabulate-sin n)
+ (tabulate sin n))
+
+;tabulate-sqrt : number -> (listof number)
+;Tabulate the sqrt of all integers from n to 0 inclusive.
+(define (tabulate-sqrt n)
+ (tabulate sqrt n))
\ No newline at end of file
blob - /dev/null
blob + 9eea2c195bed14f37d29f446ce2194d91d9f3c61 (mode 644)
--- /dev/null
+++ 21.1.2.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+Exercise 21.1.2. Define fold, which is the abstraction of the following two functions:
+
+;; sum : (listof number) -> number
+;; to compute the sum of
+;; the numbers on alon
+(define (sum alon)
+ (cond
+ [(empty? alon) 0]
+ [else (+ (first alon)
+ (sum (rest alon)))]))
+
+;; product : (listof number) -> number
+;; to compute the product of
+;; the numbers on alon
+(define (product alon)
+ (cond
+ [(empty? alon) 1]
+ [else (* (first alon)
+ (product (rest alon)))]))
+Don't forget to test fold.
+After fold is defined and tested, use it to define append, which juxtaposes the items of two lists or, equivalently, replaces empty at the end of the first list with the second list:
+
+(equal? (append (list 1 2 3) (list 4 5 6 7 8))
+ (list 1 2 3 4 5 6 7 8))
+Finally, define map using fold.
+
+Compare the four examples to formulate a contract. Solution
+
+|#
+
+;fold : (X Y -> Y) (listof X) Y -> Y
+;Given op and alox, return the value of op applied cumulatively on every value in alox. The value base specifies a value that is the base from which fold operates upon.
+
+(define (fold op alox base)
+ (cond
+ [(empty? alox) base]
+ [else (op (first alox) (fold op (rest alox) base))]))
+
+;sum : (listof number) -> number
+;Given alon, adds all the numbers in the list.
+(define (sum alon)
+ (fold + alon 0))
+
+;product : (listof number) -> number
+;Given alon, multiplies all the numbers in the list.
+(define (product alon)
+ (fold * alon 1))
+
+;append : (listof X) (listof Y)
+;Given list1 and list2, append list2 to the end of list1.
+(define (append! list1 list2)
+ (fold cons list1 list2))
+
+(append! '(Hi my name is Joe) '(Hi my name is Aaron))
+
blob - /dev/null
blob + 2516d4eb429b7848f04874529af4737b28429287 (mode 644)
--- /dev/null
+++ 21.1.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+Exercise 21.1.3. Define natural-f, which is the abstraction of the following two functions:
+
+;; copy : N X -> (listof X)
+;; to create a list that contains
+;; obj n times
+(define (copy n obj)
+ (cond
+ [(zero? n) empty]
+ [else (cons obj
+ (copy (sub1 n) obj))]))
+
+;; n-adder : N number -> number
+;; to add n to x using
+;; (+ 1 ...) only
+(define (n-adder n x)
+ (cond
+ [(zero? n) x]
+ [else (+ 1
+ (n-adder (sub1 n) x))]))
+Don't forget to test natural-f. Also use natural-f to define n-multiplier, which consumes n and x and produces n times x with additions only. Use the examples to formulate a contract.
+Hint: The two function differ more than, say, the functions sum and product in exercise 21.1.2. In particular, the base case in one instance is a argument of the function, where in the other it is just a constant value. Solution
\ No newline at end of file
blob - /dev/null
blob + bf9dc286ff22e141632ee10a00336077d0aa5ad2 (mode 644)
--- /dev/null
+++ 21.1.3.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+Exercise 21.1.3. Define natural-f, which is the abstraction of the following two functions:
+
+;; copy : N X -> (listof X)
+;; to create a list that contains
+;; obj n times
+(define (copy n obj)
+ (cond
+ [(zero? n) empty]
+ [else (cons obj
+ (copy (sub1 n) obj))]))
+
+;; n-adder : N number -> number
+;; to add n to x using
+;; (+ 1 ...) only
+(define (n-adder n x)
+ (cond
+ [(zero? n) x]
+ [else (+ 1
+ (n-adder (sub1 n) x))]))
+
+Don't forget to test natural-f. Also use natural-f to define n-multiplier, which consumes n and x and produces n times x with additions only. Use the examples to formulate a contract.
+Hint: The two function differ more than, say, the functions sum and product in exercise 21.1.2. In particular, the base case in one instance is a argument of the function, where in the other it is just a constant value. Solution
+
+|#
+
+;natural-f : (X Z -> Z) N[>=0] X Y -> Z
+;Given a function f, natural number n (N[>=0]), data (X), and base (Y), recursively use f on x, n times.
+(define (natural-f f n x base)
+ (cond
+ [(zero? n) base]
+ [else (f x (natural-f f (sub1 n) x base))]))
+
+;; copy : N X -> (listof X)
+;; to create a list that contains
+;; obj n times
+
+(define (copy n obj)
+ (natural-f cons n obj empty))
+
+;; n-adder : N number -> number
+;; to add n to x using
+;; (+ 1 ...) only
+
+(define (n-adder n x)
+ (natural-f + n 1 x))
+
+;Don't forget to test natural-f. Also use natural-f to define n-multiplier, which consumes n and x and produces n times x with additions only. Use the examples to formulate a contract.
+;
+;n-multiplier : N number -> number
+;Multiply x by n with additions only.
+
+(define (n-multiplier n x)
+ (natural-f + n x 0))
+
+(equal? empty (copy 0 'hi))
+(equal? '(hi hi hi) (copy 3 'hi))
+
+(equal? 35 (n-adder 10 25))
+(equal? 57 (n-adder 23 34))
+(equal? 32 (n-multiplier 8 4))
\ No newline at end of file
blob - /dev/null
blob + d0abdd7282fca1daee834b314da4ccbe089c1f80 (mode 644)
--- /dev/null
+++ 21.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+#|
+
+Exercise 21.1.3. Define natural-f, which is the abstraction of the following two functions:
+
+;; copy : N X -> (listof X)
+;; to create a list that contains
+;; obj n times
+(define (copy n obj)
+ (cond
+ [(zero? n) empty]
+ [else (cons obj
+ (copy (sub1 n) obj))]))
+
+;; n-adder : N number -> number
+;; to add n to x using
+;; (+ 1 ...) only
+(define (n-adder n x)
+ (cond
+ [(zero? n) x]
+ [else (+ 1
+ (n-adder (sub1 n) x))]))
+
+Don't forget to test natural-f. Also use natural-f to define n-multiplier, which consumes n and x and produces n times x with additions only. Use the examples to formulate a contract.
+Hint: The two function differ more than, say, the functions sum and product in exercise 21.1.2. In particular, the base case in one instance is a argument of the function, where in the other it is just a constant value. Solution
+
+|#
+
+;natural-f : (X Z -> Z) N[>=0] X Y -> Z
+;Given a function f, natural number n (N[>=0]), data (X), and base (Y), recursively use f on x, n times.
+(define (natural-f f n x base)
+ (cond
+ [(zero? n) base]
+ [else (f x (natural-f f (sub1 n) x base))]))
+
+;; copy : N X -> (listof X)
+;; to create a list that contains
+;; obj n times
+
+(define (copy n obj)
+ (natural-f cons n obj empty))
+
+;; n-adder : N number -> number
+;; to add n to x using
+;; (+ 1 ...) only
+
+(define (n-adder n x)
+ (natural-f + n 1 x))
+
+;Don't forget to test natural-f. Also use natural-f to define n-multiplier, which consumes n and x and produces n times x with additions only. Use the examples to formulate a contract.
+;
+;n-multiplier : N number -> number
+;Multiply x by n with additions only.
+
+(define (n-multiplier n x)
+ (natural-f + n x 0))
+
+(equal? empty (copy 0 'hi))
+(equal? '(hi hi hi) (copy 3 'hi))
+
+(equal? 35 (n-adder 10 25))
+(equal? 57 (n-adder 23 34))
+(equal? 32 (n-multiplier 8 4))
\ No newline at end of file
blob - /dev/null
blob + 017d93acd193a4dd1610c6d78a6dfb6cd64391b7 (mode 644)
--- /dev/null
+++ 21.2.1.ss
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(local ((define (f x) x))
+ (build-list 4 f))
+
+(local ((define (f x) (+ 1 x)))
+ (build-list 4 f))
+
+(local ((define (f x)
+ (expt 10 (* -1
+ (+ x 1)))))
+ (build-list 4 f))
+
+;evens : N [>=0] -> (listof N [>=0])
+;Given n, evens creates a list of the first n even numbers.
+
+(define (evens n)
+ (local ((define (evens n)
+ (build-list n f))
+ (define (f n)
+ (* 2
+ (+ 1 n))))
+ (evens n)))
+
+#|
+
+(define (tabulate op n)
+ (cond
+ [(= n 0) (list (op 0))]
+ [else (cons (op n)
+ (tabulate op (sub1 n)))]))
+
+|#
+
+;tabulate : (number -> X) number -> (listof X)
+;Given op and n, tabulate a list of (f x) from x = n to x = 0.
+
+(define (tabulate op n)
+ (reverse (build-list (+ n 1) op)))
+
+;diagonal : N [>=0] -> (listof (listof number))
+;Creates a list of list of numbers representing a square identity matrix of width and height n with 1's where the row index equals the column index and 0's elsewhere. Do this by building a list of length n with 1 in the n-th position and 0's elsewhere. Then, append this list to the previously formed diagonal with a column of 0's appended to it.
+
+;first-row : N [>=0] -> (listof number)
+;Given n, create the first row of the n-by-n identity matrix.
+
+;add-col-zero : (listof (listof number)) -> (listof (listof number))
+;Given a-diag, add a new column of zeros to the left side of a-diag.
+
+(define (diagonal n)
+ (local ((define (diagonal n)
+ (cond
+ [(zero? n) empty]
+ [else (append (list (build-list n first-row))
+ (add-col-zero (diagonal (sub1 n))))]))
+ (define (first-row n)
+ (cond
+ [(= n 0) 1]
+ [else 0]))
+ (define (add-col-zero a-diag)
+ (cond
+ [(empty? a-diag) empty]
+ [else (cons (cons 0 (first a-diag))
+ (add-col-zero (rest a-diag)))])))
+ (diagonal n)))
+
+#|
+
+;f : N[>=0] N[>=0] -> (listof number)
+;Creates a (listof number) with length l with 1 at the n-th position (the first position has an index of zero) and 0's elsewhere.
+
+(define (f n l)
+ (cond
+ [(zero? l) empty]
+ [else ... (sub1 l) ...]))
+
+
+ (list
+ (list 1 0 0)
+ (list 0 1 0)
+ (list 0 0 1)))
+
+
+ (list
+ (list 1 0)
+ (list 0 1)))
+
+|#
+
+#|
+Exercise 21.2.1. Use build-list
+
+to define tabulate from exercise 21.1.1; and
+
+to define diagonal, which consumes a natural number n and creates a list of lists of 0 and 1.
+Example:
+
+(equal? (diagonal 3)
+ (list
+ (list 1 0 0)
+ (list 0 1 0)
+ (list 0 0 1)))
+Use local if function definitions require auxiliary functions. Solution
+
+;; build-list : N (N -> X) -> (listof X)
+;; to construct (list (f 0) ... (f (- n 1)))
+(define (build-list n f) ...)
+
+|#
\ No newline at end of file
blob - /dev/null
blob + 25a4a3d21cac255e3378b20c6743cc473094fb55 (mode 644)
--- /dev/null
+++ 21.2.1.ss~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+(local ((define (f x) x))
+ (build-list 4 f))
+
+(local ((define (f x) (+ 1 x)))
+ (build-list 4 f))
+
+(local ((define (f x)
+ (expt 10 (* -1
+ (+ x 1)))))
+ (build-list 4 f))
+
+;evens : N [>=0] -> (listof N [>=0])
+Given n, evens creates a list of the first n even numbers.
+
+(define (evens n)
+ (local ((define (evens n)
+ (build-list n f))
+ (define (f n)
+ (* 2
+ (+ 1 n))))
+ (evens n)))
+
+
+Exercise 21.2.1. Use build-list
+
+to define evens, which consumes a natural number n and creates the list of the first n even numbers;
+
+to define tabulate from exercise 21.1.1; and
+
+to define diagonal, which consumes a natural number n and creates a list of lists of 0 and 1.
+Example:
+
+(equal? (diagonal 3)
+ (list
+ (list 1 0 0)
+ (list 0 1 0)
+ (list 0 0 1)))
+Use local if function definitions require auxiliary functions. Solution
+
+;; build-list : N (N -> X) -> (listof X)
+;; to construct (list (f 0) ... (f (- n 1)))
+(define (build-list n f) ...)
\ No newline at end of file
blob - /dev/null
blob + 2291b6aa5fe837a38857c236919ad0200a340eb2 (mode 644)
--- /dev/null
+++ 21.2.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.2|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+;move-all : (listof posn) -> (listof posn)
+;Given alop, translate every posn to the right by 3.
+
+;move-x-3 : posn -> posn
+;Given aposn, translate to the right by 3.
+
+(define (move-all alop)
+ (local ((define (move-all alop)
+ (map move-x-3 alop))
+ (define (move-x-3 aposn)
+ (make-posn (+ 3 (posn-x aposn))
+ (posn-y aposn))))
+ (move-all alop)))
+
+(define-struct toy (name price))
+
+;A toy is a structure
+;(make-toy n p)
+;where n is a symbol and p is a number.
+;
+
+
+;eliminate-exp : (listof toy) number -> (listof toy)
+;Given alot, return all those (listof toy) whose price is below ua.
+
+;local
+;eliminate-exp : (listof toy) -> (listof toy)
+;Given alot, return all those (listof toy) whose price is below ua.
+;
+;expensive : toy -> boolean
+;Given ua, return true if the atoy has a price below ua.
+
+(define (eliminate-exp alot ua)
+ (local ((define (eliminate-exp alot)
+ (filter expensive? alot))
+ (define (expensive? atoy)
+ (< (toy-price atoy) ua)))
+ (eliminate-exp alot)))
+
+;recall : symbol (listof symbol) -> (listof symbol)
+;Consumes the name of a toy, called ty, and a list of names, called lon, and produces a list of names that contains all components of lon with the exception of ty
+
+(define (recall ty lon)
+ (local ((define (recall lon)
+ (filter not-equal lon))
+ (define (not-equal name)
+ (not (symbol=? ty name))))
+ (recall lon)))
+
+selection : (listof symbol) (listof symbol) -> (listof symbol)
+
+(define (selection list1 list2)
+ (cond
+ [(empty? list2) empty]
+ [(filter in-other-list? (first list2))
+ (cons (first list2)
+ (selection list1 (rest list2)))]
+ [else (selection list1 (rest list2))]))
+
+in-other-list? : symbol -> boolean
+Given name, determine if it occurs in the other list.
+
+(filter listequal list1)
+listequal
+= (first list2) (first list1)
+= (first list2) (second list1)
+...
+= (first list2) (first list1)
+
+
+;selection : (listof symbol) (listof symbol) -> (listof symbol)
+;selection, which consumes two lists of names and selects all those from the second one that are also on the first.
+
+(define (selection list1 list2)
+ (cond
+ [(empty? list2) empty]
+ [(in-other-list? (first list2) list1) (cons (first list2)
+ (selection list1 (rest list2)))]
+ [else (selection list1 (rest list2))]))
+
+(define (in-other-list? an-item a-list)
+ (cond
+ [(empty? a-list) false]
+ [(equal? (first a-list) an-item) true]
+ [else (in-other-list? an-item (rest a-list))]))
+
+in-other-list? symbol -> boolean
+Given name and list2, determine if name occurs anywhere in list2.
+
+
+
+#|
+
+Exercise 21.2.3. Here is the version of filter that DrScheme provides:
+
+;; filter : (X -> boolean) (listof X) -> (listof X)
+;; to construct a list of X from all those items on alon
+;; for which predicate? holds
+(define (filter predicate? alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cond
+ [(predicate? (first alon))
+ (cons (first alon) (filter predicate? (rest alon)))]
+ [else (filter predicate? (rest alon))])]))
+1. eliminate-exp, which consumes a number, ua, and a list of toy structures (containing name and price) and produces a list of all those descriptions whose price is below ua;
+2. recall, which consumes the name of a toy, called ty, and a list of names, called lon, and produces a list of names that contains all components of lon with the exception of ty;
+3. selection, which consumes two lists of names and selects all those from the second one that are also on the first.
+
+|#
\ No newline at end of file
blob - /dev/null
blob + 5d7d34cbd4c38fabbc37890a82a7bc23b644030d (mode 644)
--- /dev/null
+++ 21.2.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.2|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
blob - /dev/null
blob + 5ed1da809117d78eb58722d200b5fc86af14527d (mode 644)
--- /dev/null
+++ 21.2.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.2|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+
+(define (selection list1 list2)
+ (cond
+ [(empty? list1) empty]
+ [else (local ((define (equal-to-first-of-list1? a-symbol)
+ (equal? (first list1) a-symbol)))
+ (append (filter equal-to-first-of-list1? list2)
+ (selection list2 (rest list1))))]))
blob - /dev/null
blob + 47a30850864664c18aa87bf574859e2e5f54c36a (mode 644)
--- /dev/null
+++ 21.2.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.2|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
+;selection : (listof symbol) (listof symbol) -> (listof symbol)
+;selection, which consumes two lists of names and selects all those from the second one that are also on the first.
+
+(define (selection list1 list2)
+ (cond
+ [(empty? list2) empty]
+ [(in-other-list? (first list2) list1) (cons (first list2)
+ (selection list1 (rest list2)))]
+ [else (selection list1 (rest list2))]))
+
+(define (in-other-list? an-item a-list)
+ (cond
+ [(empty? a-list) false]
+ [(equal? (first a-list) an-item) true]
+ [else (in-other-list? an-item (rest a-list))]))
+
+(define (selection list1 list2)
+ (cond
+ [(empty? list1) empty]
+ [else (local ((define (equal-to-first-of-list1 a-symbol)
+ (equal? (first list1) a-symbol)))
+ (cons (filter equal-to-first-of-list1? list2) (selection list2 (rest list1))))]))
+
+
+equal-to-first-of-list1 : symbol -> boolean
blob - /dev/null
blob + 131b95b2741fc9fdf32ffafc3d304c0fb22a6ea1 (mode 644)
--- /dev/null
+++ 21.4.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+
+(define-struct circle (center radius color))
+#|
+;A circle is a structure
+;(make-circle ce ra co)
+;where ce is a posn, ra is a number, and co is a symbol.
+;
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+|#
+;process-circle : (circle -> X) circle -> X
+;Given operation and a-circle, process the circle according to operation (draw-solid-disk or clear-solid-disk).
+
+(define (process-circle operation a-circle)
+ (operation (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (process-circle draw-solid-disk a-circle))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (process-circle clear-solid-disk a-circle))
+
+;Exercise 21.4.1. Abstract the functions draw-a-circle and clear-a-circle into a single function process-circle.
+;
+;Define translate-circle using process-circle. Hint: If a primitive function doesn't quite fit an abstraction, we have to define auxiliary functions. For now, use define to do so. Intermezzo 4 introduces a handy and important short-hand for that purpose. Solution
+
+;translate-circle : circle number -> circle
+;Given a-circle and delta, return a circle structure moved delta to the right.
+;
+;translate-delta : posn number symbol -> circle
+;Given delta, center, radius, and color, return a circle structure translated delta to the right.
+
+(define (translate-circle a-circle delta)
+ (local ((define (translate-delta center radius color)
+ (make-circle (make-posn (+ delta (posn-x center))
+ (posn-y center))
+ radius
+ color)))
+ (process-circle translate-delta a-circle)))
+
+(define-struct rectangle (upper-left width height color))
+
+;A rectangle is a structure
+;(make-rectangle u w h c)
+;where u is a posn, w, h are numbers, and color is a symbol.
+;
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+
+#|
+Exercise 21.4.2. Abstract the functions draw-a-rectangle and clear-a-rectangle into a single function process-rectangle.
+
+Define translate-rectangle using process-rectangle. Solution
+|#
+
+;process-rectangle : (posn number number symbol -> X) rectangle -> X
+;Perform operation on a-rectangle.
+
+(define (process-rectangle operation a-rect)
+ (operation (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;draw-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (draw-a-rectangle a-rect)
+ (process-rectangle draw-solid-rect a-rect))
+
+;clear-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (clear-a-rectangle a-rect)
+ (process-rectangle clear-solid-rect a-rect))
+
+;translate-rectangle : (posn number number symbol -> boolean) rectangle number -> rectangle
+;Given a-rect and delta, return a rectangle structure translated delta to the right.
+
+(define (translate-rectangle a-rect delta)
+ (local ((define (translate-rectangle a-rect)
+ (process-rectangle translate-delta a-rect))
+ (define (translate-delta upper-left width height color)
+ (make-rectangle (make-posn (+ delta (posn-x upper-left))
+ (posn-y upper-left))
+ width
+ height
+ color)))
+ (translate-rectangle a-rect)))
+
+;process-shape : (posn number symbol -> X) or
+; (posn number number symbol -> X) shape -> X
+(define (process-shape operation a-shape)
+ (cond
+ [(circle? a-shape) process-circle operation a-shape]
+ [(rectangle? a-shape) process-rectangle operation a-shape]))
+
+(define (draw-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape draw-solid-disk a-shape)]
+ [(rectangle? a-shape) (process-shape draw-solid-rect a-shape)]))
\ No newline at end of file
blob - /dev/null
blob + db0e2d34a97dca9a52f4bf84b7751bbc6e649273 (mode 644)
--- /dev/null
+++ 21.4.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.4|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
blob - /dev/null
blob + c4fe4b86f16b5e263444f1e924eb1b969612cc3c (mode 644)
--- /dev/null
+++ 21.4.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+
+(define-struct circle (center radius color))
+#|
+;A circle is a structure
+;(make-circle ce ra co)
+;where ce is a posn, ra is a number, and co is a symbol.
+;
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+|#
+;process-circle : (circle -> X) circle -> X
+;Given operation and a-circle, process the circle according to operation (draw-solid-disk or clear-solid-disk).
+
+(define (process-circle operation a-circle)
+ (operation (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (process-circle draw-solid-disk a-circle))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (process-circle clear-solid-disk a-circle))
+
+;Exercise 21.4.1. Abstract the functions draw-a-circle and clear-a-circle into a single function process-circle.
+;
+;Define translate-circle using process-circle. Hint: If a primitive function doesn't quite fit an abstraction, we have to define auxiliary functions. For now, use define to do so. Intermezzo 4 introduces a handy and important short-hand for that purpose. Solution
+
+;translate-circle : circle number -> circle
+;Given a-circle and delta, return a circle structure moved delta to the right.
+;
+;translate-delta : posn number symbol -> circle
+;Given delta, center, radius, and color, return a circle structure translated delta to the right.
+
+(define (translate-circle a-circle delta)
+ (local ((define (translate-delta center radius color)
+ (make-circle (make-posn (+ delta (posn-x center))
+ (posn-y center))
+ radius
+ color)))
+ (process-circle translate-delta a-circle)))
+
+(define-struct rectangle (upper-left width height color))
+
+;A rectangle is a structure
+;(make-rectangle u w h c)
+;where u is a posn, w, h are numbers, and color is a symbol.
+;
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+
+#|
+Exercise 21.4.2. Abstract the functions draw-a-rectangle and clear-a-rectangle into a single function process-rectangle.
+
+Define translate-rectangle using process-rectangle. Solution
+|#
+
+;process-rectangle : (posn number number symbol -> X) rectangle -> X
+;Perform operation on a-rectangle.
+
+(define (process-rectangle operation a-rect)
+ (operation (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;draw-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (draw-a-rectangle a-rect)
+ (process-rectangle draw-solid-rect a-rect))
+
+;clear-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (clear-a-rectangle a-rect)
+ (process-rectangle clear-solid-rect a-rect))
+
+;translate-rectangle : (posn number number symbol -> boolean) rectangle number -> rectangle
+;Given a-rect and delta, return a rectangle structure translated delta to the right.
+
+(define (translate-rectangle a-rect delta)
+ (local ((define (translate-rectangle a-rect)
+ (process-rectangle translate-delta a-rect))
+ (define (translate-delta upper-left width height color)
+ (make-rectangle (make-posn (+ delta (posn-x upper-left))
+ (posn-y upper-left))
+ width
+ height
+ color)))
+ (translate-rectangle a-rect)))
+
+;process-shape : (posn number symbol -> X) or
+; (posn number number symbol -> X) shape -> X
+(define (process-shape operation a-shape)
+ (cond
+ [(circle? a-shape) (process-circle operation a-shape)]
+ [(rectangle? a-shape) (process-rectangle operation a-shape)]))
+
+(define (draw-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape draw-solid-disk a-shape)]
+ [(rectangle? a-shape) (process-shape draw-solid-rect a-shape)]))
+
+(define (clear-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape clear-solid-disk a-shape)]
+ [(rectangle? a-shape) (process-shape clear-solid-rect a-shape)]))
+
+(define (translate-shape a-shape delta)
+ (cond
+ [(circle? a-shape) (translate-circle a-shape delta)]
+ [(rectangle? a-shape) (translate-rectangle a-shape delta)]))
+
+;Exercise 21.4.4. Use Scheme's map and andmap to define draw-losh, clear-losh, and translate-losh. Solution
+
+
+;draw-losh : (listof shapes) -> boolean
+;Draws a (listof shapes) and return true.
+(define (draw-losh alosh)
+ (andmap draw-shape alosh))
+
+;clear-losh : (listof shapes) -> boolean
+;Clears a (listof shapes) and return true.
+(define (clear-losh alosh)
+ (andmap clear-shape alosh))
+
+;translate-losh : number (listof shapes) -> (listof shapes)
+;Translates alosh delta to the right and returns a new (listof shapes).
+
+(define (translate-losh alosh delta)
+ (local ((define (translate-shape a-shape)
+ (cond
+ [(circle? a-shape) (translate-circle a-shape delta)]
+ [(rectangle? a-shape) (translate-rectangle a-shape delta)])))
+ (map translate-shape alosh)))
+
+(define SQUIDWARD
+ (list (make-circle (make-posn 100 100)
+ 80
+ 'blue)
+ (make-circle (make-posn 60 60)
+ 10
+ 'red)
+ (make-circle (make-posn 140 60)
+ 10
+ 'red)
+ (make-rectangle (make-posn 90 80)
+ 20
+ 50
+ 'yellow)
+ (make-rectangle (make-posn 60 140)
+ 80
+ 20
+ 'green)))
+
+(translate-losh SQUIDWARD 50)
+
+#|
+;; map : (X -> Y) (listof X) -> (listof Y)
+;; to construct a list by applying f to each item on alox
+;; that is, (map f (list x-1 ... x-n)) = (list (f x-1) ... (f x-n))
+(define (map f alox) ...)
+
+;; andmap : (X -> boolean) (listof X) -> boolean
+;; to determine whether p holds for every item on alox
+;; that is, (andmap p (list x-1 ... x-n)) = (and (p x-1) (and ... (p x-n)))
+(define (andmap p alox) ...)
+
+;; ormap : (X -> boolean) (listof X) -> boolean
+;; to determine whether p holds for at least one item on alox
+;; that is, (ormap p (list x-1 ... x-n)) = (or (p x-1) (or ... (p x-n)))
+(define (ormap p alox) ...)
+|#
\ No newline at end of file
blob - /dev/null
blob + 9ed2454b6166fbd130a3b0d48ee9dad4721e814f (mode 644)
--- /dev/null
+++ 21.4.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+
+(define-struct circle (center radius color))
+#|
+;A circle is a structure
+;(make-circle ce ra co)
+;where ce is a posn, ra is a number, and co is a symbol.
+;
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+|#
+;process-circle : (circle -> X) circle -> X
+;Given operation and a-circle, process the circle according to operation (draw-solid-disk or clear-solid-disk).
+
+(define (process-circle operation a-circle)
+ (operation (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (process-circle draw-solid-disk a-circle))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (process-circle clear-solid-disk a-circle))
+
+;Exercise 21.4.1. Abstract the functions draw-a-circle and clear-a-circle into a single function process-circle.
+;
+;Define translate-circle using process-circle. Hint: If a primitive function doesn't quite fit an abstraction, we have to define auxiliary functions. For now, use define to do so. Intermezzo 4 introduces a handy and important short-hand for that purpose. Solution
+
+;translate-circle : circle number -> circle
+;Given a-circle and delta, return a circle structure moved delta to the right.
+;
+;translate-delta : posn number symbol -> circle
+;Given delta, center, radius, and color, return a circle structure translated delta to the right.
+
+(define (translate-circle a-circle delta)
+ (local ((define (translate-delta center radius color)
+ (make-circle (make-posn (+ delta (posn-x center))
+ (posn-y center))
+ radius
+ color)))
+ (process-circle translate-delta a-circle)))
+
+(define-struct rectangle (upper-left width height color))
+
+;A rectangle is a structure
+;(make-rectangle u w h c)
+;where u is a posn, w, h are numbers, and color is a symbol.
+;
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+
+#|
+Exercise 21.4.2. Abstract the functions draw-a-rectangle and clear-a-rectangle into a single function process-rectangle.
+
+Define translate-rectangle using process-rectangle. Solution
+|#
+
+;process-rectangle : (posn number number symbol -> X) rectangle -> X
+;Perform operation on a-rectangle.
+
+(define (process-rectangle operation a-rect)
+ (operation (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;draw-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (draw-a-rectangle a-rect)
+ (process-rectangle draw-solid-rect a-rect))
+
+;clear-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (clear-a-rectangle a-rect)
+ (process-rectangle clear-solid-rect a-rect))
+
+;translate-rectangle : (posn number number symbol -> boolean) rectangle number -> rectangle
+;Given a-rect and delta, return a rectangle structure translated delta to the right.
+
+(define (translate-rectangle a-rect delta)
+ (local ((define (translate-rectangle a-rect)
+ (process-rectangle translate-delta a-rect))
+ (define (translate-delta upper-left width height color)
+ (make-rectangle (make-posn (+ delta (posn-x upper-left))
+ (posn-y upper-left))
+ width
+ height
+ color)))
+ (translate-rectangle a-rect)))
+
+;process-shape : (posn number symbol -> X) or
+; (posn number number symbol -> X) shape -> X
+(define (process-shape operation a-shape)
+ (cond
+ [(circle? a-shape) (process-circle operation a-shape)]
+ [(rectangle? a-shape) (process-rectangle operation a-shape)]))
+
+(define (draw-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape draw-solid-disk a-shape)]
+ [(rectangle? a-shape) (process-shape draw-solid-rect a-shape)]))
\ No newline at end of file
blob - /dev/null
blob + 7361838e238ade076cb6282ef37da5df9ef325a6 (mode 644)
--- /dev/null
+++ 21.4.5
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.4|) (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")))))
+;A circle is a structure
+;(make-circle ce ra co)
+;where ce is a posn, ra is a number, and co is a symbol.
+
+;A rectangle is a structure
+;(make-rectangle u w h c)
+;where u is a posn, w, h are numbers, and color is a symbol.
+
+;A line is a structure
+;(make-line s e c)
+;where s, e are posn and c is a symbol.
+
+;A shape is either
+;1. a circle,
+;2. a rectangle, or
+;3. a line.
+
+;translate-posn : posn number number -> posn
+;Given a-posn, down, and right, translate the posn down and right.
+
+;process-circle : (circle -> X) circle -> X
+;Given operation and a-circle, process the circle according to operation (draw-solid-disk or clear-solid-disk).
+
+;process-rectangle : (posn number number symbol -> X) rectangle -> X
+;Perform operation on a-rectangle.
+
+;process-line : (posn posn symbol -> X) line -> X
+
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+;draw-a-rectangle : rectangle -> boolean
+;clear-a-rectangle : rectangle -> boolean
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+;translate-circle : circle number number -> circle
+
+;translate-rectangle : rectangle number number -> rectangle
+;Given a-rect, right, and down, return a rectangle structure translated right to the right and down.
+
+;Given a-circle and right, return a circle structure moved right towards the x-axis and down towards the y-axis.
+
+;translate-right : number posn number symbol -> circle
+;Given right, center, radius, and color, return a circle structure translated right units towards the x-axis.
+
+;translate-down : number posn number symbol -> circle
+;Given down, center, radius, and color, return a circle structure translated down units towards the y-axis.
+
+;translate-line : line number number -> line
+;Given a-line, right, and down, return a new line translated right and down.
+
+;process-shape : (shape -> X) shape -> X
+
+;draw-shape : (shape -> X) shape -> X
+
+;clear-shape : (shape -> X) shape -> X
+
+;translate-shape : (shape -> shape) shape number number -> shape
+
+;draw-losh : (listof shapes) -> boolean
+;Draws a (listof shapes) and return true.
+
+;clear-losh : (listof shapes) -> boolean
+;Clears a (listof shapes) and return true.
+
+;translate-losh : (listof shapes) number number -> (listof shapes)
+;Translates alosh right and down and returns a new (listof shapes).
+
+(define-struct circle (center radius color))
+
+(define-struct rectangle (upper-left width height color))
+
+(define-struct line (start end color))
+
+(define (translate-posn a-posn right down)
+ (make-posn (+ right (posn-x a-posn))
+ (+ down (posn-y a-posn))))
+
+(define (process-circle operation a-circle)
+ (operation (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+(define (process-rectangle operation a-rect)
+ (operation (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+(define (process-line operation a-line)
+ (operation (line-start a-line)
+ (line-end a-line)
+ (line-color a-line)))
+
+(define (draw-a-circle a-circle)
+ (process-circle draw-solid-disk a-circle))
+
+(define (draw-a-rectangle a-rect)
+ (process-rectangle draw-solid-rect a-rect))
+
+(define (draw-a-line a-line)
+ (process-line draw-solid-line a-line))
+
+(define (clear-a-circle a-circle)
+ (process-circle clear-solid-disk a-circle))
+
+(define (clear-a-rectangle a-rect)
+ (process-rectangle clear-solid-rect a-rect))
+
+(define (clear-a-line a-line)
+ (process-line clear-solid-line a-line))
+
+(define (translate-circle a-circle right down)
+ (local ((define (translate-right-down center radius color)
+ (make-circle (translate-posn center right down)
+ radius
+ color)))
+ (process-circle translate-right-down a-circle)))
+
+(define (translate-rectangle a-rect right down)
+ (local ((define (translate-right-down upper-left width height color)
+ (make-rectangle (translate-posn upper-left right down)
+ width
+ height
+ color)))
+ (process-rectangle translate-right-down a-rect)))
+
+
+(define (translate-line a-line right down)
+ (local ((define (translate-right-down start end color)
+ (make-line (translate-posn start right down)
+ (translate-posn end right down)
+ color)))
+ (process-line translate-right-down a-line)))
+
+(define (process-shape operation a-shape)
+ (operation a-shape))
+
+(define (draw-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape draw-a-circle a-shape)]
+ [(rectangle? a-shape) (process-shape draw-a-rectangle a-shape)]
+ [(line? a-shape) (process-shape draw-a-line a-shape)]))
+
+(define (clear-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape clear-a-circle a-shape)]
+ [(rectangle? a-shape) (process-shape clear-a-rectangle a-shape)]
+ [(line? a-shape) (process-shape clear-a-line a-shape)]))
+
+(define (translate-shape a-shape right down)
+ (local ((define (translate-shape-right-down a-shape)
+ (cond
+ [(circle? a-shape) (translate-circle a-shape right down)]
+ [(rectangle? a-shape) (translate-rectangle a-shape right down)]
+ [(line? a-shape) (translate-line a-shape right down)])))
+ (process-shape translate-shape-right-down a-shape)))
+
+(define (draw-losh alosh)
+ (andmap draw-shape alosh))
+
+(define (clear-losh alosh)
+ (andmap clear-shape alosh))
+
+(define (translate-losh alosh right down)
+ (local ((define (translate-shape-right-down a-shape)
+ (translate-shape a-shape right down)))
+ (map translate-shape-right-down alosh)))
+
+(define SQUIDWARD
+ (list (make-circle (make-posn 100 100)
+ 80
+ 'blue)
+ (make-circle (make-posn 60 60)
+ 10
+ 'red)
+ (make-circle (make-posn 140 60)
+ 10
+ 'red)
+ (make-rectangle (make-posn 90 80)
+ 20
+ 50
+ 'yellow)
+ (make-rectangle (make-posn 60 140)
+ 80
+ 20
+ 'green)
+ (make-line (make-posn 60 150)
+ (make-posn 140 150)
+ 'brown)
+ (make-line (make-posn 60 200)
+ (make-posn 140 200)
+ 'brown)))
+
+;(start 500 500)
+;(translate-losh SQUIDWARD 15 25)
+;(draw-losh SQUIDWARD)
+
+(define LUNAR (list (make-circle (make-posn 375
+ 375)
+ 100 'blue)
+ (make-line (make-posn (- 375 (* 50 (sqrt 2))) (+ 375 (* 50 (sqrt 2))))
+ (make-posn 150 600)
+ 'black)
+ (make-line (make-posn (+ 375 (* 50 (sqrt 2))) (+ 375 (* 50 (sqrt 2))))
+ (make-posn 600 600)
+ 'black)
+ (make-rectangle (make-posn 400 300) 100 75 'gray)))
+
+
+;move-lr : number (listof shape) -> (listof shape)
+;Given right and alosh, moves the (listof shapes) right.
+
+(define (move-lr right alosh)
+ (translate-losh alosh right 0))
+
+;move-ud : number (listof shape) -> (listof shape)
+;Given down and alosh, moves the (listof shapes) down.
+
+(define (move-ud down alosh)
+ (translate-losh alosh 0 down))
+
+;clear-and-draw-losh : (listof shapes) -> boolean
+;Clears and draws alosh.
+(define (clear-and-draw-losh alosh)
+ (and (clear-losh alosh)
+ (draw-losh alosh)))
+
+;lunar-lander : (listof shapes) number -> boolean
+;Given alosh and delta, moves alosh using a GUI controller.
+
+(start 750 750)
+(draw-losh LUNAR)
+(control LUNAR 5 move-lr move-ud clear-and-draw-losh)
blob - /dev/null
blob + c4fe4b86f16b5e263444f1e924eb1b969612cc3c (mode 644)
--- /dev/null
+++ 21.4.5~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |21.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
+
+(define-struct circle (center radius color))
+#|
+;A circle is a structure
+;(make-circle ce ra co)
+;where ce is a posn, ra is a number, and co is a symbol.
+;
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+|#
+;process-circle : (circle -> X) circle -> X
+;Given operation and a-circle, process the circle according to operation (draw-solid-disk or clear-solid-disk).
+
+(define (process-circle operation a-circle)
+ (operation (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+;draw-a-circle : circle -> boolean
+;Given a-circle, draw it and return true.
+
+(define (draw-a-circle a-circle)
+ (process-circle draw-solid-disk a-circle))
+
+;clear-a-circle : circle -> boolean
+;Given a-circle, clear it and return true.
+
+(define (clear-a-circle a-circle)
+ (process-circle clear-solid-disk a-circle))
+
+;Exercise 21.4.1. Abstract the functions draw-a-circle and clear-a-circle into a single function process-circle.
+;
+;Define translate-circle using process-circle. Hint: If a primitive function doesn't quite fit an abstraction, we have to define auxiliary functions. For now, use define to do so. Intermezzo 4 introduces a handy and important short-hand for that purpose. Solution
+
+;translate-circle : circle number -> circle
+;Given a-circle and delta, return a circle structure moved delta to the right.
+;
+;translate-delta : posn number symbol -> circle
+;Given delta, center, radius, and color, return a circle structure translated delta to the right.
+
+(define (translate-circle a-circle delta)
+ (local ((define (translate-delta center radius color)
+ (make-circle (make-posn (+ delta (posn-x center))
+ (posn-y center))
+ radius
+ color)))
+ (process-circle translate-delta a-circle)))
+
+(define-struct rectangle (upper-left width height color))
+
+;A rectangle is a structure
+;(make-rectangle u w h c)
+;where u is a posn, w, h are numbers, and color is a symbol.
+;
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+
+#|
+Exercise 21.4.2. Abstract the functions draw-a-rectangle and clear-a-rectangle into a single function process-rectangle.
+
+Define translate-rectangle using process-rectangle. Solution
+|#
+
+;process-rectangle : (posn number number symbol -> X) rectangle -> X
+;Perform operation on a-rectangle.
+
+(define (process-rectangle operation a-rect)
+ (operation (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;draw-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (draw-a-rectangle a-rect)
+ (process-rectangle draw-solid-rect a-rect))
+
+;clear-a-rectangle : (posn number number symbol -> boolean) rectangle -> boolean
+(define (clear-a-rectangle a-rect)
+ (process-rectangle clear-solid-rect a-rect))
+
+;translate-rectangle : (posn number number symbol -> boolean) rectangle number -> rectangle
+;Given a-rect and delta, return a rectangle structure translated delta to the right.
+
+(define (translate-rectangle a-rect delta)
+ (local ((define (translate-rectangle a-rect)
+ (process-rectangle translate-delta a-rect))
+ (define (translate-delta upper-left width height color)
+ (make-rectangle (make-posn (+ delta (posn-x upper-left))
+ (posn-y upper-left))
+ width
+ height
+ color)))
+ (translate-rectangle a-rect)))
+
+;process-shape : (posn number symbol -> X) or
+; (posn number number symbol -> X) shape -> X
+(define (process-shape operation a-shape)
+ (cond
+ [(circle? a-shape) (process-circle operation a-shape)]
+ [(rectangle? a-shape) (process-rectangle operation a-shape)]))
+
+(define (draw-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape draw-solid-disk a-shape)]
+ [(rectangle? a-shape) (process-shape draw-solid-rect a-shape)]))
+
+(define (clear-shape a-shape)
+ (cond
+ [(circle? a-shape) (process-shape clear-solid-disk a-shape)]
+ [(rectangle? a-shape) (process-shape clear-solid-rect a-shape)]))
+
+(define (translate-shape a-shape delta)
+ (cond
+ [(circle? a-shape) (translate-circle a-shape delta)]
+ [(rectangle? a-shape) (translate-rectangle a-shape delta)]))
+
+;Exercise 21.4.4. Use Scheme's map and andmap to define draw-losh, clear-losh, and translate-losh. Solution
+
+
+;draw-losh : (listof shapes) -> boolean
+;Draws a (listof shapes) and return true.
+(define (draw-losh alosh)
+ (andmap draw-shape alosh))
+
+;clear-losh : (listof shapes) -> boolean
+;Clears a (listof shapes) and return true.
+(define (clear-losh alosh)
+ (andmap clear-shape alosh))
+
+;translate-losh : number (listof shapes) -> (listof shapes)
+;Translates alosh delta to the right and returns a new (listof shapes).
+
+(define (translate-losh alosh delta)
+ (local ((define (translate-shape a-shape)
+ (cond
+ [(circle? a-shape) (translate-circle a-shape delta)]
+ [(rectangle? a-shape) (translate-rectangle a-shape delta)])))
+ (map translate-shape alosh)))
+
+(define SQUIDWARD
+ (list (make-circle (make-posn 100 100)
+ 80
+ 'blue)
+ (make-circle (make-posn 60 60)
+ 10
+ 'red)
+ (make-circle (make-posn 140 60)
+ 10
+ 'red)
+ (make-rectangle (make-posn 90 80)
+ 20
+ 50
+ 'yellow)
+ (make-rectangle (make-posn 60 140)
+ 80
+ 20
+ 'green)))
+
+(translate-losh SQUIDWARD 50)
+
+#|
+;; map : (X -> Y) (listof X) -> (listof Y)
+;; to construct a list by applying f to each item on alox
+;; that is, (map f (list x-1 ... x-n)) = (list (f x-1) ... (f x-n))
+(define (map f alox) ...)
+
+;; andmap : (X -> boolean) (listof X) -> boolean
+;; to determine whether p holds for every item on alox
+;; that is, (andmap p (list x-1 ... x-n)) = (and (p x-1) (and ... (p x-n)))
+(define (andmap p alox) ...)
+
+;; ormap : (X -> boolean) (listof X) -> boolean
+;; to determine whether p holds for at least one item on alox
+;; that is, (ormap p (list x-1 ... x-n)) = (or (p x-1) (or ... (p x-n)))
+(define (ormap p alox) ...)
+|#
\ No newline at end of file
blob - /dev/null
blob + 5978999c38a0033087e85c6bb9f30c82cc95c62a (mode 644)
--- /dev/null
+++ 22.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.2|) (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")))))
+;Exercise 22.2.1. Define an abstraction of the functions convertCF and names from section 21.1 using the new recipe for abstraction. Solution
+
+(define-struct ir (name price))
+
+;An inventory record (ir) is a structure
+;(make-ir name price)
+
+#|
+
+;; convertCF : lon -> lon
+(define (convertCF alon)
+ (cond
+ [(empty? alon) empty]
+ [else
+ (cons (operator (first alon))
+ (convertCF (rest alon)))]))
+
+;; names : (listof ir) -> los
+(define (names aloir)
+ (cond
+ [(empty? aloir) empty]
+ [else
+ (cons (operator (first aloir))
+ (names (rest aloir)))]))
+
+|#
+
+;abs-func : (X -> Y) -> ((listof X) -> (listof Y))
+(define (abs-map operator)
+ (local ((define (map alox)
+ (cond
+ [(empty? alox) empty]
+ [else (cons (operator (first alox))
+ (map (rest alox)))])))
+ map))
+
+;C->F : number -> number
+(define (C->F temp)
+ (+ (* 9/5 temp) 32))
+
+(define convertCF (abs-map C->F))
+(define names (abs-map ir-name))
+
+(define listofir (list (make-ir 'Pencil 0.40)
+ (make-ir 'Eraser 1.99)
+ (make-ir 'Pen 1.25)
+ (make-ir 'PaperClip 0.05)
+ (make-ir 'Highlighter 4.50)))
\ No newline at end of file
blob - /dev/null
blob + 039e1b897491387483bf91a68403ef8bfe00adef (mode 644)
--- /dev/null
+++ 22.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.2|) (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")))))
+Exercise 22.2.1. Define an abstraction of the functions convertCF and names from section 21.1 using the new recipe for abstraction. Solution
+
+map
+
+;convertFC : (listof number) -> (listof number)
+;Converts a list of Fahrenheit measurements to a list of Celsius measurements
+
+
+(define (convertFC lon)
+ (map F->C lon))
+(define (F->C t)
+ (* 5/9 (- t 32)))
+(convertFC lon)
\ No newline at end of file
blob - /dev/null
blob + 06362d09593d79f2c1cd40edd1302fd7b1f26dfc (mode 644)
--- /dev/null
+++ 22.2.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.2|) (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")))))
+;Exercise 22.2.2. Define an abstract version of sort (see exercise 19.1.6) using the new recipe for abstraction. Solution
+
+;abs-sort : (number number -> boolean) -> ((listof number) -> (listof number))
+;Given the operator, which determines whether to sort ascending or descending, abs-sort returns a sort function that sorts a (listof numbers).
+
+(define (abs-sort operator)
+ (local ((define (sort alon)
+ (local ((define (sort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (insert (first alon) (sort (rest alon)))]))
+ (define (insert an alon)
+ (cond
+ [(empty? alon) (list an)]
+ [else (cond
+ [(operator an (first alon)) (cons an alon)]
+ [else (cons (first alon) (insert an (rest alon)))])])))
+ (sort alon))))
+ sort))
+
+;sort-ascend : (listof numbers) -> (listof numbers)
+;Given a-lon, return a list-of-numbers sorted in ascending order.
+(define sort-ascend (abs-sort <))
+
+;sort-descend : (listof numbers) -> (listof numbers)
+;Given a-lon, return a list-of-numbers sorted in descending order.
+(define sort-descend (abs-sort >))
+
+;abs-fold : (X Y -> Y) -> ((listof X) -> Y)
+;Given operator and base, return the fold function with operator filled in.
+
+(define (abs-fold operator base)
+ (local ((define (fold alon)
+ (cond
+ [(empty? alon) base]
+ [else (operator (first alon)
+ (fold (rest alon)))])))
+ fold))
+
+(define sum (abs-fold + 0))
+(define product (abs-fold * 1))
\ No newline at end of file
blob - /dev/null
blob + f298dc307b87716196c7d819b2917c90f9fbcea8 (mode 644)
--- /dev/null
+++ 22.2.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.2|) (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")))))
+Exercise 22.2.2. Define an abstract version of sort (see exercise 19.1.6) using the new recipe for abstraction. Solution
+
+;; sort : list-of-numbers predicate -> list-of-numbers
+;; to construct a list with all items from alon in ascending or descending order
+(define (sort1 alon predicate)
+ (local ((define (sort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (insert (first alon) (sort (rest alon)))]))
+ (define (insert an alon)
+ (cond
+ [(empty? alon) (list an)]
+ [else (cond
+ [(predicate an (first alon)) (cons an alon)]
+ [else (cons (first alon) (insert an (rest alon)))])])))
+ (sort alon)))
+
+;sort-ascend : list-of-numbers
+;Given a-lon, return a list-of-numbers sorted in ascending order.
+(define (sort-ascend alon)
+ (sort1 alon <))
+
+;sort-descend : list-of-numbers
+;Given a-lon, return a list-of-numbers sorted in descending order.
+(define (sort-ascend alon)
+ (sort1 alon >))
+
+;; sort : list-of-numbers -> list-of-numbers
+;; to construct a list with all items from alon in descending order
+(define (sort alon)
+ (local ((define (sort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (insert (first alon) (sort (rest alon)))]))
+ (define (insert an alon)
+ (cond
+ [(empty? alon) (list an)]
+ [else (cond
+ [(> an (first alon)) (cons an alon)]
+ [else (cons (first alon) (insert an (rest alon)))])])))
+ (sort alon)))
blob - /dev/null
blob + 100d955f21a3464a5121fd0bedd526e5cde309d0 (mode 644)
--- /dev/null
+++ 22.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+
+(define (change-text event)
+ (draw-message main-message (text-contents main-text)))
+(define (change-choice event)
+ (cond
+ [(= (choice-index main-choice) 0) (draw-message main-choice-message "Please make a selection")]
+ [(= (choice-index main-choice) 1) (draw-message main-choice-message "Let's shop another time")]
+ [(= (choice-index main-choice) 2) (draw-message main-choice-message "There's nothing interesting on TV")]
+ [(= (choice-index main-choice) 3) (draw-message main-choice-message "Sure, we're programming right now!")]
+ [(= (choice-index main-choice) 4) (draw-message main-choice-message "Maybe in 2 hours!")]))
+(define (close-main-window event)
+ (hide-window main-window))
+
+(define main-message (make-message "Hi, nice to meet you too!"))
+(define query (make-message "What would you like to do today?"))
+(define main-text (make-text "Hi Aaron!"))
+(define main-choice-message (make-message ""))
+(define main-choice (make-choice (list "Make a selection"
+ "Go Shopping"
+ "Watch TV"
+ "Program Scheme"
+ "Sleep")))
+(define main-window
+ (create-window
+ (list (list (make-button "Close Window" close-main-window))
+ (list (make-button "Change Text" change-text)
+ main-text main-message)
+ (list query)
+ (list main-choice
+ (make-button "Go!" change-choice))
+ (list main-choice-message))))
+
+
\ No newline at end of file
blob - /dev/null
blob + 593c59f7e4c3c586143eb0cd562a9e5e306f7a63 (mode 644)
--- /dev/null
+++ 22.3.1-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+;build-number : (listof number) -> number
+;Given alon which represent the digits of a number, with the first digit representing the most significant digit, return the number alon represents.
+
+;x10add : number number -> number
+;Given n1 and n2, multiply n2 by 10 (ie, x10) then add to n1 (ie, add).
+
+(define (build-number alon)
+ (local ((define (x10add n1 n2)
+ (+ (* n2 10) n1)))
+ (foldl x10add 0 alon)))
+
+;;View
+
+(define a-msg (make-message "Please choose 3 digits"))
+
+;;DIGITS is a list of gui-items [choice]
+(define DIGITS (local ((define (create-choice-gui colnum)
+ (make-choice (build-list 10 number->string))))
+ (build-list 3 create-choice-gui)))
+
+;;list-of-digit-choices : number -> gui-item [choice]
+
+
+;;Controller
+
+(define (submit-digits event)
+ (draw-message a-msg (number->string (build-number (map choice-index DIGITS)))))
+
+(create-window (list DIGITS
+ (list a-msg)
+ (list (make-button "Submit digits" submit-digits))))
\ No newline at end of file
blob - /dev/null
blob + 2a203194d5e996fab8915cc0170378dfdf4433db (mode 644)
--- /dev/null
+++ 22.3.1-2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+Model
+
+View
+
+(define a-msg (make-message "Please choose 3 digits"))
+(define submit (make-button "Submit digits" submit-digits))
+
+Controller
+
+(create-window (list (list a-msg)
+ (list ))
blob - /dev/null
blob + ba80cabab48be0c951d13ddea0b1364c554e0f7d (mode 644)
--- /dev/null
+++ 22.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+
+(define (change-text event)
+ (draw-message main-message (text-contents main-text)))
+
+(define main-message (make-message "What would you like to do today?"))
+(define main-text (make-text "Hi Aaron!"))
+(define main-choice (make-message "Choose an option"))
+
+(create-window
+ (list (list (make-button "Change Text" change-text)
+ main-text)
+ (list main-message)
+ (list (make-choice (list "Go Shopping"
+ "Watch TV"
+ "Program Scheme"
+ "Sleep")))
+ (list main-choice)))
+
+
\ No newline at end of file
blob - /dev/null
blob + 49984cc23768241d74791f4f8b64af169ee170db (mode 644)
--- /dev/null
+++ 22.3.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+;build-number : number number -> number
+;Given new and previous, multiply previous by 10 and add new to build a new number for display in the calculator.
+
+(define (build-number new previous)
+ (+ (* 10 previous) new))
+
+;A cell is either
+;1. a number or
+;2. a symbol.
+
+;A gui-table is a (listof (listof cell)).
+
+
+(define pad1 '((1 2 3)
+ (4 5 6)
+ (7 8 9)
+ ("#" 0 "*")))
+(define pad2 '((1 2 3 "+")
+ (4 5 6 "-")
+ (7 8 9 "*")
+ (0 "=" "." "/")))
+
+
+;;View
+
+;pad->gui : string gui-table -> (listof (listof gui-items))
+;Given title and a-gui-table, return a (listof (listof gui-items)) that can be used by create-window to create a phone or calculator pad. pad->gui first creates a message gui-item with the string from title, then a message gui-item repeating the last item entered, and finally an array of button gui-items.
+
+(define (pad->gui title a-gui-table)
+ (append (list (list (make-message title))
+ (list (make-message "")))
+ (map loc->lob a-gui-table)))
+
+
+
+;;Controller
+
+;cell->button : cell -> gui-item [button]
+;Given acell, create a gui-item [button].
+
+;gen-button : string -> gui-item [button]
+
+;pad-callback : event -> true
+;Draws acell (the text associated with the button) into title.
+
+(define (cell->button acell)
+ (local ((define (gen-button cell-text)
+ (make-button cell-text pad-callback))
+ (define (pad-callback event)
+ (draw-text (convert->string acell))))
+ (gen-button (convert->string acell))))
+
+;draw-text : string -> true
+;Given a-string, draw it into the title and return true.
+
+(define (draw-text a-string)
+ (draw-message (list-ref (list-ref phonepad 1) 0) a-string))
+
+;convert->string : X -> string
+
+(define (convert->string a-datum)
+ (cond
+ [(number? a-datum) (number->string a-datum)]
+ [else a-datum]))
+
+;loc->lob : (listof cell)
+;[(listof cells) to (listof buttons)] Given aloc, convert them to a lob.
+
+(define (loc->lob aloc)
+ (map cell->button aloc))
+
+(define phonepad (pad->gui "Phone" pad1))
+(define calcpad (pad->gui "Calculator" pad2))
+
+(create-window phonepad)
blob - /dev/null
blob + 0989d51ae3a7aa932aefc75e8e9ac82986a9ff8a (mode 644)
--- /dev/null
+++ 22.3.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+A cell is either
+1. a number or
+2. a symbol.
+
+A gui-table is a (listof (listof cell)).
+
+(define phonepad '((1 2 3)
+ (4 5 6)
+ (7 8 9)
+ (\# 0 *)))
+(define calcpad '((1 2 3 +)
+ (4 5 6 -)
+ (7 8 9 *)
+ (0 = \. /)))
+
+pad->gui
\ No newline at end of file
blob - /dev/null
blob + 9b065495ad21308373a30041e4ac5760b13e025d (mode 644)
--- /dev/null
+++ 23.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;sqr-term : N[>=0] -> number
+;Given n, maps n to the n-th term of a sequence, in this case, sqr-term.
+
+(define (sqr-term n)
+ (sqr n))
+
+;series : (number -> number) [N>=0] -> number
+;Given a nth-term and n, sums up the first n terms of the series.
+(define (series nth-term n)
+ (cond
+ [(zero? n) (nth-term n)]
+ [else (+ (nth-term n)
+ (series nth-term (sub1 n)))]))
blob - /dev/null
blob + eb22c6f1105c0564797bc5185dfc9ce7c767389b (mode 644)
--- /dev/null
+++ 23.1.1-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; make-even : N -> N[even]
+;; to compute the i-th even number
+(define (make-even i)
+ (* 2 i))
+
+;; make-odd : N -> N[odd]
+;; to compute the i-th odd number
+(define (make-odd i)
+ (+ (* 2 i) 1))
+
+;series-local : (N -> N) -> (N -> number)
+(define (series-local a-term)
+ (local ((define (series n)
+ (cond
+ [(= n 0) (a-term n)]
+ [else (+ (a-term n)
+ (series (- n 1)))])))
+ series))
+
+(define series-even (series-local make-even))
+(series-even 10)
\ No newline at end of file
blob - /dev/null
blob + 019c41a37d7d96e2067377666a3d90b1893860fa (mode 644)
--- /dev/null
+++ 23.1.1-2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; make-even : N -> N[even]
+;; to compute the i-th even number
+(define (make-even i)
+ (* 2 i))
+
+;; make-odd : N -> N[odd]
+;; to compute the i-th odd number
+(define (make-odd i)
+ (+ (* 2 i) 1))
+
+;; series : N (N -> number) -> number
+;; to sum up the first n numbers in the sequence a-term,
+(define (series n a-term)
+ (cond
+ [(= n 0) (a-term n)]
+ [else (+ (a-term n)
+ (series (- n 1) a-term))]))
+
+;; series-even1 : N -> number
+(define (series-even1 n)
+ (series n make-even))
+
+;; series-odd1 : N -> number
+(define (series-odd1 n)
+ (series n make-odd))
+
blob - /dev/null
blob + 4c31a4efbeb02d4d19e548f48192485e42816a58 (mode 644)
--- /dev/null
+++ 23.1.1-3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+(define NUM-OF-DIGITS 3)
+
+;;Chosen is a random number between 0 and 10^(NUM-OF-DIGITS)
+(define chosen (random (expt 10 NUM-OF-DIGITS)))
+
+
+;build-number : (listof number) -> number
+;Given alon which represent the digits of a number, with the first digit representing the most significant digit, return the number alon represents.
+
+;x10add : number number -> number
+;Given n1 and n2, multiply n2 by 10 (ie, x10) then add to n1 (ie, add).
+
+(define (build-number alon)
+ (local ((define (x10add n1 n2)
+ (+ (* n2 10) n1)))
+ (foldl x10add 0 alon)))
+
+;;View
+
+(define a-msg (make-message "Make a guess!"))
+
+;;DIGITS is a list of gui-items [choice]
+(define DIGITS (local ((define (create-choice-gui colnum)
+ (make-choice (build-list 10 number->string))))
+ (build-list NUM-OF-DIGITS create-choice-gui)))
+
+;;list-of-digit-choices : number -> gui-item [choice]
+
+
+;;Controller
+
+;;check-digits : event -> true
+;;Given event, return true. check-digits checks to see if the guess matches the chosen number.
+(define (check-digits event)
+ (local ((define guess (build-number (map choice-index DIGITS))))
+ (cond
+ [(> guess chosen) (draw-message a-msg "Too High")]
+ [(< guess chosen) (draw-message a-msg "Too Low")]
+ [(= guess chosen) (draw-message a-msg "You've Won!")])))
+
+(create-window (list DIGITS
+ (list a-msg)
+ (list (make-button "Check Guess" check-digits))))
\ No newline at end of file
blob - /dev/null
blob + 8cf162ba840f418f1eecdd1c5c3b6100d2ab9e81 (mode 644)
--- /dev/null
+++ 23.1.1-3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+;build-number : (listof number) -> number
+;Given alon which represent the digits of a number, with the first digit representing the most significant digit, return the number alon represents.
+
+;x10add : number number -> number
+;Given n1 and n2, multiply n2 by 10 (ie, x10) then add to n1 (ie, add).
+
+(define (build-number alon)
+ (local ((define (x10add n1 n2)
+ (+ (* n2 10) n1)))
+ (foldl x10add 0 alon)))
+
+;;View
+
+(define a-msg (make-message "Please choose 3 digits"))
+
+;;DIGITS is a list of gui-items [choice]
+(define DIGITS (local ((define (create-choice-gui colnum)
+ (make-choice (build-list 10 number->string))))
+ (build-list 3 create-choice-gui)))
+
+;;list-of-digit-choices : number -> gui-item [choice]
+
+
+;;Controller
+
+(define (submit-digits event)
+ (draw-message a-msg (number->string (build-number (map choice-index DIGITS)))))
+
+(create-window (list DIGITS
+ (list a-msg)
+ (list (make-button "Submit digits" submit-digits))))
\ No newline at end of file
blob - /dev/null
blob + 33941135c0dc6fe8ac92b6c8b7eafaa2403a8ba5 (mode 644)
--- /dev/null
+++ 23.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 260d863c64af27fe94fe8f187e993f53c2fc3ccf (mode 644)
--- /dev/null
+++ 23.1.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+(define-struct pr (name number))
+
+;A phone-record (pr) is a structure
+;(make-pr name number)
+;where name is a symbol and number is a number
+
+(define LOPR (list (make-pr 'John 6265939257)
+ (make-pr 'Aaron 6267217410)
+ (make-pr 'Hsinya 9195374958)))
+
+;search-name : symbol (listof pr)-> string
+;Given aname and alopr, find the phone-record containing aname in the name field and return its phone number as a string. Otherwise returns "name not found".
+
+;search-number : number (listof pr) -> string
+
+(define (search-name aname alopr)
+ (cond
+ [(empty? alopr) "name not found"]
+ [(symbol=? aname (pr-name (first alopr))) (number->string (pr-number (first alopr)))]
+ [else (search-name aname (rest alopr))]))
+
+(define (search-number anumber alopr)
+ (cond
+ [(empty? alopr) "number not found"]
+ [(= anumber (pr-number (first alopr))) (symbol->string (pr-name (first alopr)))]
+ [else (search-number anumber (rest alopr))]))
+
+;;View
+
+(define search-text (make-text "Enter Name:"))
+(define search-result (make-message "Find A Phone Number"))
+
+;;Controller
+
+;search-controller : event -> true
+;Extract the name or number from search-text and draw either the corresponding number or name in search-result.
+
+;search-controller : (X (listof pr) -> string) (string -> X) -> true
+;X is either a symbol or number
+;Extract the name or number from search-text and draw either the corresponding number or name in search-result.
+
+(define (search-controller event)
+ (local ((define (search-controller search-op convert-op)
+ (draw-message search-result
+ (search-op
+ (convert-op (text-contents search-text)) LOPR)))
+ (define a-num? (string->number (text-contents search-text))))
+ (cond
+ [(number? a-num?) (search-controller search-number string->number)]
+ [else (search-controller search-name string->symbol)])))
+
+(create-window (list (list search-text
+ (make-button "Search" search-controller))
+ (list search-result)))
\ No newline at end of file
blob - /dev/null
blob + 8ad180e10b156a9ecdb95b11524ff9fd46967af5 (mode 644)
--- /dev/null
+++ 23.1.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+;;View
+
+(define text-search (make-text "
+
+;;Controller
+
+(create-window (list (list )
+ (list))
\ No newline at end of file
blob - /dev/null
blob + 7195ed0af6e258f8ae51f2153c911c2d2d3c87bf (mode 644)
--- /dev/null
+++ 23.2.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;a-fives : N[>=0] -> number
+;Given n, determine recursively the value of the n-th term in the series 8, 13, 18, etc. where the first term has an index 0.
+
+(define (a-fives n)
+ (cond
+ [(zero? n) 8]
+ [else (+ 5 (a-fives (sub1 n)))]))
+
+;a-fives-closed : N[>=0] -> number
+;A non-recursive function for finding the n-th term of the series 8, 13, 18, etc., where the first term has an index 0.
+
+(define (a-fives-closed n)
+ (+ (* n 5) 8))
+
+;series : (N[>=0] -> number) N[>=0] -> number
+;Given a-term and n, determine the sum of the first n-th terms in the sequence a-term.
+
+(define (series a-term n)
+ (cond
+ [(zero? n) (a-term n)]
+ [else (+ (a-term n)
+ (series a-term (sub1 n)))]))
+
+;sequence : (N -> number) N -> (listof number)
+;Given a-term and n, generate the sequence of the first nth terms in a-term as a (listof numbers).
+
+(define (sequence a-term n)
+ (build-list n a-term))
+
+(define (seq-a-fives n)
+ (sequence a-fives-closed n))
+
+;arithmetic-term : N number -> (N -> number)
+;Given start and s (summand), return a function that consumes a natural number n and returns the nth-term in the arithmetic sequence.
+(define (arithmetic-term start s)
+ (local ((define (a-term n)
+ (+ (* n s) start)))
+ a-term))
+
+(define a-fives2 (arithmetic-term 8 5))
+(define evens (arithmetic-term 0 2))
+
+;g-fives : N -> number
+;Recursively returns the nth term of the geometric sequence: 3, 15, 75, 275, ...
+(define (g-fives n)
+ (cond
+ [(zero? n) 3]
+ [else (* 5 (g-fives (sub1 n)))]))
+
+;g-fives-closed : N -> number
+;Non-recursively returns the nth term of the geometric sequence: 3, 15, 75, 275, ...
+(define (g-fives-closed n)
+ (* (expt 5 n) 3))
+
+;seq-g-fives : N -> (listof numbers)
+;Given n, returns a list of the first n-th terms in the g-fives sequence.
+
+(define (seq-g-fives n)
+ (build-list n g-fives-closed))
+
+;geometric-series : number number -> (N -> number)
+;Given start and s, returns a function who computes the n-th term (where n is a natural number) of the geometric series with first term start with ratio s.
+
+(define (geometric-series start s)
+ (local ((define (g-term n)
+ (* (expt s n) start)))
+ g-term))
+
+(define g-fives2 (geometric-series 3 5))
\ No newline at end of file
blob - /dev/null
blob + 512128c8188d3681090d0f6233258e33259e8d82 (mode 644)
--- /dev/null
+++ 23.2.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;a-fives : N[>=0] -> number
+;Given n, determine recursively the value of the n-th term in the series 8, 13, 18, etc. where the first term has an index 0.
+
+(define (a-fives n)
+ (cond
+ [(zero? n) 8]
+ [else (+ 5 (a-fives (sub1 n)))]))
+
+;a-fives-closed : N[>=0] -> number
\ No newline at end of file
blob - /dev/null
blob + 4233abfddd5223ce74ca1cb93844468b4511f408 (mode 644)
--- /dev/null
+++ 23.3.6
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;! : N -> number
+;Computes the factorial of n.
+
+(define (! n)
+ (cond
+ [(zero? n) 1]
+ [else (* n (! (sub1 n)))]))
+
+;series : (N[>=0] -> number) N[>=0] -> number
+;Given a-term and n, determine the sum of the first n-th terms in the sequence a-term.
+
+(define (series a-term n)
+ (cond
+ [(zero? n) (a-term n)]
+ [else (+ (a-term n)
+ (series a-term (sub1 n)))]))
+
+;;e-taylor : N -> number
+;;Given i, find the i-th term of the Taylor series e^x = 1 + x + (x^2)/2! ...
+
+;e-power : number N -> number
+;e-power computes the x-th power of e by summing up n terms of the Taylor sequence.
+
+(define (e-power x n)
+ (local ((define (e-taylor i)
+ (/ (expt x i) (! i))))
+ (series e-taylor n)))
+
+#|
+
+(define (inexact-e-power x n)
+ (exact->inexact (e-power x n)))
+
+(inexact-e-power 1 1000)
+(exp 1)
+(- (inexact-e-power 1 100) (exp 1))
+|#
+
+;ln-taylor : N -> number
+;Computes the n-th term of the taylor sequence for ln (x).
+
+;ln-x : number N -> number
+;Computes ln(x) by summing the first n-th terms of the Taylor sequence.
+
+(define (ln-x x n)
+ (local ((define (ln-taylor i)
+ (* 2 (/ (expt (/ (- x 1)
+ (+ x 1))
+ (+ (* 2 i) 1))
+ (+ (* 2 i) 1)))))
+ (series ln-taylor n)))
+
+;sin-x : number N -> number
+;Determines sin(x) by summing the first n-th terms of the Taylor sequence.
+
+;sin-taylor : N -> number
+;Returns the i-th term of the Taylor sequence for sin(x).
+
+(define (sin-x x n)
+ (local ((define (sin-taylor i)
+ (* (/ (expt x (+ (* 2 i) 1))
+ (! (+ (* 2 i) 1)))
+ (cond
+ [(even? i) 1]
+ [(odd? i) -1]))))
+ (series sin-taylor n)))
+
+;pi-greg : N -> number
+;Calculates pi by summing the first n-th terms of the Taylor sequence.
+
+;greg : N -> number
+;Given i, find the n-th term of the greg series.
+
+(define (pi-greg n)
+ (local ((define (greg i)
+ (* 4 (* (/ 1
+ (+ (* 2 i)
+ 1))
+ (cond
+ [(even? i) 1]
+ [(odd? i) -1])))))
+ (series greg n)))
\ No newline at end of file
blob - /dev/null
blob + 7dd6e8fb310cbf41baa49f074dd935e36646d184 (mode 644)
--- /dev/null
+++ 23.3.6~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;e-taylor : N -> number
\ No newline at end of file
blob - /dev/null
blob + cab9ed53f97a61bbde9e5f71bcad17dafdc0b737 (mode 644)
--- /dev/null
+++ 23.4.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "graphing.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "graphing.ss" "teachpack" "htdp")))))
+;integrate-kepler : (number -> number) number number
+;Integrate f from left to right according to kepler's rule (split the curve into two trapezoids and evaluate the area of the trapezoids).
+
+(define (integrate-kepler f left right)
+ (local ((define average (/ (- right left) 2))
+ (define midpoint (+ left average)))
+ (+ (area-of-trapezoid average (f left) (f midpoint))
+ (area-of-trapezoid average (f midpoint) (f right)))))
+
+;area-of-trapezoid : number number number -> number
+;Given the width, height1, and height2, compute the area of the trapezoid according to the formula A = width * (1/2) * (height1 + height2).
+(define (area-of-trapezoid width height1 height2)
+ (* width 1/2 (+ height1 height2)))
+
+#|
+(define (y=x x)
+ x)
+(define (y=x2 x)
+ (sqr x))
+(define (y=x3 x)
+ (expt x 3))
+|#
+
+;series : (N[>=0] -> number) N[>=0] -> number
+;Given a-term and n, determine the sum of the first n-th terms in the sequence a-term.
+
+(define (series a-term n)
+ (cond
+ [(zero? n) (a-term n)]
+ [else (+ (a-term n)
+ (series a-term (sub1 n)))]))
+
+;integrate : (number -> number) number number number
+;Divide the interval between left and right into R rectangles and approximate the area under the curve by the sum of the area of the rectangles with their height taken at the midpoint. integrate sums the area of the rectangles, with the first rectangle given an index of 0, and the last, R-1.
+
+;area-of-rectangle : N -> number
+;Find the area of the i-th rectangle, with the first rectangle given an index of 0.
+
+;midpoint : N -> number
+;Find the midpoint of the i-th rectangle, where the first rectangle has an index of 0.
+
+(define (integrate f left right R)
+ (local ((define width (/ (- right left) R))
+ (define step (/ width 2))
+ (define (area-of-rectangle i)
+ (* width (f (midpoint i))))
+ (define (midpoint i)
+ (cond
+ [(zero? i) (+ left step)]
+ [else (+ width (midpoint (sub1 i)))])))
+ (series area-of-rectangle (- R 1))))
+
+(define (y1 x) (+ x 4))
+(define (y2 x) (- 4 x))
+(define (y3 x) (+ x 10))
+(define (y4 x) (- 10 x))
+(define (y5 x) 12)
+
+(define listofeqns (list y1
+ y2
+ y3
+ y4
+ y5))
+(define listofcolors '(blue
+ red
+ black
+ green
+ orange
+ purple))
+
+;binarymap : (X Y -> Z) (listof X) (listof Y) -> (listof Z)
+;Maps alox and aloy simultaneously, together, to aloz using operator.
+(define (binarymap operator alox aloy)
+ (cond
+ [(empty? alox) empty]
+ [else (cons (operator (first alox) (first aloy))
+ (binarymap operator (rest alox) (rest aloy)))]))
+
+;(binarymap graph-line listofeqns listofcolors)
+
+;line-from-point+slope : posn number -> (number -> number)
+;Given point and slope, return a function that represents the desired line.
+
+(define (line-from-point+slope point slope)
+ (local ((define (f x)
+ (+ (* slope
+ (- x (posn-x point)))
+ (posn-y point))))
+ f))
+
+(define y=x+4 (line-from-point+slope (make-posn 0 4) 1))
+
+#|
+(graph-line y=x+4 'green)
+(graph-line y1 'black)
+|#
+
+(define (y0 x)
+ (+ (sqr x) (* -4 x) 7))
+
+;secant-line : (number -> number) number number -> (number -> number)
+;Given f, e, and x, returns the function that corresponds to the line that passes through (x-e, f(x-e)) and (x+e, f(x+e)) (ie, the secant line).
+
+(define (secant-line f e x)
+ (local ((define a-slope (/ (- (f (+ x e))
+ (f (- x e)))
+ (* 2 e)))
+ (define a-point (make-posn (- x e)
+ (f (- x e)))))
+ (line-from-point+slope a-point a-slope)))
+
+;(graph-fun y0 'purple)
+;(graph-line (secant-line y0 0.5 3) 'green)
+
+#|
+
+;d/dx : (number -> number) -> (number -> number)
+;Returns f', the slope of f.
+
+(define (d/dx f)
+ (local ((define (slope x) (/ (- (f (+ x e))
+ (f (- x e)))
+ (* 2 e)))
+ (define e 0.01))
+ slope))
+|#
+
+;d/dx : (number -> number) number -> (number -> number)
+;Returns f', the slope of f, given epsilon e.
+
+(define (d/dx f e)
+ (local ((define (slope x) (/ (- (f (+ x e))
+ (f (- x e)))
+ (* 2 e))))
+ slope))
+
+
+;line-from-two-points : posn posn -> (number -> number)
+;Given p1 and p2, return a function that represents the line.
+
+(define (line-from-two-points p1 p2)
+ (cond
+ [(zero? (- (posn-x p2) (posn-x p1))) (error 'line-from-two-points "vertical line")]
+ [else (local ((define slope (/ (- (posn-y p2) (posn-y p1))
+ (- (posn-x p2) (posn-x p1))))
+ (define a-line (line-from-point+slope p1 slope))
+ (define (f x)
+ (a-line x)))
+ f)]))
+
+(define y6 (line-from-two-points (make-posn 2 3)
+ (make-posn 2.3 8)))
+
+(graph-line y6 'black)
+
+(define (y7 x)
+ (+ (* 1/60 (* x x x))
+ (* -1/10 (* x x))
+ 5))
+
+(define a-slope (d/dx y7 2))
+(define b-slope (d/dx y7 1))
+(define c-slope (d/dx y7 0.5))
+(list (a-slope 4)
+ (b-slope 4)
+ (c-slope 4))
\ No newline at end of file
blob - /dev/null
blob + dae3d5d18340432db82abb0b29b01c54924a3695 (mode 644)
--- /dev/null
+++ 23.4.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.4|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+integrate-kepler : (number -> number) number number
+Integrate f from left to right according to kepler's rule (split the curve into two trapezoids and evaluate the area of the trapezoids).
+
+(define (integrate-kepler f left right))
+
+area-of-trapezoid : number number number -> number
+Given the width, height1, and height2, compute the area of the trapezoid according to the formula A = width * (1/2) * (height1 + height2).
+(define (area-of-trapezoid width height1 height2)
+ (* width 1/2 (+ height1 height2)))
\ No newline at end of file
blob - /dev/null
blob + cf31b1ed7c1b336d13af86d62d4f297ca55ac9d4 (mode 644)
--- /dev/null
+++ 25.1.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define-struct ball (radius x y delta-x delta-y color))
+
+;A ball is a structure
+;(make-ball number number number number number symbol)
+
+;draw-and-clear-ball : ball -> true
+(define (draw-and-clear-ball a-ball)
+ (and (draw-solid-disk (make-posn (ball-x a-ball)
+ (ball-y a-ball))
+ (ball-radius a-ball)
+ (ball-color a-ball))
+ (sleep-for-a-while DELAY)
+ (clear-solid-disk (make-posn (ball-x a-ball)
+ (ball-y a-ball))
+ (ball-radius a-ball)
+ (ball-color a-ball))))
+
+;move-ball : ball -> ball
+(define (move-ball a-ball)
+ (make-ball (ball-radius a-ball)
+ (+ (ball-x a-ball) (ball-delta-x a-ball))
+ (+ (ball-y a-ball) (ball-delta-y a-ball))
+ (ball-delta-x a-ball)
+ (ball-delta-y a-ball)
+ (ball-color a-ball)))
+
+;out-of-bounds? : ball -> boolean
+(define (out-of-bounds? a-ball)
+ (not (and (<= 0 (ball-x a-ball) WIDTH)
+ (<= 0 (ball-y a-ball) HEIGHT))))
+
+;move-until-out : ball -> true
+;Move the ball until it is out of bounds.
+
+(define (move-until-out a-ball)
+ (cond
+ [(out-of-bounds? a-ball) true]
+ [(draw-and-clear-ball a-ball) (move-until-out (move-ball a-ball))]))
+
+(define VOLLEYBALL (make-ball 20 0 0 5 2 'black))
+(define BEACHBALL (make-ball 50 25 25 3 2 'green))
+(define BASEBALL (make-ball 10 470 470 -10 -14 'blue))
+(define TENNISBALL (make-ball 8 470 20 -6 8 'yellow))
+
+(define LISTOFBALLS (list VOLLEYBALL
+ BEACHBALL
+ BASEBALL
+ TENNISBALL))
+
+
+;move-balls : (listof balls) -> true
+;Moves alob (listof balls).
+
+(define (move-balls alob)
+ (andmap move-until-out alob))
+
+;move-simultaneous : (listof balls) -> true
+;Moves alob simultaneously.
+
+(define (move-simultaneous alob)
+ (cond
+ [(andmap out-of-bounds? alob) true]
+ [else (and (andmap draw-and-clear-ball alob)
+ (move-simultaneous (map move-ball alob)))]))
+
+(define WIDTH 500)
+(define HEIGHT 500)
+(define DELAY 1)
+(start WIDTH HEIGHT)
+;(move-balls LISTOFBALLS)
+(move-simultaneous LISTOFBALLS)
+(stop)
blob - /dev/null
blob + ca1e4a9eca14da2e79e26ca47ac4aeeba782cbed (mode 644)
--- /dev/null
+++ 25.1.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define-struct ball (radius x y delta-x delta-y color))
+
+;A ball is a structure
+;(make-ball number number number number number symbol)
+
+;draw-and-clear-ball : ball -> true
+(define (draw-and-clear-ball a-ball)
+ (and (draw-solid-disk (make-posn (ball-x a-ball)
+ (ball-y a-ball))
+ (ball-radius a-ball)
+ (ball-color a-ball))
+ (sleep-for-a-while DELAY)
+ (clear-solid-disk (make-posn (ball-x a-ball)
+ (ball-y a-ball))
+ (ball-radius a-ball)
+ (ball-color a-ball))))
+
+
+;move-ball : ball -> ball
+(define (move-ball a-ball)
+ (make-ball (ball-radius a-ball)
+ (+ (ball-x a-ball) (ball-delta-x a-ball))
+ (+ (ball-y a-ball) (ball-delta-y a-ball))
+ (ball-delta-x a-ball)
+ (ball-delta-y a-ball)
+ (ball-color a-ball)))
+
+out-of-bounds? : ball -> boolean
+(define (out-of-bounds? a-ball)
+ (not (and (<= 0 (ball-x a-ball) WIDTH)
+ (<= 0 (ball-y a-ball) HEIGHT))))
+
+;(define VOLLEYBALL (make-ball 20 0 0 5 2 'black))
+
+(define WIDTH 500)
+(define HEIGHT 0.05)
+(define DELAY 5)
+(start WIDTH HEIGHT)
\ No newline at end of file
blob - /dev/null
blob + e89f821a5776965ee78fdbd28fac0d13f75ef5c7 (mode 644)
--- /dev/null
+++ 25.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define THRESHOLD 5)
+
+;qsort : (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort alon)
+ (cond
+ [(empty? alon) empty]
+ [(empty? (rest alon)) (list (first alon))]
+ [(<= (length alon) THRESHOLD) (srt alon)]
+ [else (append (qsort (smaller-items (first alon) (rest alon)))
+ (list (first alon))
+ (qsort (larger-items (first alon) (rest alon))))]))
+
+;smaller-items : number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon less than or equal to anumber.
+
+(define (smaller-items anumber alon)
+ (filter (lambda (x) (<= x anumber)) alon))
+
+;larger-items : number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon larger than anumber.
+
+(define (larger-items anumber alon)
+ (filter (lambda (x) (> x anumber)) alon))
+
+;; sort : list-of-numbers -> list-of-numbers (sorted)
+;; to create a list of numbers with the same numbers as
+;; alon sorted in descending order
+(define (srt alon)
+ (cond
+ [(empty? alon) empty]
+ [(cons? alon) (insert (first alon) (srt (rest alon)))]))
+
+;; insert : number list-of-numbers (sorted) -> list-of-numbers (sorted)
+;; to create a list of numbers from n and the numbers on
+;; alon that is sorted in descending order; alon is sorted
+(define (insert n alon)
+ (cond
+ [(empty? alon) (cons n empty)]
+ [else (cond
+ [(<= n (first alon)) (cons n alon)]
+ [(> n (first alon)) (cons (first alon) (insert n (rest alon)))])]))
blob - /dev/null
blob + 735e1e76ab37f82ecb89c1263ce8bc12ec19355a (mode 644)
--- /dev/null
+++ 25.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;qsort : (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (append (qsort (filter (lambda (x) (<= x (first alon)))
+ (rest alon)))
+ (list (first alon))
+ (qsort (filter (lambda (x) (> x (first alon)))
+ (rest alon))))]))
\ No newline at end of file
blob - /dev/null
blob + 905fb7efb2e00d2eae661a5724acb5b9f0ebacf7 (mode 644)
--- /dev/null
+++ 25.2.6
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define THRESHOLD 5)
+
+;qsort : (number -> number) (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort operator alon)
+ (cond
+ [(empty? alon) empty]
+ [(empty? (rest alon)) (list (first alon))]
+ [(<= (length alon) THRESHOLD) (srt alon)]
+ [else (append (qsort operator (filter-items operator (first alon) (rest alon)))
+ (list (first alon))
+ (qsort operator (remaining-items operator (first alon) (rest alon))))]))
+
+;filter-items : (number -> number) number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon such that (operator x anumber) holds true, where x is a number in alon.
+
+(define (filter-items operator anumber alon)
+ (filter (lambda (x) (operator x anumber)) alon))
+
+;remaining-items : (number -> number) number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon where (operator x anumber) is false, where x is a number in alon.
+
+(define (remaining-items operator anumber alon)
+ (filter (lambda (x) (not (operator x anumber))) alon))
+
+;; sort : list-of-numbers -> list-of-numbers (sorted)
+;; to create a list of numbers with the same numbers as
+;; alon sorted in descending order
+(define (srt alon)
+ (cond
+ [(empty? alon) empty]
+ [(cons? alon) (insert (first alon) (srt (rest alon)))]))
+
+;; insert : number list-of-numbers (sorted) -> list-of-numbers (sorted)
+;; to create a list of numbers from n and the numbers on
+;; alon that is sorted in descending order; alon is sorted
+(define (insert n alon)
+ (cond
+ [(empty? alon) (cons n empty)]
+ [else (cond
+ [(<= n (first alon)) (cons n alon)]
+ [(> n (first alon)) (cons (first alon) (insert n (rest alon)))])]))
blob - /dev/null
blob + 905fb7efb2e00d2eae661a5724acb5b9f0ebacf7 (mode 644)
--- /dev/null
+++ 25.2.6-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define THRESHOLD 5)
+
+;qsort : (number -> number) (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort operator alon)
+ (cond
+ [(empty? alon) empty]
+ [(empty? (rest alon)) (list (first alon))]
+ [(<= (length alon) THRESHOLD) (srt alon)]
+ [else (append (qsort operator (filter-items operator (first alon) (rest alon)))
+ (list (first alon))
+ (qsort operator (remaining-items operator (first alon) (rest alon))))]))
+
+;filter-items : (number -> number) number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon such that (operator x anumber) holds true, where x is a number in alon.
+
+(define (filter-items operator anumber alon)
+ (filter (lambda (x) (operator x anumber)) alon))
+
+;remaining-items : (number -> number) number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon where (operator x anumber) is false, where x is a number in alon.
+
+(define (remaining-items operator anumber alon)
+ (filter (lambda (x) (not (operator x anumber))) alon))
+
+;; sort : list-of-numbers -> list-of-numbers (sorted)
+;; to create a list of numbers with the same numbers as
+;; alon sorted in descending order
+(define (srt alon)
+ (cond
+ [(empty? alon) empty]
+ [(cons? alon) (insert (first alon) (srt (rest alon)))]))
+
+;; insert : number list-of-numbers (sorted) -> list-of-numbers (sorted)
+;; to create a list of numbers from n and the numbers on
+;; alon that is sorted in descending order; alon is sorted
+(define (insert n alon)
+ (cond
+ [(empty? alon) (cons n empty)]
+ [else (cond
+ [(<= n (first alon)) (cons n alon)]
+ [(> n (first alon)) (cons (first alon) (insert n (rest alon)))])]))
blob - /dev/null
blob + e89f821a5776965ee78fdbd28fac0d13f75ef5c7 (mode 644)
--- /dev/null
+++ 25.2.6~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define THRESHOLD 5)
+
+;qsort : (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort alon)
+ (cond
+ [(empty? alon) empty]
+ [(empty? (rest alon)) (list (first alon))]
+ [(<= (length alon) THRESHOLD) (srt alon)]
+ [else (append (qsort (smaller-items (first alon) (rest alon)))
+ (list (first alon))
+ (qsort (larger-items (first alon) (rest alon))))]))
+
+;smaller-items : number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon less than or equal to anumber.
+
+(define (smaller-items anumber alon)
+ (filter (lambda (x) (<= x anumber)) alon))
+
+;larger-items : number (listof numbers) -> (listof numbers)
+;Returns (listof numbers) of all those numbers in alon larger than anumber.
+
+(define (larger-items anumber alon)
+ (filter (lambda (x) (> x anumber)) alon))
+
+;; sort : list-of-numbers -> list-of-numbers (sorted)
+;; to create a list of numbers with the same numbers as
+;; alon sorted in descending order
+(define (srt alon)
+ (cond
+ [(empty? alon) empty]
+ [(cons? alon) (insert (first alon) (srt (rest alon)))]))
+
+;; insert : number list-of-numbers (sorted) -> list-of-numbers (sorted)
+;; to create a list of numbers from n and the numbers on
+;; alon that is sorted in descending order; alon is sorted
+(define (insert n alon)
+ (cond
+ [(empty? alon) (cons n empty)]
+ [else (cond
+ [(<= n (first alon)) (cons n alon)]
+ [(> n (first alon)) (cons (first alon) (insert n (rest alon)))])]))
blob - /dev/null
blob + b47d83e94e6352a31e26248060a9c51006e2bf53 (mode 644)
--- /dev/null
+++ 26.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;tabulate-div : N -> (listof N)
+;;Given n, tabulates all the divisors of n starting from 1 and ending in n.
+
+;;Examples:
+
+;;(equal? (tabulate-div 5) '(1 5))
+;;(equal? (tabulate-div 10) '(1 2 5 10))
+
+;;Using general list processing functions:
+;;Generate a list of integers from 1 to n who are potential divisors, then filter for those that divide evenly into n.
+
+(define (tabulate-div1 n)
+ (filter (lambda (x) (= (remainder n x) 0))
+ (build-list n (lambda (x) (+ 1 x)))))
+
+;;Using structural recursion:
+
+;;return-divisors : N N -> (listof N)
+;;returns a (listof N) which contains the list of the divisors for the number n from 1 up to d (inclusive).
+
+(define (tabulate-div2 n)
+ (local ((define (return-divisors n d)
+ (cond
+ [(= d 1) (list 1)]
+ [(= (remainder n d) 0) (cons d (return-divisors n (sub1 d)))]
+ [else (return-divisors n (sub1 d))])))
+ (reverse (return-divisors n n))))
+
+;(time (tabulate-div1 299400))
+;(time (tabulate-div2 299400))
+
+;merge-sort : (listof numbers) -> (listof numbers)
+;Sorts alon in ascending order.
+;
+;make-singles : (listof X) -> (listof (listof X))
+;Given alox, creates a listof one number lists.
+
+(define (make-singles alox)
+ (cond
+ [(empty? alox) empty]
+ [else (append (list (list (first alox)))
+ (make-singles (rest alox)))]))
+
+;merge-all-neighbors : (listof (listof X)) -> (listof X)
+;Given alolox, recursively merge neighbors to return a (listof X).
+
+;Examples:
+;(merge-all-neighbors (list (list 2 5) (list 3 9)))
+;(list 2 5 3 9)
+
+(define (merge-all-neighbors alolox)
+ (cond
+ [(cons? (first alolox))]
+ []))
\ No newline at end of file
blob - /dev/null
blob + a71e53be09f886ac6d6f66d168258652facd6282 (mode 644)
--- /dev/null
+++ 26.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + cd06e9e17d80fc0edc9c765736cb38d1ac80bb99 (mode 644)
--- /dev/null
+++ 26.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;gcd-structural : N[>=1] N[>=1] -> N
+;Determine the greatest common divisor between n and m by testing every number between 1 and (min m n), starting at (min m n).
+
+;check-divisible : N[>=1] -> N
+;Given x, check to see if m and n are divisible by x. m and n are passed into check-divisible by a binding variable outside of check-divisible.
+
+#|
+
+Examples
+(gcd-structural 5 10)
+5
+(gcd-structural 1 10)
+1
+(gcd-structural 1750 150)
+50
+
+|#
+
+(define (gcd-structural m n)
+ (local ((define (check-divisible x)
+ (cond
+ [(= x 1) 1]
+ [(and (= (remainder m x) 0)
+ (= (remainder n x) 0)) x]
+ [else (check-divisible (sub1 x))])))
+ (check-divisible (min m n))))
+
+;gcd-generative : N N -> N
+;Uses generative recursion to determine the greatest common divisor between m and n. Reduces the main problem of finding the gcd of larger and smaller into the simpler problem of finding the gcd of smaller and the remainder of the larger divided by smaller. Only one new problem is generated each recursion, resulting in no net increase in problems. The solution to the new problem is the same as the old problem. No problems need to be combined. A trivially solvable problem is the case (gcd-generative x 0) where x is a number. In this case, the answer is simply x.
+
+;Termination Argument: gcd-algol takes in larger and smaller and produces a new problem with the two new parameters smaller and (remainder larger smaller). Clearly, smaller is less than larger, and (remainder larger smaller) must necessarily be less than smaller. Hence, each new recursion produces numbers that tend to get smaller. At some point, (remainder larger smaller) must necessarily equal 0 for any given value since the recursion is strictly monotonic decreasing. At this point the generative recursion answers the trivially solvable problem.
+
+;Examples
+;(gcd-generative 10 20)
+;10
+
+;gcd-algol : N N -> N
+;Given larger and smaller, finds the greatest common divisor.
+
+(define (gcd-generative m n)
+ (local ((define (gcd-algol larger smaller)
+ (cond
+ [(= smaller 0) larger]
+ [else (gcd-algol smaller (remainder larger smaller))])))
+ (gcd-algol (max m n) (min m n))))
+
blob - /dev/null
blob + e5f119a97abf35465a72524686f4fd558a1736c7 (mode 644)
--- /dev/null
+++ 26.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;gcd-structural : N[>=1] N[>=1] -> N
+;Determine the greatest common divisor between n and m by testing every number between 1 and (min m n), starting at (min m n).
+
+(define (gcd-structural m n)
+ (check-divisible (min m n)))
+
+;check-divisible : N[>=1] -> N
+Given x, check to see if m and n are divisible by x. m and n are passed into check-divisible by a binding variable outside of check-divisible.
+
+(define (check-divisible x)
+ (cond
+ [(= x 1) 1]
+ []))
\ No newline at end of file
blob - /dev/null
blob + 9d371cdf791e0ab876831cb4bdd9c530f389aa9b (mode 644)
--- /dev/null
+++ 26.3.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;qsort : (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (append (qsort (filter (lambda (x) (< x (first alon)))
+ (rest alon)))
+ (list (first alon))
+ (qsort (filter (lambda (x) (> x (first alon)))
+ (rest alon))))]))
+
+qsort-filter : (number number -> boolean) number (listof numbers) -> (listof numbers)
+Returns a (listof numbers) for all numbers in alon that when compared to anumber satisfies (filter number alon).
+
+(define (filter-qsort operator anumber alon)
+
+(filter (lambda (x) (< x (first alon)))
+ (rest alon))
\ No newline at end of file
blob - /dev/null
blob + e141162291dfe961be622c34a2937c5e0841a8a7 (mode 644)
--- /dev/null
+++ 26.3.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;qsort : (listof number) -> (listof number)
+;Uses generative recursion to quickly sort alon.
+
+(define (qsort alon)
+ (cond
+ [(empty? alon) empty]
+ [else (append (qsort )
+ (list (first alon))
+ (qsort (filter (lambda (x) (> x (first alon)))
+ (rest alon))))]))
+
+qsort-filter : (number number -> boolean) number (listof numbers) -> (listof numbers)
+Returns a (listof numbers) for all numbers in alon that when compared to anumber satisfies (filter number alon).
+
+(define (filter-qsort operator anumber alon)
+
+(filter (lambda (x) (< x (first alon)))
+ (rest alon))
\ No newline at end of file
blob - /dev/null
blob + 3f94f30387f8af12b1907158c50718f046fd90cb (mode 644)
--- /dev/null
+++ 26.3.5
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |26.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+1. (quick-sort (list 10 6 8 9 14 12 3 11 14 16 2))
+2. (append (quick-sort (list 6 8 9 3 2))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+3. (append (append (quick-sort (list 3 2))
+ 6
+ (quick-sort (list 8 9)))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+4. (append (append (append (quick-sort (list 2))
+ 3
+ empty)
+ 6
+ (quick-sort (list 8 9)))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+
+5. (append (append (append (list 2)
+ 3
+ empty)
+ 6
+ (quick-sort (list 8 9)))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+
+6. (append (append (list 2 3)
+ 6
+ (quick-sort (list 8 9)))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+7. (append (append (list 2 3)
+ 6
+ (append empty
+ 8
+ (quick-sort (list 9))))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+
+8. (append (append (list 2 3)
+ 6
+ (append empty
+ 8
+ (list 9)))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+9. (append (append (list 2 3)
+ 6
+ (list 8 9))
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+
+10. (append '(2 3 6 8 9)
+ 10
+ (quick-sort (list 14 12 11 14 16)))
+
+11. (append '(2 3 6 8 9)
+ 10
+ (append (quick-sort (list 12 11 14))
+ 14
+ (quick-sort (list 16))))
+12. (append '(2 3 6 8 9)
+ 10
+ (append (append (quick-sort (list 11))
+ 12
+ (quick-sort (list 14)))
+ 14
+ (quick-sort (list 16))))
+13. (append '(2 3 6 8 9)
+ 10
+ (append (append (list 11)
+ 12
+ (quick-sort (list 14)))
+ 14
+ (quick-sort (list 16))))
+14. (append '(2 3 6 8 9)
+ 10
+ (append (append (list 11)
+ 12
+ (list 14))
+ 14
+ (quick-sort (list 16))))
+
+15. (append '(2 3 6 8 9)
+ 10
+ (append '(11 12 14)
+ 14
+ (quick-sort (list 16))))
+
+16. (append '(2 3 6 8 9)
+ 10
+ (append '(11 12 14)
+ 14
+ (list 16)))
+17. (append '(2 3 6 8 9)
+ 10
+ (append '(11 12 14)
+ 14
+ '(16)))
+18. (append '(2 3 6 8 9)
+ 10
+ '(11 12 14 14 16))
+19. '(2 3 6 8 9 10 11 12 14 14 16)
+
+The number of appends and quick-sorts is each (- (length alon) 1), or (- N 1).
+
+(quick-sort (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14))
+(append empty
+ 1
+ (quick-sort (list 2 3 4 5 6 7 8 9 10 11 12 13 14)))
+
+(append empty
+ 1
+ (append empty
+ 2
+ (quick-sort (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14))
+ (quick-sort (list 3 4 5 6 7 8 9 10 11 12 13 14))))
\ No newline at end of file
blob - /dev/null
blob + 6549704f2bf09ee463e6c13541728b57c6d7bd40 (mode 644)
--- /dev/null
+++ 27.1.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; sierpinski : posn posn posn symbol -> true
+;; Given a, b, and c (posns), draw the triangle specified by the 3 posns and color and then use generative recursion to draw the nested triangles. Return true once the triangles become too small to draw.
+
+(define (sierpinski a b c color)
+ (local ((define a-b (midpoint a b))
+ (define a-c (midpoint a c))
+ (define b-c (midpoint b c)))
+ (cond
+ [(too-small? a b c) true]
+ [else (and (draw-triangle (round-posn a-b)
+ (round-posn b-c)
+ (round-posn a-c) color)
+ (sierpinski a a-b a-c color)
+ (sierpinski b a-b b-c color)
+ (sierpinski c a-c b-c color))])))
+
+;round-posn : posn -> posn
+;Rounds a posn x to the nearest integer
+
+(define (round-posn p)
+ (make-posn (inexact->exact (round (posn-x p)))
+ (inexact->exact (round (posn-y p)))))
+
+;draw-triangle : posn posn posn -> true
+;Draw the triangle that contains a, b, and c as vertices.
+
+(define (draw-triangle a b c color)
+ (and (draw-solid-line a b color)
+ (draw-solid-line b c color)
+ (draw-solid-line c a color)))
+
+;midpoint : posn posn -> posn
+;Given a, b, find the midpoint of the two posns.
+
+(define (midpoint a b)
+ (make-posn (/ (+ (posn-x a) (posn-x b)) 2)
+ (/ (+ (posn-y a) (posn-y b)) 2)))
+
+;too-small? : posn posn posn -> boolean
+;Given a, b, c, determine if the triangle is too small. A triangle is too small if the area of the given triangle is less than MINAREA.
+
+(define MINAREA 10)
+
+(define (too-small? a b c)
+ (< (area-of-triangle a b c) MINAREA))
+
+;area-of-triangle : posn posn posn -> number
+;Given a, b, c, determine the area of the triangle. (uses Heron's formula)
+
+(define (area-of-triangle a b c)
+ (local ((define A (distance b c))
+ (define B (distance a c))
+ (define C (distance a b))
+ (define semiperimeter (/ (+ A B C) 2)))
+ (sqrt (* semiperimeter
+ (- semiperimeter A)
+ (- semiperimeter B)
+ (- semiperimeter C)))))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+(define CENTER (make-posn 200 200))
+(define RADIUS 200)
+
+;;circle-pt : number -> posn
+;;Given angle-ratio (ie, 120/360, 240/360, 360/360), find a position on the circle with CENTER and RADIUS as defined above.
+
+(define (circle-pt angle-ratio)
+ (local ((define theta (* angle-ratio 2 pi)))
+ (make-posn (+ (posn-x CENTER)
+ (* RADIUS (cos theta)))
+ (- (posn-y CENTER)
+ (* RADIUS (sin theta))))))
+
+(define A (circle-pt 120/360))
+(define B (circle-pt 240/360))
+(define C (circle-pt 360/360))
+
+(define WIDTH 400)
+(define HEIGHT 400)
+(start WIDTH HEIGHT)
+
+(draw-circle CENTER RADIUS 'black)
+(draw-solid-disk A 5 'green)
+(draw-solid-disk B 5 'blue)
+(draw-solid-disk C 5 'purple)
+
+#|
+(define WIDTH 1000)
+(define HEIGHT 1000)
+
+(define x1 (make-posn 0 (round (inexact->exact HEIGHT))))
+(define x2 (make-posn (round (inexact->exact WIDTH))
+ (round (inexact->exact HEIGHT))))
+(define x3 (make-posn (round (inexact->exact (/ WIDTH 2)))
+ (round (inexact->exact (* HEIGHT (- 1 (/ (sqrt 3)
+ 2)))))))
+
+(start WIDTH HEIGHT)
+(sierpinski x1 x2 x3 'black)
+
+|#
\ No newline at end of file
blob - /dev/null
blob + d6ea4fd406982e635069e704f9db2e7b9d58430b (mode 644)
--- /dev/null
+++ 27.1.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; sierpinski : posn posn posn -> true
+;; Given a, b, and c (posns), draw the triangle specified by the 3 posns and then use generative recursion to draw the nested triangles. Return true once the triangles become too small to draw.
+
+(define (sierpinski a b c)
+ (cond
+ [(too small? a b c) true]
+ [else (and (draw-triangle a b c)
+ (sierpinski a a-b a-c)
+ (sierpinski b a-b b-c)
+ (sierpinski c a-c b-c))]))
\ No newline at end of file
blob - /dev/null
blob + a4f23d002c81feb922c5ddcc79241517fd6aaaae (mode 644)
--- /dev/null
+++ 27.1.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; sierpinski : posn posn posn symbol -> true
+;; Given a, b, and c (posns), draw the triangle specified by the 3 posns and color and then use generative recursion to draw the nested triangles. Return true once the triangles become too small to draw.
+
+(define (sierpinski a b c color)
+ (local ((define a-b (midpoint a b))
+ (define a-c (midpoint a c))
+ (define b-c (midpoint b c)))
+ (cond
+ [(too-small? a b c) true]
+ [else (and (draw-triangle (round-posn a)
+ (round-posn b)
+ (round-posn c) color)
+ (sierpinski a a-b a-c color)
+ (sierpinski b a-b b-c color)
+ (sierpinski c a-c b-c color))])))
+
+;round-posn : posn -> posn
+;Rounds a posn x to the nearest integer
+
+(define (round-posn p)
+ (make-posn (inexact->exact (round (posn-x p)))
+ (inexact->exact (round (posn-y p)))))
+
+;draw-triangle : posn posn posn -> true
+;Draw the triangle that contains a, b, and c as vertices.
+
+(define (draw-triangle a b c color)
+ (and (draw-solid-line a b color)
+ (draw-solid-line b c color)
+ (draw-solid-line c a color)))
+
+;midpoint : posn posn -> posn
+;Given a, b, find the midpoint of the two posns.
+
+(define (midpoint a b)
+ (make-posn (/ (+ (posn-x a) (posn-x b)) 2)
+ (/ (+ (posn-y a) (posn-y b)) 2)))
+
+;too-small? : posn posn posn -> boolean
+;Given a, b, c, determine if the triangle is too small. A triangle is too small if the area of the given triangle is less than MINAREA.
+
+(define MINAREA 5)
+
+(define (too-small? a b c)
+ (< (area-of-triangle a b c) MINAREA))
+
+;area-of-triangle : posn posn posn -> number
+;Given a, b, c, determine the area of the triangle. (uses Heron's formula)
+
+(define (area-of-triangle a b c)
+ (local ((define A (distance b c))
+ (define B (distance a c))
+ (define C (distance a b))
+ (define semiperimeter (/ (+ A B C) 2)))
+ (sqrt (* semiperimeter
+ (- semiperimeter A)
+ (- semiperimeter B)
+ (- semiperimeter C)))))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+(define CENTER (make-posn 200 200))
+(define RADIUS 200)
+
+;;circle-pt : number -> posn
+;;Given angle-ratio (ie, 120/360, 240/360, 360/360), find a position on the circle with CENTER and RADIUS as defined above.
+
+(define (circle-pt angle-ratio)
+ (local ((define theta (* angle-ratio 2 pi)))
+ (make-posn (+ (posn-x CENTER)
+ (* RADIUS (cos theta)))
+ (- (posn-y CENTER)
+ (* RADIUS (sin theta))))))
+
+(define A (circle-pt 120/360))
+(define B (circle-pt 240/360))
+(define C (circle-pt 360/360))
+
+#|
+(define WIDTH 400)
+(define HEIGHT 400)
+(start WIDTH HEIGHT)
+
+
+
+(draw-circle CENTER RADIUS 'black)
+(draw-solid-disk A 5 'green)
+(draw-solid-disk B 5 'blue)
+(draw-solid-disk C 5 'purple)
+|#
+
+(define WIDTH 1000)
+(define HEIGHT 1000)
+
+(define x1 (make-posn 0 (round (inexact->exact HEIGHT))))
+(define x2 (make-posn (round (inexact->exact WIDTH))
+ (round (inexact->exact HEIGHT))))
+(define x3 (make-posn (round (inexact->exact (/ WIDTH 2)))
+ (round (inexact->exact (* HEIGHT (- 1 (/ (sqrt 3)
+ 2)))))))
+
+(start WIDTH HEIGHT)
+(sierpinski x1 x2 x3 'black)
+
blob - /dev/null
blob + eb3a8a7dc9d16efa1e39b2fb6740396a4ebd9cd4 (mode 644)
--- /dev/null
+++ 27.1.3-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define-struct triangle (a b c color))
+;
+;A triangle is a structure
+;(make-triangle a b c co)
+;where a, b, c are posns, and co is a symbol.
+
+;sierpinski-list : (listof triangle) -> true
+;;Given alot, draw the triangles using sierpinski. Return true once the triangles become too small to draw.
+
+(define (sierpinski-list alot)
+ (andmap (lambda (x) (sierpinski (triangle-a x)
+ (triangle-b x)
+ (triangle-c x)
+ (triangle-color x)))
+ alot))
+
+;; sierpinski : posn posn posn symbol -> true
+;; Given a, b, and c (posns), draw the triangle specified by the 3 posns and color and then use generative recursion to draw the nested triangles. Return true once the triangles become too small to draw.
+
+(define (sierpinski a b c color)
+ (local ((define a-b (midpoint a b))
+ (define a-c (midpoint a c))
+ (define b-c (midpoint b c)))
+ (cond
+ [(too-small? a b c) true]
+ [else (and (draw-triangle (round-posn a)
+ (round-posn b)
+ (round-posn c) color)
+ (sierpinski a a-b a-c color)
+ (sierpinski b a-b b-c color)
+ (sierpinski c a-c b-c color))])))
+
+;round-posn : posn -> posn
+;Rounds a posn x to the nearest integer
+
+(define (round-posn p)
+ (make-posn (round-number (posn-x p))
+ (round-number (posn-y p))))
+
+;round-number : inexact number -> exact number
+;Returns x as an exact number rounded to the nearest integer
+(define (round-number x)
+ (round (inexact->exact x)))
+
+;draw-triangle : posn posn posn -> true
+;Draw the triangle that contains a, b, and c as vertices.
+
+(define (draw-triangle a b c color)
+ (and (draw-solid-line a b color)
+ (draw-solid-line b c color)
+ (draw-solid-line c a color)))
+
+;midpoint : posn posn -> posn
+;Given a, b, find the midpoint of the two posns.
+
+(define (midpoint a b)
+ (make-posn (/ (+ (posn-x a) (posn-x b)) 2)
+ (/ (+ (posn-y a) (posn-y b)) 2)))
+
+;too-small? : posn posn posn -> boolean
+;Given a, b, c, determine if the triangle is too small. A triangle is too small if the area of the given triangle is less than MINAREA.
+
+(define MINAREA 5)
+
+(define (too-small? a b c)
+ (< (area-of-triangle a b c) MINAREA))
+
+;area-of-triangle : posn posn posn -> number
+;Given a, b, c, determine the area of the triangle. (uses Heron's formula). (sp stands for semiperimeter)
+
+(define (area-of-triangle a b c)
+ (local ((define A (distance b c))
+ (define B (distance a c))
+ (define C (distance a b))
+ (define sp (/ (+ A B C) 2)))
+ (sqrt (* sp
+ (- sp A)
+ (- sp B)
+ (- sp C)))))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+;;circle-pt : number posn number -> posn
+;;Given angle-ratio (ie, 120/360, 240/360, 360/360), find a position on the circle with center and radius as defined above.
+
+(define (circle-pt angle-ratio center radius)
+ (local ((define theta (* angle-ratio 2 pi)))
+ (make-posn (+ (posn-x center)
+ (* radius (cos theta)))
+ (- (posn-y center)
+ (* radius (sin theta))))))
+
+(define WIDTH 1000)
+(define HEIGHT 1000)
+
+(define triangle3 (list (make-triangle (make-posn 0 300)
+ (make-posn 400 300)
+ (make-posn 200 0)
+ 'black)
+ (make-triangle (make-posn 0 800)
+ (make-posn 400 800)
+ (make-posn 200 500)
+ 'green)
+ (make-triangle (make-posn 400 600)
+ (make-posn 1000 600)
+ (make-posn 700 300)
+ 'purple)))
+(start WIDTH HEIGHT)
+(sierpinski-list triangle3)
+
+;;Obsoleted code
+
+#|
+
+(define CENTER (make-posn 200 200))
+(define RADIUS 200)
+
+;;circle-pt : number -> posn
+;;Given angle-ratio (ie, 120/360, 240/360, 360/360), find a position on the circle with CENTER and RADIUS as defined above.
+
+(define (circle-pt angle-ratio)
+ (local ((define theta (* angle-ratio 2 pi)))
+ (make-posn (+ (posn-x CENTER)
+ (* RADIUS (cos theta)))
+ (- (posn-y CENTER)
+ (* RADIUS (sin theta))))))
+
+(define A (circle-pt 120/360))
+(define B (circle-pt 240/360))
+(define C (circle-pt 360/360))
+
+(define WIDTH 400)
+(define HEIGHT 400)
+(start WIDTH HEIGHT)
+
+
+
+(draw-circle CENTER RADIUS 'black)
+(draw-solid-disk A 5 'green)
+(draw-solid-disk B 5 'blue)
+(draw-solid-disk C 5 'purple)
+
+(define WIDTH 1000)
+(define HEIGHT 1000)
+
+(define x1 (make-posn 0 (round-number HEIGHT)))
+(define x2 (make-posn (round-number WIDTH)
+ (round-number HEIGHT)))
+(define x3 (make-posn (round-number (/ WIDTH 2))
+ (round-number (* HEIGHT
+ (- 1 (/ (sqrt 3) 2))))))
+
+(start WIDTH HEIGHT)
+(sierpinski x1 x2 x3 'black)
+
+(build-list 3 (lambda (x) (circle-pt (* x 120/360)
+ (make-posn 400 400)
+ 300)))
+
+|#
\ No newline at end of file
blob - /dev/null
blob + a4f23d002c81feb922c5ddcc79241517fd6aaaae (mode 644)
--- /dev/null
+++ 27.1.3-2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; sierpinski : posn posn posn symbol -> true
+;; Given a, b, and c (posns), draw the triangle specified by the 3 posns and color and then use generative recursion to draw the nested triangles. Return true once the triangles become too small to draw.
+
+(define (sierpinski a b c color)
+ (local ((define a-b (midpoint a b))
+ (define a-c (midpoint a c))
+ (define b-c (midpoint b c)))
+ (cond
+ [(too-small? a b c) true]
+ [else (and (draw-triangle (round-posn a)
+ (round-posn b)
+ (round-posn c) color)
+ (sierpinski a a-b a-c color)
+ (sierpinski b a-b b-c color)
+ (sierpinski c a-c b-c color))])))
+
+;round-posn : posn -> posn
+;Rounds a posn x to the nearest integer
+
+(define (round-posn p)
+ (make-posn (inexact->exact (round (posn-x p)))
+ (inexact->exact (round (posn-y p)))))
+
+;draw-triangle : posn posn posn -> true
+;Draw the triangle that contains a, b, and c as vertices.
+
+(define (draw-triangle a b c color)
+ (and (draw-solid-line a b color)
+ (draw-solid-line b c color)
+ (draw-solid-line c a color)))
+
+;midpoint : posn posn -> posn
+;Given a, b, find the midpoint of the two posns.
+
+(define (midpoint a b)
+ (make-posn (/ (+ (posn-x a) (posn-x b)) 2)
+ (/ (+ (posn-y a) (posn-y b)) 2)))
+
+;too-small? : posn posn posn -> boolean
+;Given a, b, c, determine if the triangle is too small. A triangle is too small if the area of the given triangle is less than MINAREA.
+
+(define MINAREA 5)
+
+(define (too-small? a b c)
+ (< (area-of-triangle a b c) MINAREA))
+
+;area-of-triangle : posn posn posn -> number
+;Given a, b, c, determine the area of the triangle. (uses Heron's formula)
+
+(define (area-of-triangle a b c)
+ (local ((define A (distance b c))
+ (define B (distance a c))
+ (define C (distance a b))
+ (define semiperimeter (/ (+ A B C) 2)))
+ (sqrt (* semiperimeter
+ (- semiperimeter A)
+ (- semiperimeter B)
+ (- semiperimeter C)))))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+(define CENTER (make-posn 200 200))
+(define RADIUS 200)
+
+;;circle-pt : number -> posn
+;;Given angle-ratio (ie, 120/360, 240/360, 360/360), find a position on the circle with CENTER and RADIUS as defined above.
+
+(define (circle-pt angle-ratio)
+ (local ((define theta (* angle-ratio 2 pi)))
+ (make-posn (+ (posn-x CENTER)
+ (* RADIUS (cos theta)))
+ (- (posn-y CENTER)
+ (* RADIUS (sin theta))))))
+
+(define A (circle-pt 120/360))
+(define B (circle-pt 240/360))
+(define C (circle-pt 360/360))
+
+#|
+(define WIDTH 400)
+(define HEIGHT 400)
+(start WIDTH HEIGHT)
+
+
+
+(draw-circle CENTER RADIUS 'black)
+(draw-solid-disk A 5 'green)
+(draw-solid-disk B 5 'blue)
+(draw-solid-disk C 5 'purple)
+|#
+
+(define WIDTH 1000)
+(define HEIGHT 1000)
+
+(define x1 (make-posn 0 (round (inexact->exact HEIGHT))))
+(define x2 (make-posn (round (inexact->exact WIDTH))
+ (round (inexact->exact HEIGHT))))
+(define x3 (make-posn (round (inexact->exact (/ WIDTH 2)))
+ (round (inexact->exact (* HEIGHT (- 1 (/ (sqrt 3)
+ 2)))))))
+
+(start WIDTH HEIGHT)
+(sierpinski x1 x2 x3 'black)
+
blob - /dev/null
blob + 6549704f2bf09ee463e6c13541728b57c6d7bd40 (mode 644)
--- /dev/null
+++ 27.1.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;; sierpinski : posn posn posn symbol -> true
+;; Given a, b, and c (posns), draw the triangle specified by the 3 posns and color and then use generative recursion to draw the nested triangles. Return true once the triangles become too small to draw.
+
+(define (sierpinski a b c color)
+ (local ((define a-b (midpoint a b))
+ (define a-c (midpoint a c))
+ (define b-c (midpoint b c)))
+ (cond
+ [(too-small? a b c) true]
+ [else (and (draw-triangle (round-posn a-b)
+ (round-posn b-c)
+ (round-posn a-c) color)
+ (sierpinski a a-b a-c color)
+ (sierpinski b a-b b-c color)
+ (sierpinski c a-c b-c color))])))
+
+;round-posn : posn -> posn
+;Rounds a posn x to the nearest integer
+
+(define (round-posn p)
+ (make-posn (inexact->exact (round (posn-x p)))
+ (inexact->exact (round (posn-y p)))))
+
+;draw-triangle : posn posn posn -> true
+;Draw the triangle that contains a, b, and c as vertices.
+
+(define (draw-triangle a b c color)
+ (and (draw-solid-line a b color)
+ (draw-solid-line b c color)
+ (draw-solid-line c a color)))
+
+;midpoint : posn posn -> posn
+;Given a, b, find the midpoint of the two posns.
+
+(define (midpoint a b)
+ (make-posn (/ (+ (posn-x a) (posn-x b)) 2)
+ (/ (+ (posn-y a) (posn-y b)) 2)))
+
+;too-small? : posn posn posn -> boolean
+;Given a, b, c, determine if the triangle is too small. A triangle is too small if the area of the given triangle is less than MINAREA.
+
+(define MINAREA 10)
+
+(define (too-small? a b c)
+ (< (area-of-triangle a b c) MINAREA))
+
+;area-of-triangle : posn posn posn -> number
+;Given a, b, c, determine the area of the triangle. (uses Heron's formula)
+
+(define (area-of-triangle a b c)
+ (local ((define A (distance b c))
+ (define B (distance a c))
+ (define C (distance a b))
+ (define semiperimeter (/ (+ A B C) 2)))
+ (sqrt (* semiperimeter
+ (- semiperimeter A)
+ (- semiperimeter B)
+ (- semiperimeter C)))))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+(define CENTER (make-posn 200 200))
+(define RADIUS 200)
+
+;;circle-pt : number -> posn
+;;Given angle-ratio (ie, 120/360, 240/360, 360/360), find a position on the circle with CENTER and RADIUS as defined above.
+
+(define (circle-pt angle-ratio)
+ (local ((define theta (* angle-ratio 2 pi)))
+ (make-posn (+ (posn-x CENTER)
+ (* RADIUS (cos theta)))
+ (- (posn-y CENTER)
+ (* RADIUS (sin theta))))))
+
+(define A (circle-pt 120/360))
+(define B (circle-pt 240/360))
+(define C (circle-pt 360/360))
+
+(define WIDTH 400)
+(define HEIGHT 400)
+(start WIDTH HEIGHT)
+
+(draw-circle CENTER RADIUS 'black)
+(draw-solid-disk A 5 'green)
+(draw-solid-disk B 5 'blue)
+(draw-solid-disk C 5 'purple)
+
+#|
+(define WIDTH 1000)
+(define HEIGHT 1000)
+
+(define x1 (make-posn 0 (round (inexact->exact HEIGHT))))
+(define x2 (make-posn (round (inexact->exact WIDTH))
+ (round (inexact->exact HEIGHT))))
+(define x3 (make-posn (round (inexact->exact (/ WIDTH 2)))
+ (round (inexact->exact (* HEIGHT (- 1 (/ (sqrt 3)
+ 2)))))))
+
+(start WIDTH HEIGHT)
+(sierpinski x1 x2 x3 'black)
+
+|#
\ No newline at end of file
blob - /dev/null
blob + 5cb5f1a1f6d8d0d7d917a9286871cde38df36ba6 (mode 644)
--- /dev/null
+++ 27.1.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;The shortest a line can be before nested savannahs will no longer be drawn
+(define MINDIST 0.5)
+
+(define (savannah-simplified start end radian)
+ (savannah start end radian 'brown 10 0.5))
+
+;savannah : posn posn radian symbol -> true
+;Given start, end, angle, and color, draw a savannah tree until the lines are too short, then return true. The savannah is drawn by drawing the first line then drawing two more smaller savannahs on the first line. savannah must necessarily terminate because each savannah is smaller than the next and the distance between start and end will shrink until it is too short to be drawn. When this occurs, the generative recursion returns true. The first line is divided into three tertiles, with a lower savannah and an upper savannah. delta-dist indicates how much the line shrinks in each recursion, and delta-radian indicates the angle by which each nested savannah branches from its parent savannah.
+
+(define (savannah start end radian color delta-dist delta-radian)
+ (local ((define lower-radian (+ radian delta-radian))
+ (define upper-radian (- radian delta-radian))
+ (define lower-start (start-lower-savannah start end))
+ (define upper-start (start-upper-savannah start end))
+ (define new-dist (- (distance start end) delta-dist))
+ (define lower-end (end-savannah lower-start lower-radian new-dist))
+ (define upper-end (end-savannah upper-start upper-radian new-dist)))
+ (cond
+ [(too-short? (distance start end)) true]
+ [else (and (draw-solid-line start
+ end
+ color)
+ (savannah lower-start
+ lower-end
+ lower-radian
+ color
+ delta-dist
+ delta-radian)
+ (savannah upper-start
+ upper-end
+ upper-radian
+ color
+ delta-dist
+ delta-radian))])))
+
+;too-short? : number -> boolean
+;Determine if the line is too short to be drawn further.
+
+(define (too-short? d)
+ (< d MINDIST))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (local ((define x1 (posn-x p1))
+ (define x2 (posn-x p2))
+ (define y1 (posn-y p1))
+ (define y2 (posn-y p2)))
+ (sqrt (+ (sqr (- x2 x1))
+ (sqr (- y2 y1))))))
+
+;start-lower-savannah : posn posn -> posn
+;Given start and end, determine the start posn of the lower savannah. Calls on savannah-tertile. The lower savannah is the bottom 1/3 tertile, hence 1/3 is used as an argument.
+
+(define (start-lower-savannah start end)
+ (savannah-tertile start end 1/3))
+
+;start-upper-savannah : posn posn -> posn
+;Given start and end, determine the start posn of the upper savannah. Calls on savannah-tertile. The upper savannah is the bottom 2/3 tertile, hence 2/3 is used as an argument.
+
+(define (start-upper-savannah start end)
+ (savannah-tertile start end 2/3))
+
+;savannah-tertile : posn posn number -> posn
+;Determines the start point of a savannah tree given start and end and tertile, which indicates in which bottom tertile the savannah lies (the lower savannah is the bottom 1/3, the upper savannah is the bottom 2/3).
+(define (savannah-tertile start end tertile)
+ (local ((define x1 (posn-x start))
+ (define x2 (posn-x end))
+ (define y1 (posn-y start))
+ (define y2 (posn-y end)))
+ (make-posn (+ x1 (* (- x2 x1) tertile))
+ (+ y1 (* (- y2 y1) tertile)))))
+
+
+;end-savannah : posn radian number -> posn
+;Given aposn, radian, and distance, determine the end posn of any savannah by calling on circle-pt, which uses trigonometry to determine where the end-point lies.
+
+(define (end-savannah aposn radian distance)
+ (circle-pt radian aposn distance))
+
+;;circle-pt : radian posn number -> posn
+;;Given theta (in radians), find a position on the circle with center and radius as defined above.
+
+(define (circle-pt theta center radius)
+ (make-posn (+ (posn-x center)
+ (* radius (cos theta)))
+ (- (posn-y center)
+ (* radius (sin theta)))))
+
+(define (positive-posn? aposn)
+ (and (positive? (posn-x aposn))
+ (positive? (posn-y aposn))))
+
+(start 1000 1000)
+(savannah-simplified (make-posn 500 600) (make-posn 500 500) (/ pi 2))
+
+
+;error when delta-dist is 30
\ No newline at end of file
blob - /dev/null
blob + 6f02d038164837dcbac98f4749e416f635f17ab8 (mode 644)
--- /dev/null
+++ 27.1.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+savannah : posn posn radian -> true
+Given start, end, and angle, draw a savannah tree until the lines are too short, then return true.
+
+(define (savannah start end radian)
+ (cond
+ [(too-short? (distance start end)) ]
+ []))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+;too-short? : number -> boolean
+;Determine if the line is too short to be drawn further.
\ No newline at end of file
blob - /dev/null
blob + 7a784a9fd0d1f3c635a1f4ac30f6c52dac6dd1e0 (mode 644)
--- /dev/null
+++ 27.1.5
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;The minimum area before the approximating triangle of the Bezier curve is drawn.
+(define MINAREA 10)
+
+;bezier : posn posn posn symbol -> true
+;Draw a smooth curve from p1 to p3, viewed from p2. In the trivial case, where the area of the triangle is very small, simply draw the triangle. When the triangle is not small, partition the larger triangle into two smaller triangles, where the first triangle is composed of p1, the midpoint of p1 and p2 (termed r2), and the midpoint between r2 and the midpoint between p2 and p3 (termed q2). The second triangle is composed of p3, q2, and the midpoint between r2 and q2. Repeat bezier on these successive triangles.
+
+(define (bezier p1 p2 p3 color)
+ (local ((define r2 (midpoint p1 p2))
+ (define q2 (midpoint p2 p3))
+ (define m (midpoint r2 q2)))
+ (cond
+ [(small-enough? p1 p2 p3) (draw-triangle p1 p2 p3 color)]
+ [else (and (bezier p1 r2 m color)
+ (bezier m q2 p3 color))])))
+
+;small-enough? : posn posn posn -> boolean
+;Determine if the triangle is small enough to draw.
+
+(define (small-enough? a b c)
+ (< (area-of-triangle a b c) MINAREA))
+
+;distance : posn posn -> number
+;Given p1, p2, determine the distance between two points.
+
+(define (distance p1 p2)
+ (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
+ (sqr (- (posn-y p2) (posn-y p1))))))
+
+;midpoint : posn posn -> posn
+;Given a, b, find the midpoint of the two posns.
+
+(define (midpoint a b)
+ (make-posn (/ (+ (posn-x a) (posn-x b)) 2)
+ (/ (+ (posn-y a) (posn-y b)) 2)))
+
+;draw-triangle : posn posn posn -> true
+;Draw the triangle that contains a, b, and c as vertices.
+
+(define (draw-triangle a b c color)
+ (and (draw-solid-line a b color)
+ (draw-solid-line b c color)
+ (draw-solid-line c a color)))
+
+;area-of-triangle : posn posn posn -> number
+;Given a, b, c, determine the area of the triangle. (uses Heron's formula)
+
+(define (area-of-triangle a b c)
+ (local ((define A (distance b c))
+ (define B (distance a c))
+ (define C (distance a b))
+ (define semiperimeter (/ (+ A B C) 2)))
+ (sqrt (* semiperimeter
+ (- semiperimeter A)
+ (- semiperimeter B)
+ (- semiperimeter C)))))
+
+(define x1 (make-posn 300 300))
+(define x2 (make-posn 400 500))
+(define x3 (make-posn 500 200))
+
+(define p1 (make-posn 50 50))
+(define p2 (make-posn 150 150))
+(define p3 (make-posn 250 100))
+
+(start 1000 1000)
+(bezier x1 x2 x3 'blue)
+(bezier p1 p2 p3 'purple)
\ No newline at end of file
blob - /dev/null
blob + 6c66a3eb8ccedda204db22a4f9d5cf89d3b697fd (mode 644)
--- /dev/null
+++ 27.1.5~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 76b5fce8bdb594fe309ed87a72e89fce53a74980 (mode 644)
--- /dev/null
+++ 27.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Exercise 27.2.1. Determine what the list-of-lines representation for empty, (list 'NL), and (list 'NL 'NL) should be. Why are these examples important test cases?
+
+;A file is either
+;1. empty or
+;2. (cons s f)
+;where s is a symbol and f is a file.
+
+;Examples
+;
+;(file->list-of-lines empty)
+;empty
+;(file->list-of-lines (list 'NL))
+;(list empty)
+;(file->list-of-lines (list 'NL 'NL))
+;(list empty empty)
+
+;The NEWLINE character is represented by 'NL
+(define NEWLINE 'NL)
+
+;file->list-of-lines : file -> (listof (listof symbols))
+;Converts a-file into a (listof (listof symbols)) representing the file. Each new list starts right at the end of a newline symbol and ends at the first occurrence of a newline symbol. file->list-of-lines uses generative recursion: the first line is appended to the front of the remainder of the file that has already been converted into a list of lines.
+;Termination Argument: Since each application of file->list-of-lines necessarily shortens the argument for the new generative recursion, the paramater must get smaller over time and eventually become the empty list, for which a trivial solution is available.
+
+(define (file->list-of-lines a-file)
+ (cond
+ [(empty? a-file) empty]
+ [else (cons (first-line a-file)
+ (file->list-of-lines (remove-first-line a-file)))]))
+
+;first-line : file -> (listof symbols)
+;Returns the first line of a-file.
+
+(define (first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) empty]
+ [else (cons (first a-file)
+ (first-line (rest a-file)))]))
+
+;remove-first-line : file -> file
+;Given a-file, remove the first line.
+
+(define (remove-first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) (rest a-file)]
+ [else (remove-first-line (rest a-file))]))
+
+(file->list-of-lines '(Hi my name is Joe NL
+ and I live in a button factory NL
+ I have a wife NL
+ and three kids NL))
\ No newline at end of file
blob - /dev/null
blob + 3d780cf8ec5d643f9c1d8f8ae616c4258847ab2a (mode 644)
--- /dev/null
+++ 27.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+Exercise 27.2.1. Determine what the list-of-lines representation for empty, (list 'NL), and (list 'NL 'NL) should be. Why are these examples important test cases?
+
+A file is either
+1. empty or
+2. (cons s f)
+where s is a symbol and f is a file.
+
blob - /dev/null
blob + 632f068577d72ed8f5736472c667d13e050ab48f (mode 644)
--- /dev/null
+++ 27.2.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Exercise 27.2.1. Determine what the list-of-lines representation for empty, (list 'NL), and (list 'NL 'NL) should be. Why are these examples important test cases?
+
+;A file is either
+;1. empty or
+;2. (cons s f)
+;where s is a symbol and f is a file.
+
+;Examples
+;
+;(file->list-of-lines empty)
+;empty
+;(file->list-of-lines (list 'NL))
+;(list empty)
+;(file->list-of-lines (list 'NL 'NL))
+;(list empty empty)
+
+;The NEWLINE character is represented by 'NL
+(define NEWLINE 'NL)
+
+;file->list-of-lines : file -> (listof (listof symbols))
+;Converts a-file into a (listof (listof symbols)) representing the file. Each new list starts right at the end of a newline symbol and ends at the first occurrence of a newline symbol. file->list-of-lines uses generative recursion: the first line is appended to the front of the remainder of the file that has already been converted into a list of lines.
+;Termination Argument: Since each application of file->list-of-lines necessarily shortens the argument for the new generative recursion, the paramater must get smaller over time and eventually become the empty list, for which a trivial solution is available.
+
+;first-line : file -> (listof symbols)
+;Returns the first line of a-file.
+
+;remove-first-line : file -> file
+;Given a-file, remove the first line.
+
+(define (file->list-of-lines a-file)
+ (local ((define (first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) empty]
+ [else (cons (first a-file)
+ (first-line (rest a-file)))]))
+ (define (remove-first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) (rest a-file)]
+ [else (remove-first-line (rest a-file))])))
+ (cond
+ [(empty? a-file) empty]
+ [else (cons (first-line a-file)
+ (file->list-of-lines (remove-first-line a-file)))])))
+
+
+(file->list-of-lines '(Hi my name is Joe NL
+ and I live in a button factory NL
+ I have a wife NL
+ and three kids NL))
\ No newline at end of file
blob - /dev/null
blob + 76b5fce8bdb594fe309ed87a72e89fce53a74980 (mode 644)
--- /dev/null
+++ 27.2.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Exercise 27.2.1. Determine what the list-of-lines representation for empty, (list 'NL), and (list 'NL 'NL) should be. Why are these examples important test cases?
+
+;A file is either
+;1. empty or
+;2. (cons s f)
+;where s is a symbol and f is a file.
+
+;Examples
+;
+;(file->list-of-lines empty)
+;empty
+;(file->list-of-lines (list 'NL))
+;(list empty)
+;(file->list-of-lines (list 'NL 'NL))
+;(list empty empty)
+
+;The NEWLINE character is represented by 'NL
+(define NEWLINE 'NL)
+
+;file->list-of-lines : file -> (listof (listof symbols))
+;Converts a-file into a (listof (listof symbols)) representing the file. Each new list starts right at the end of a newline symbol and ends at the first occurrence of a newline symbol. file->list-of-lines uses generative recursion: the first line is appended to the front of the remainder of the file that has already been converted into a list of lines.
+;Termination Argument: Since each application of file->list-of-lines necessarily shortens the argument for the new generative recursion, the paramater must get smaller over time and eventually become the empty list, for which a trivial solution is available.
+
+(define (file->list-of-lines a-file)
+ (cond
+ [(empty? a-file) empty]
+ [else (cons (first-line a-file)
+ (file->list-of-lines (remove-first-line a-file)))]))
+
+;first-line : file -> (listof symbols)
+;Returns the first line of a-file.
+
+(define (first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) empty]
+ [else (cons (first a-file)
+ (first-line (rest a-file)))]))
+
+;remove-first-line : file -> file
+;Given a-file, remove the first line.
+
+(define (remove-first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) (rest a-file)]
+ [else (remove-first-line (rest a-file))]))
+
+(file->list-of-lines '(Hi my name is Joe NL
+ and I live in a button factory NL
+ I have a wife NL
+ and three kids NL))
\ No newline at end of file
blob - /dev/null
blob + b25f3a46f05efc14d58c91caa6bcbd8415fc757d (mode 644)
--- /dev/null
+++ 27.2.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Exercise 27.2.1. Determine what the list-of-lines representation for empty, (list 'NL), and (list 'NL 'NL) should be. Why are these examples important test cases?
+
+;A file is either
+;1. empty or
+;2. (cons s f)
+;where s is a symbol and f is a file.
+
+;Examples
+;
+;(file->list-of-lines empty)
+;empty
+;(file->list-of-lines (list 'NL))
+;(list empty)
+;(file->list-of-lines (list 'NL 'NL))
+;(list empty empty)
+
+;The NEWLINE character is represented by 'NL
+(define NEWLINE 'NL)
+
+;file->list-of-lines : file -> (listof (listof symbols))
+;Converts a-file into a (listof (listof symbols)) representing the file. Each new list starts right at the end of a newline symbol and ends at the first occurrence of a newline symbol. file->list-of-lines uses generative recursion: the first line is appended to the front of the remainder of the file that has already been converted into a list of lines.
+;Termination Argument: Since each application of file->list-of-lines necessarily shortens the argument for the new generative recursion, the paramater must get smaller over time and eventually become the empty list, for which a trivial solution is available.
+
+;first-line : file -> (listof symbols)
+;Returns the first line of a-file.
+
+;remove-first-line : file -> file
+;Given a-file, remove the first line.
+
+(define (file->list-of-lines a-file)
+ (local ((define (first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) empty]
+ [else (cons (first a-file)
+ (first-line (rest a-file)))]))
+ (define (remove-first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) (rest a-file)]
+ [else (remove-first-line (rest a-file))])))
+ (cond
+ [(empty? a-file) empty]
+ [else (cons (first-line a-file)
+ (file->list-of-lines (remove-first-line a-file)))])))
+
+
+;(file->list-of-lines '(Hi my name is Joe NL
+; and I live in a button factory NL
+; I have a wife NL
+; and three kids NL))
+;
+;A file of numbers (fon) is either
+;1. empty, or
+;2. (cons N F),
+;3. (cons 'NL F)
+;where N is a number and F is a file.
+
+(define-struct rr (table costs))
+;
+;A restaurant is a structure
+;(make-rr ta co)
+;where ta is a number and co is a (listof numbers).
+;
+;file->list-of-checks : fon -> (listof rr)
+;Given afon, file->list-of-checks converts afon into a (listof rr). The first number in each line in afon represents the table number and the remaining numbers up to the NEWLINE represent the costs per table. We again use generative recursion. First, we create an rr structure with the first table and its associated costs, and then we append that to the beginning of an already-created (listof rr) of the remaining file-of-numbers.
+;Termination Argument: each file that is passed into file->list-of-checks must necessary get smaller and ultimately reach empty since one line is removed every recursion.
+;
+;Examples
+;
+;(equal? (file->list-of-checks
+; (list 1 2.30 4.00 12.50 13.50 'NL
+; 2 4.00 18.00 'NL
+; 4 2.30 12.50))
+; (list (make-rr 1 (list 2.30 4.00 12.50 13.50))
+; (make-rr 2 (list 4.00 18.00))
+; (make-rr 4 (list 2.30 12.50))))
+
+(define (file->list-of-checks afon)
+ (cond
+ [(empty? afon) empty]
+ [(and (symbol? (first afon))
+ (symbol=? NEWLINE (first afon))) (file->list-of-checks (remove-first-line afon))]
+ [else (cons (make-rr (first-table afon)
+ (first-costs afon))
+ (file->list-of-checks (remove-first-line afon)))]))
+
+(define (remove-first-line a-file)
+ (cond
+ [(empty? a-file) empty]
+ [(and (symbol? (first a-file))
+ (symbol=? NEWLINE (first a-file))) (rest a-file)]
+ [else (remove-first-line (rest a-file))]))
+
+;first-table : fon -> number
+;Given afon, return the table associated with it (if (first afon) is a number, it is simply the first number--if (first afon) is empty or NEWLINE, it is empty).
+
+(define (first-table afon)
+ (cond
+ [(number? (first afon)) (first afon)]
+ [else 'error]))
+
+;first-costs : fon -> (listof numbers)
+;Given afon, return the first line of (listof numbers) after the table number.
+
+(define (first-costs afon)
+ (first-line (rest afon)))
+
+;first-line : (listof X) -> (listof X)
+;Returns the first line of alox.
+
+(define (first-line a-file)
+ (cond
+ [(empty? a-file) empty]
+ [(and (symbol? (first a-file))
+ (symbol=? NEWLINE (first a-file))) empty]
+ [else (cons (first a-file)
+ (first-line (rest a-file)))]))
+
+;Tests
+;(file->list-of-checks (list 1 2.5 3.5 4.5 'NL
+; 2 3.5 4.5 5.5 'NL
+; 3 8.5 2.4 3.9 'NL))
+;
+;(equal? (file->list-of-checks
+; (list 1 2.30 4.00 12.50 13.50 'NL
+; 2 4.00 18.00 'NL
+; 4 2.30 12.50))
+; (list (make-rr 1 (list 2.30 4.00 12.50 13.50))
+; (make-rr 2 (list 4.00 18.00))
+; (make-rr 4 (list 2.30 12.50))))
\ No newline at end of file
blob - /dev/null
blob + 632f068577d72ed8f5736472c667d13e050ab48f (mode 644)
--- /dev/null
+++ 27.2.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Exercise 27.2.1. Determine what the list-of-lines representation for empty, (list 'NL), and (list 'NL 'NL) should be. Why are these examples important test cases?
+
+;A file is either
+;1. empty or
+;2. (cons s f)
+;where s is a symbol and f is a file.
+
+;Examples
+;
+;(file->list-of-lines empty)
+;empty
+;(file->list-of-lines (list 'NL))
+;(list empty)
+;(file->list-of-lines (list 'NL 'NL))
+;(list empty empty)
+
+;The NEWLINE character is represented by 'NL
+(define NEWLINE 'NL)
+
+;file->list-of-lines : file -> (listof (listof symbols))
+;Converts a-file into a (listof (listof symbols)) representing the file. Each new list starts right at the end of a newline symbol and ends at the first occurrence of a newline symbol. file->list-of-lines uses generative recursion: the first line is appended to the front of the remainder of the file that has already been converted into a list of lines.
+;Termination Argument: Since each application of file->list-of-lines necessarily shortens the argument for the new generative recursion, the paramater must get smaller over time and eventually become the empty list, for which a trivial solution is available.
+
+;first-line : file -> (listof symbols)
+;Returns the first line of a-file.
+
+;remove-first-line : file -> file
+;Given a-file, remove the first line.
+
+(define (file->list-of-lines a-file)
+ (local ((define (first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) empty]
+ [else (cons (first a-file)
+ (first-line (rest a-file)))]))
+ (define (remove-first-line a-file)
+ (cond
+ [(symbol=? NEWLINE (first a-file)) (rest a-file)]
+ [else (remove-first-line (rest a-file))])))
+ (cond
+ [(empty? a-file) empty]
+ [else (cons (first-line a-file)
+ (file->list-of-lines (remove-first-line a-file)))])))
+
+
+(file->list-of-lines '(Hi my name is Joe NL
+ and I live in a button factory NL
+ I have a wife NL
+ and three kids NL))
\ No newline at end of file
blob - /dev/null
blob + f6f23e99271d19896674afe564bd4fd79fe091c2 (mode 644)
--- /dev/null
+++ 27.2.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;create-matrix : N (listof numbers) -> (listof (listof numbers))
+;Given n (N[>=1]) and alon (alon has a length of n by m, where m is any integer), return a (listof (listof numbers)) representing an n by m matrix.
+
+(define (create-matrix n alon)
+ (cond
+ [(empty? alon) empty]
+ [(zero? n) (error 'create-matrix "expected arg: nonzero number")]
+ [(not (= (remainder (length alon) n) 0)) (error 'create-matrix "improper dimensions")]
+ [else (cons (first-n n alon)
+ (create-matrix n (remove-n n alon)))]))
+
+;first-n : N (listof numbers) -> (listof numbers)
+;Returns the first n numbers of alon as a (listof numbers).
+
+(define (first-n n alon)
+ (cond
+ [(zero? n) empty]
+ [else (cons (first alon)
+ (first-n (sub1 n) (rest alon)))]))
+
+;remove-n : N (listof numbers) -> (listof numbers)
+;Removes the first n numbers of alon and returns the result as a (listof numbers).
+
+(define (remove-n n alon)
+ (cond
+ [(zero? n) alon]
+ [else (remove-n (sub1 n) (rest alon))]))
+
+(equal? (create-matrix 2 '(4 5 6 7 8 9)) '((4 5)
+ (6 7)
+ (8 9)))
+(create-matrix 3 '(4 5 6 7 8 9))
\ No newline at end of file
blob - /dev/null
blob + 9e3faa01a5c5bb3e2f4ca61f83bd2be4d82244db (mode 644)
--- /dev/null
+++ 27.2.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;create-matrix : N (listof numbers) -> (listof (listof numbers))
+;Given n (N[>=1]) and alon (alon has a length of n^2), return a (listof (listof numbers)) representing an n by n matrix.
+
+(define (create-matrix n alon)
+ (
\ No newline at end of file
blob - /dev/null
blob + 13bf0487bf85f7e5a2422413aced6ebfa9d1fa32 (mode 644)
--- /dev/null
+++ 27.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define TOLERANCE 0.000000001)
+
+;; poly : number -> number
+(define (poly x)
+ (* (- x 2) (- x 4)))
+
+;midpoint : number number -> number
+;Returns the average of the two numbers.
+(define (midpoint n1 n2)
+ (/ (+ n1 n2) 2))
+
+;find-root : (number -> number) number number -> number
+;Given f, left and right, approximate a root by using a binary search. find-root returns the left interval once the interval size is less than tolerance. find-root uses generative recursion to find the root--it splits the interval in half and finds the root for one half of the interval.
+;Assume that (<= (f left) 0 (f right)) or (<= (f right) 0 (f left)).
+;Termination argument: Each interval is half the size of the previous interval. Hence, the nth recursive call has an interval of initial * (1/2)^n, where initial is the size of the initial interval. As n-> infinity, the interval approaches zero, which implies that this function must terminate for any value of tolerance greater than zero.
+
+(define (find-root f left right)
+ (local ((define mid (/ (+ left right) 2))
+ (define f-mid (f mid)))
+ (cond
+ [(<= (- right left) TOLERANCE) left]
+ [(or (<= (f left) 0 f-mid)
+ (>= (f left) 0 f-mid)) (find-root f left mid)]
+ [else (find-root f mid right)])))
+
+#|
+
+(define (find-root f left right)
+ (local ((define mid (/ (+ left right) 2)))
+ (cond
+ [(<= (- right left) TOLERANCE) left]
+ [(or (<= (f left) 0 (f mid))
+ (>= (f left) 0 (f mid))) (find-root f left mid)]
+ [(or (<= (f right) 0 (f mid))
+ (>= (f right) 0 (f mid))) (find-root f mid right)]
+ [else (error 'find-root "not guaranteed root")])))
+
+|#
+
+;find-root-aux : (number -> number) number number number number -> number
+;Same as find-root except it takes in two more arguments, f-left and f-right, in order to avoid calculating (f mid) twice.
+
+(define (find-root-aux f left right f-left f-right)
+ (local ((define mid (/ (+ left right) 2))
+ (define f-mid (f mid)))
+ (cond
+ [(<= (- right left) TOLERANCE) left]
+ [(or (<= f-left 0 f-mid)
+ (>= f-left 0 f-mid)) (find-root-aux f left mid f-left f-mid)]
+ [else (find-root-aux f mid right f-mid f-right)])))
+
+;find-root-aux : (number -> number) number number -> number
+;Same as find-root except it avoid calculating (f mid) twice to speed up calculations.
+
+(define (find-root2 f left right)
+ (find-root-aux f left right (f left) (f right)))
+
+(define (poly2 x)
+ (+ (- (log (+ (* (expt x 3) (exp x))
+ (sin (* x
+ (exp (* x (log x))))))) (abs x))
+ (- (+ (expt 2 x)
+ (expt 2 (sin x)))
+ (/ (expt x x) (+ x 3)))))
+
blob - /dev/null
blob + f55851bf2836e435afbefb3e5024183db8e79d38 (mode 644)
--- /dev/null
+++ 27.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + 7f2dce9598efdb5bf90a27db30102a12eb2827c5 (mode 644)
--- /dev/null
+++ 27.3.5
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;A table is a function that consumes only natural numbers between 0 (inclusive) and VL (exclusive) and returns a number.
+;
+;Formally, a table is a function
+;g : N[>=0 and <= (- VL 1)] -> number
+;
+;The root of a table is the value x such that (g x) is the closest to 0.
+;
+;find-root-linear : (N -> number) N -> N
+;Given a-table (table) and index i, find the root of a table. find-root-linear finds the root using structural induction (linear search).
+
+(define (find-root-linear a-table i)
+ (cond
+ [(zero? i) i]
+ [else (local ((define a-table-i (a-table i))
+ (define root-of-rest (find-root-linear a-table (sub1 i))))
+ (cond
+ [(<= (abs a-table-i)
+ (abs (a-table root-of-rest))) i]
+ [else root-of-rest]))]))
+
+(define (t x)
+ (+ (+ (* 3 (sin x)) (* 5 x))
+ (* -1 x (sqrt x))
+ 3))
+
+;find-root-discrete : (N -> number) N N -> N
+;Given a-table, left, and right, find a root of the table using binary search generative recursion. If there are multiple roots, only the root closest to zero is returned.
+;Termination Argument: The interval of find-root-discrete decreases by half each time until the interval size is only 1. Once this occurs, find-root-discrete either returns the left or the right index as the root. Hence, find-root-discrete must terminate.
+;midpoint : Given left and right, determine the midpoint rounded to the nearest integer.
+;No assumption about a-table being monotonic
+
+
+
+(define (find-root-discrete2 a-table left right)
+ (cond
+ [(= (- right left) 1)
+ (cond
+ [(<= (abs (a-table left))
+ (abs (a-table right))) left]
+ [else right])]
+ [else (local ((define midpoint
+ (round (+ left
+ (/ (- right left) 2))))
+ (define left-side-root (find-root-discrete2 a-table left midpoint))
+ (define right-side-root (find-root-discrete2 a-table midpoint right)))
+ (cond
+ [(<= (abs (a-table left-side-root))
+ (abs (a-table right-side-root))) left-side-root]
+ [else right-side-root]))]))
+
+
+
+;find-root-discrete : (N -> number) N N -> N
+;Given a-table, left, and right, find a root of the table using binary search generative recursion. If there are multiple roots, only the root closest to zero is returned.
+;Termination Argument: The interval of find-root-discrete decreases by half each time until the interval size is only 1. Once this occurs, find-root-discrete either returns the left or the right index as the root. Hence, find-root-discrete must terminate.
+;midpoint : Given left and right, determine the midpoint rounded to the nearest integer.
+;ASSUMPTION : a-table is monotonic increasing or monotonic decreasing.
+
+(define (find-root-discrete a-table left right)
+ (local ((define midpoint
+ (round (+ left
+ (/ (- right left) 2)))))
+ (cond
+ [(= (- right left) 1)
+ (cond
+ [(<= (abs (a-table left))
+ (abs (a-table right))) left]
+ [else right])]
+ [(or (<= (a-table left) 0 (a-table midpoint))
+ (<= (a-table midpoint) 0 (a-table left))) (find-root-discrete a-table left midpoint)]
+ [else (find-root-discrete a-table midpoint right)])))
+
+(time (find-root-linear t 30000))
+(time (find-root-discrete2 t 0 100000))
+(time (find-root-discrete t 0 100000))
+
+find-root-linear requires 1024 applications whereas find-root-discrete requires 10 applications
\ No newline at end of file
blob - /dev/null
blob + b74bc2298449caf64610aab747bda7d6a6e5fc81 (mode 644)
--- /dev/null
+++ 27.3.5~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+A table is a function that consumes only natural numbers between 0 (inclusive) and VL (exclusive) and returns a number.
+
+Formally, a table is a function
+;g : N[>=0 and <= (- VL 1)] -> number
blob - /dev/null
blob + aaea891acdc1ffc4c1ae3fa593dbfc8cf55e0734 (mode 644)
--- /dev/null
+++ 27.3.6
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Once the interval size reaches TOLERANCE, simply approximate the area under the curve as the corresponding rectangle or trapezoid.
+
+;TOLERANCE1 is for integrate-dc
+(define TOLERANCE1 0.0001)
+
+;TOLERANCE2 is for integrate-adaptive
+(define TOLERANCE2 0.0000001)
+
+;integrate-dc : (number -> number) number number -> number
+;(integrate-divide and conquer)
+;Given f, left, and right, use the divide-and-conquer generative recursion strategy to find the area under the curve. Given an interval, if the interval is small enough (compared to TOLERANCE1), we simply find the area of the interval (using a rectangle or trapezoid). Otherwise, we divide the interval into two pieces and sum the area under the curves of the resulting two integrals.
+;ASSUMPTION : (> right left)
+;Termination argument: Since each recursion involves an interval with half the width of the original interval, integrate-dc will eventually be applied to an interval less than the TOLERANCE1 and so terminate.
+
+(define (integrate-dc f left right)
+ (local ((define midpoint (+ left
+ (/ (- right left) 2))))
+ (cond
+ [(not (> right left))
+ (error 'integrate-dc "right endpoint must be greater than left endpoint")]
+ [(<= (- right left) TOLERANCE1) (area-of-trapezoid f left right)]
+ [else (+ (integrate-dc f left midpoint)
+ (integrate-dc f midpoint right))])))
+
+;area-of-rectangle : number number number -> number
+;Given the left and right endpoints as well as the height, compute the area of the rectangle.
+
+(define (area-of-rectangle left right height)
+ (* (- right left) height))
+
+;area-of-trapezoid : (number -> number) number number -> number
+;Given the function f, the left and right endpoints, compute the area of the trapezoid.
+(define (area-of-trapezoid f left right)
+ (* (/ (+ (f left) (f right)) 2)
+ (- right left)))
+
+;integrate-adaptive :
+;Given f, left, and right, integrate-adaptive uses the same strategy as integrate-dc except that it prematurely ends recursions if it notices that the difference between the trapezoid approximation of an interval versus the trapezoid approximation of the interval split in two is about the same.
+
+(define (integrate-adaptive f left right)
+ (local ((define midpoint (+ left
+ (/ (- right left) 2)))
+ (define current-approx (area-of-trapezoid f left right)))
+ (cond
+ [(not (> right left))
+ (error 'integrate-adaptive "right endpoint must be greater than left endpoint")]
+ [(< (- current-approx
+ (+ (area-of-trapezoid f left midpoint)
+ (area-of-trapezoid f midpoint right)))
+ (* TOLERANCE2 (- right left)))
+ current-approx]
+ [(<= (- right left) TOLERANCE2) current-approx]
+ [else (+ (integrate-adaptive f left midpoint)
+ (integrate-adaptive f midpoint right))])))
+
+(time (integrate-adaptive (lambda (x) (sqr x)) -4 9))
+(time (integrate-dc (lambda (x) (sqr x)) -4 9))
blob - /dev/null
blob + f55851bf2836e435afbefb3e5024183db8e79d38 (mode 644)
--- /dev/null
+++ 27.3.6~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + bd52625eb94345da4139a7b56c5df76a0aef72c6 (mode 644)
--- /dev/null
+++ 27.4.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.4|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define TOLERANCE 0.0001)
+
+;newton : (number -> number) number -> number
+;Given f, ig (initial guess), find the root of f using Newton's Method.
+;TERMINATION ARGUMENT: There is no guarantee that newton will terminate.
+
+(define (newton f ig)
+ (cond
+ [(<= (abs (f ig)) TOLERANCE) ig]
+ [else (newton f (find-root-tangent f ig))]))
+
+;find-root-tangent : (number -> number) number -> number
+;Finds the root of the tangent line to f at point x.
+
+(define (find-root-tangent f x)
+ (local ((define fprime (d/dx f TOLERANCE)))
+ (- x (/ (f x)
+ (fprime x)))))
+
+;d/dx : (number -> number) number -> (number -> number)
+;Returns f', the slope of f, given epsilon e.
+
+(define (d/dx f e)
+ (local ((define (slope x) (/ (- (f (+ x e))
+ (f (- x e)))
+ (* 2 e))))
+ slope))
+
+;find-root : (number -> number) number number -> number
+;Given f, left and right, approximate a root by using a binary search. find-root returns the left interval once the interval size is less than tolerance. find-root uses generative recursion to find the root--it splits the interval in half and finds the root for one half of the interval.
+;Assume that (<= (f left) 0 (f right)) or (<= (f right) 0 (f left)).
+;Termination argument: Each interval is half the size of the previous interval. Hence, the nth recursive call has an interval of initial * (1/2)^n, where initial is the size of the initial interval. As n-> infinity, the interval approaches zero, which implies that this function must terminate for any value of tolerance greater than zero.
+
+(define (find-root f left right)
+ (local ((define mid (/ (+ left right) 2))
+ (define f-mid (f mid)))
+ (cond
+ [(<= (- right left) TOLERANCE) left]
+ [(or (<= (f left) 0 f-mid)
+ (>= (f left) 0 f-mid)) (find-root f left mid)]
+ [else (find-root f mid right)])))
+
+(time (find-root (lambda (x) (- (* (expt x 3)
+ (exp x))
+ (cos x)))
+ 0 1000))
+(time (newton (lambda (x) (- (* (expt x 3)
+ (exp x))
+ (cos x)))
+ 500))
blob - /dev/null
blob + 5cdeabb9a2e7a24d394c00b4574002f5349c5455 (mode 644)
--- /dev/null
+++ 27.4.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.4|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;secant-line : (number -> number) number number -> (number -> number)
+;Given f, e, and x, returns the function that corresponds to the line that passes through (x-e, f(x-e)) and (x+e, f(x+e)) (ie, the secant line).
+
+
+;(graph-fun y0 'purple)
+;(graph-line (secant-line y0 0.5 3) 'green)
+
+;d/dx : (number -> number) number -> (number -> number)
+;Returns f', the slope of f, given epsilon e.
+
+(define (d/dx f e)
+ (local ((define (slope x) (/ (- (f (+ x e))
+ (f (- x e)))
+ (* 2 e)))
+ (define (secant-line f e x)
+ (local ((define a-slope (/ (- (f (+ x e))
+ (f (- x e)))
+ (* 2 e)))
+ (define a-point (make-posn (- x e)
+ (f (- x e)))))
+ (line-from-point+slope a-point a-slope))))
+ slope))
+
blob - /dev/null
blob + d170dec20f151d5cceca177bd7b28aa6dbdebc6d (mode 644)
--- /dev/null
+++ 27.5.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.5|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;subtract : (listof numbers) (listof numbers) -> (listof numbers)
+;Given list1 and list2, subtract a multiple of list1 so that the first column of list2 is 0. Return the remainder of the list (that is, leave out the leading zero).
+;ASSUMPTION : list1 must be the same length as list2
+;
+;Examples:
+;
+;(subtract '(5 6 7)
+; '(3 4 5))
+;should give
+;'(2/5 4/5)
+
+;subtract-lists : (listof numbers) (listof numbers) -> (listof numbers)
+;Given list1 and list2, subtract list1 from list2.
+
+;multiply-row : number (listof numbers) -> (listof numbers)
+;Given factor, multiply alon by factor.
+
+(define (subtract list1 list2)
+ (local ((define multiplied-list1
+ (multiply-row (/ (first list2) (first list1)) list1)))
+ (cond
+ [(not (= (length list1) (length list2)))
+ (error 'subtract "unequal list lengths")]
+ [(empty? list1) empty]
+ [(not (= (first list1) (first list2)))
+ (rest (subtract-lists multiplied-list1
+ list2))]
+ [else (rest (subtract-lists list1 list2))])))
+
+(define (subtract-lists list1 list2)
+ (cond
+ [(not (= (length list1) (length list2)))
+ (error 'subtract "unequal list lengths")]
+ [(empty? list1) empty]
+ [else (cons (- (first list2)
+ (first list1))
+ (subtract-lists (rest list1) (rest list2)))]))
+
+(define (multiply-row factor alon)
+ (map (lambda (x) (* factor x)) alon))
+
+;triangulate : (listof (listof numbers)) -> (listof (listof numbers))
+;Given a-matrix, return the triangularized matrix obtained by following Gaussian elimination. (generative recursion involved) We keep the first row and append this to the remaining rows, all of which have been subtracted by the first row, which has been multiplied by a factor such that all the remaining rows have the first column zeroed out (and then dropped). We then take the matrix, excluding the first row, and repeat the process until we hit the last row.
+;Termination Argument: each generative recursion involves a matrix with one less row and one less column. Ultimately, we hit the last row, and we simply return the last row. Hence, triangulate must necessarily terminate.
+
+
+(define (triangulate a-matrix)
+ (cond
+ [(or (empty? a-matrix)
+ (not (cons? (first a-matrix))))
+ (error 'triangulate "expected arg: non-empty (listof (listof numbers))")]
+ [(= (length a-matrix) 1) a-matrix]
+ [(column-zeros? a-matrix) (error 'triangulate "cannot triangulate matrix")]
+ [(zero? (first (first a-matrix))) (triangulate (switch-row a-matrix))]
+ [else (cons (first a-matrix)
+ (triangulate (map (lambda (x) (subtract (first a-matrix) x))
+ (rest a-matrix))))]))
+
+;switch-row : (listof (listof numbers)) -> (listof (listof numbers))
+;Given a-matrix, find the first-nonzero row in a-matrix and move it to the top of the matrix while replacing that first-nonzero-row with the first row. If there are no nonzero rows for the first column, return a-matrix.
+
+(define (switch-row a-matrix)
+ (cond
+ [(empty? a-matrix) empty]
+ ;[(empty? (first a-matrix)) empty]
+ [(and (zero? (first (first a-matrix)))
+ (cons? (first-nonzero-row a-matrix)))
+ (cons (first-nonzero-row a-matrix)
+ (remove (first-nonzero-row a-matrix) a-matrix))]
+ [else a-matrix]))
+
+;first-nonzero-row : (listof (listof numbers)) -> (listof numbers)
+;Given a-matrix, return the first-nonzero-row.
+
+(define (first-nonzero-row a-matrix)
+ (cond
+ [(empty? a-matrix) empty]
+ [(not (zero? (first (first a-matrix)))) (first a-matrix)]
+ [else (first-nonzero-row (rest a-matrix))]))
+
+;remove : X (listof X) -> (listof X)
+;Given x and alox, removes the first instance of x in alox and returns the remaining list. If x is not present in alox, simply returns alox.
+
+(define (remove x alox)
+ (cond
+ [(empty? alox) empty]
+ [(equal? x (first alox)) (rest alox)]
+ [else (cons (first alox)
+ (remove x (rest alox)))]))
+
+;column-zeros? : (listof (listof numbers)) -> boolean
+;Determines if the entire first column of a-matrix consists of nothing but zeros.
+
+(define (column-zeros? a-matrix)
+ (cond
+ [(empty? a-matrix) true]
+ [(not (zero? (first (first a-matrix)))) false]
+ [else (column-zeros? (rest a-matrix))]))
+
+;evaluate : (listof numbers) (listof numbers) -> number
+;Given eqn and var, substitute the corresponding value of the variables in var into eqn and subtract the value of the right-hand side of eqn from the left-hand side of eqn.
+;
+;For example, (evaluate '(9 21) '(2)) represents 9y and 21 and y=2. We plug y=2 into 9*y - 21 to obtain -3.
+
+(define (evaluate eqn var)
+ (cond
+ [(and (empty? var)
+ (cons? eqn)) (* -1 (first eqn))]
+ [(and (cons? eqn)
+ (cons? var)) (+ (* (first eqn) (first var))
+ (evaluate (rest eqn) (rest var)))]
+ [else (error 'evaluate "unexpected error")]))
+
+;solve : (listof (listof numbers)) -> (listof numbers)
+;solve consumes a (listof (listof numbers)) representing a triangular matrix and returns the solutions, a (listof numbers).
+;ASSUMPTION: A "perfect" matrix is provided
+
+(define (solve a-matrix)
+ (cond
+ [(empty? a-matrix) empty]
+ [(empty? (rest a-matrix)) (cons (/ (second (first a-matrix))
+ (first (first a-matrix)))
+ empty)]
+ [(cons? a-matrix) (cons (/ (* -1 (evaluate (rest (first a-matrix))
+ (solve (rest a-matrix))))
+ (first (first a-matrix)))
+ (solve (rest a-matrix)))]))
+
+#|
+(= (evaluate '(9 21) '(2)) -3)
+(= (evaluate '(3 9 37) '(4 2)) -7)
+|#
+
+;Tests
+
+(define a-matrix '((2 3 3 8)
+ (2 3 -2 3)
+ (4 -2 2 4)))
+(define b-matrix '((2 2 3 10)
+ (2 5 12 31)
+ (4 1 -2 1)))
+
+#|
+(define c-matrix '((2 2 2 6)
+ (2 2 4 8)
+ (2 2 1 2)))
+
+|#
+;(triangulate a-matrix)
+;(triangulate b-matrix)
+;(triangulate c-matrix)
+(triangulate a-matrix)
+(solve (triangulate a-matrix))
+(solve (triangulate b-matrix))
+(define d-matrix '((5 6 9 7 1 9)
+ (5 0 3 1 1 8)
+ (7 8 3 9 4 3)
+ (5 4 5 6 7 5)
+ (8 1 2 0 9 1)))
+(solve (triangulate d-matrix))
\ No newline at end of file
blob - /dev/null
blob + da22b4077a5b66888904569ff1bb91908347f325 (mode 644)
--- /dev/null
+++ 27.5.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |27.5|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+subtract : (listof numbers) (listof numbers) -> (listof numbers)
+Given first-list and second-list, subtract
\ No newline at end of file
blob - /dev/null
blob + 58600401914ad3782a98ba4f8275afd8c121baa5 (mode 644)
--- /dev/null
+++ 28.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+(define Graph2
+ (list (list 'A (list 'B 'E))
+ (list 'B (list 'E 'F))
+ (list 'C (list 'D))
+ (list 'D empty)
+ (list 'E (list 'C 'F))
+ (list 'F (list 'D 'G))
+ (list 'G empty)))
+
+A node is a symbol.
+
+A path is a list of the form
+(cons no lon)
+where no is a node and lon is a (listof nodes). A path represents a node and the nodes that can be accessed from the node.
+
+A graph is either
+1. empty or
+2. (cons pa gr)
+where pa is a path and gr is a graph.
+
+find-route : node node graph -> (listof nodes) or false
+Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
+
+(define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else ... (find-route/list (neighbors ori G) dest G) ...]))
+
+find-route/list : (listof nodes) node graph -> (listof nodes) or false
+Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+(define (find-route/list lo-ori dest G)
+ ( ... ))
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+(define (neighbors anode G)
+ (assf (lambda (x) (equal? anode x)) G))
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+(define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+
+(assf (lambda (x) (equal? anode x)) G)
\ No newline at end of file
blob - /dev/null
blob + 961b0de45be219f7e873896f4045b65e6d66168d (mode 644)
--- /dev/null
+++ 28.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+(define Graph2
+ (list (list 'A (list 'B 'E))
+ (list 'B (list 'E 'F))
+ (list 'C (list 'D))
+ (list 'D empty)
+ (list 'E (list 'C 'F))
+ (list 'F (list 'D 'G))
+ (list 'G empty)))
\ No newline at end of file
blob - /dev/null
blob + 5fc9ebfd851b58ff4325b0a5a571a3c45a237db3 (mode 644)
--- /dev/null
+++ 28.1.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+(define Graph2
+ '((A (B E))
+ (B (E F))
+ (C (B D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+
+;A node is a symbol.
+;
+;A path is a list of the form
+;(cons no lon)
+;where no is a node and lon is a (listof nodes).
+;
+;A graph is either
+;1. empty or
+;2. (cons pa gr)
+;where pa is a path and gr is a graph.
+
+;find-route : node node graph -> (listof nodes) or false
+;Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
+
+(define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+;find-route/list : (listof nodes) node graph -> (listof nodes) or false
+;Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+(define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+(define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G))))
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+(define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+
+;(find-route 'A 'G Graph)
+;(find-route 'C 'G Graph)
+
+;A node-path is a list
+;(cons no1 no2 lon)
+;where no1, no2 are nodes (representing the origin and destination, respectively), and lon is a (listof nodes) representing the route from the origin to the destination.
+
+;test-on-all-nodes : graph -> (listof (listof node-path))
+;Tests find-route for all possible pairs of nodes in G. We first generate all possible permutations of node pairs and we apply find-route to each node pair. We then return the resulting (listof node-paths), each node-path being a list containing the origin, destination, and the (listof nodes) taken to get from the origin to the destination.
+
+;find-route : node node graph -> (listof nodes) or false
+
+(define (test-on-all-nodes G)
+ (map (lambda (x)
+ (list (first x)
+ (second x)
+ (find-route (first x) (second x) G)))
+ (generate-pairs (extract-nodes G))))
+
+;extract-nodes : graph -> (listof nodes)
+;Extracts the nodes from G and returns them as a (listof nodes).
+
+(define (extract-nodes G)
+ (map (lambda (x) (first x)) G))
+
+;generate-pairs : (listof nodes) -> (listof (listof nodes))
+;Generates all possible pairs of nodes from alon and returns it as a (listof (listof nodes)), each element containing a pair of nodes.
+
+;generate-pairs : (listof nodes) (listof nodes) -> (listof (listof nodes))
+;Pair the first element of current-lon with the entire complete-lon, and repeat the process to return a (listof (listof nodes)), each element containing a pair of nodes, to give all possible pairings.
+
+
+(define (generate-pairs alon)
+ (local ((define (generate-pairs current-lon complete-lon)
+ (cond
+ [(empty? current-lon) empty]
+ [else (append (pair (first current-lon)
+ (remove (first current-lon) complete-lon))
+ (generate-pairs (rest current-lon) complete-lon))])))
+ (generate-pairs alon alon)))
+
+;pair : node (listof nodes) -> (listof (listof nodes))
+;Given anode and alon, generate all possible pairs of anode with elements in alon.
+
+(define (pair anode alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (list anode (first alon))
+ (pair anode (rest alon)))]))
+
+;remove : X (listof X) -> (listof X)
+;Given x and alox, removes the first instance of x in alox and returns the remaining list. If x is not present in alox, simply returns alox.
+
+(define (remove x alox)
+ (cond
+ [(empty? alox) empty]
+ [(equal? x (first alox)) (rest alox)]
+ [else (cons (first alox)
+ (remove x (rest alox)))]))
+(equal? (find-route 'B 'C Graph2) '(B E C))
\ No newline at end of file
blob - /dev/null
blob + 610129a3d6a1f01ff5382d005f35e20a0718397b (mode 644)
--- /dev/null
+++ 28.1.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+(define Graph2
+ (list (list 'A (list 'B 'E))
+ (list 'B (list 'E 'F))
+ (list 'C (list 'D))
+ (list 'D empty)
+ (list 'E (list 'C 'F))
+ (list 'F (list 'D 'G))
+ (list 'G empty)))
+
+A node is a symbol.
+
+A path is a list of the form
+(cons no lon)
+where no is a node and lon is a (listof nodes). A path represents a node and the nodes that can be accessed from the node.
+
+A graph is either
+1. empty or
+2. (cons pa gr)
+where pa is a path and gr is a graph.
+
+find-route : node node graph -> (listof nodes) or false
+Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
+
+(define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else ... (find-route/list (neighbors ori G) dest G) ...]))
+
+find-route/list : (listof nodes) node graph -> (listof nodes) or false
+Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+(define (find-route/list lo-ori dest G)
+ ( ... ))
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+(define (neighbors anode G)
+ (assf (lambda (x) (equal? anode x)) G))
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+(define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+
+(neighbors 'A Graph2
\ No newline at end of file
blob - /dev/null
blob + e90af1801acaa8e139e71e2cf543cd261f86a615 (mode 644)
--- /dev/null
+++ 28.1.6
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+(define Graph2
+ '((A (B E))
+ (B (E F))
+ (C (B D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+
+;A node is a symbol.
+;
+;A path is a list of the form
+;(cons no lon)
+;where no is a node and lon is a (listof nodes).
+;
+;A graph is either
+;1. empty or
+;2. (cons pa gr)
+;where pa is a path and gr is a graph.
+
+;find-route : node node graph -> (listof nodes) or false
+;Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
+
+;find-route/list : (listof nodes) node graph -> (listof nodes) or false
+;Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+;(find-route 'A 'G Graph)
+;(find-route 'C 'G Graph)
+
+;A node-path is a list
+;(cons no1 no2 lon)
+;where no1, no2 are nodes (representing the origin and destination, respectively), and lon is a (listof nodes) representing the route from the origin to the destination.
+
+;test-on-all-nodes : graph -> (listof (listof node-path))
+;Tests find-route for all possible pairs of nodes in G. We first generate all possible permutations of node pairs and we apply find-route to each node pair. We then return the resulting (listof node-paths), each node-path being a list containing the origin, destination, and the (listof nodes) taken to get from the origin to the destination.
+
+;find-route : node node graph -> (listof nodes) or false
+
+;extract-nodes : graph -> (listof nodes)
+;Extracts the nodes from G and returns them as a (listof nodes).
+
+;generate-pairs : (listof nodes) -> (listof (listof nodes))
+;Generates all possible pairs of nodes from alon and returns it as a (listof (listof nodes)), each element containing a pair of nodes.
+
+;generate-pairs : (listof nodes) (listof nodes) -> (listof (listof nodes))
+;Pair the first element of current-lon with the entire complete-lon, and repeat the process to return a (listof (listof nodes)), each element containing a pair of nodes, to give all possible pairings.
+
+;pair : node (listof nodes) -> (listof (listof nodes))
+;Given anode and alon, generate all possible pairs of anode with elements in alon.
+
+;remove : X (listof X) -> (listof X)
+;Given x and alox, removes the first instance of x in alox and returns the remaining list. If x is not present in alox, simply returns alox.
+
+(define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else
+ (local (
+
+ (define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+ (define neighbors
+ (first (rest (assf (lambda (x) (equal? ori x)) G))))
+ (define (find-route/list neighbors)
+ (cond
+ [(empty? neighbors) false]
+ [else (local ((define possible-route (find-route (first neighbors) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest neighbors))]
+ [else possible-route]))]))
+ (define possible-route (find-route/list neighbors)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+
+
+
+(define (test-on-all-nodes G)
+ (map (lambda (x)
+ (list (first x)
+ (second x)
+ (find-route (first x) (second x) G)))
+ (generate-pairs (extract-nodes G))))
+
+(define (extract-nodes G)
+ (map (lambda (x) (first x)) G))
+
+(define (generate-pairs alon)
+ (local ((define (generate-pairs current-lon complete-lon)
+ (cond
+ [(empty? current-lon) empty]
+ [else (append (pair (first current-lon)
+ (remove (first current-lon) complete-lon))
+ (generate-pairs (rest current-lon) complete-lon))])))
+ (generate-pairs alon alon)))
+
+(define (pair anode alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (list anode (first alon))
+ (pair anode (rest alon)))]))
+
+(define (remove x alox)
+ (cond
+ [(empty? alox) empty]
+ [(equal? x (first alox)) (rest alox)]
+ [else (cons (first alox)
+ (remove x (rest alox)))]))
+(equal? (find-route 'B 'C Graph2) '(B E C))
+(find-route 'B 'F Graph1)
blob - /dev/null
blob + 5fc9ebfd851b58ff4325b0a5a571a3c45a237db3 (mode 644)
--- /dev/null
+++ 28.1.6~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+(define Graph2
+ '((A (B E))
+ (B (E F))
+ (C (B D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+
+;A node is a symbol.
+;
+;A path is a list of the form
+;(cons no lon)
+;where no is a node and lon is a (listof nodes).
+;
+;A graph is either
+;1. empty or
+;2. (cons pa gr)
+;where pa is a path and gr is a graph.
+
+;find-route : node node graph -> (listof nodes) or false
+;Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
+
+(define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+;find-route/list : (listof nodes) node graph -> (listof nodes) or false
+;Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+(define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+(define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G))))
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+(define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+
+;(find-route 'A 'G Graph)
+;(find-route 'C 'G Graph)
+
+;A node-path is a list
+;(cons no1 no2 lon)
+;where no1, no2 are nodes (representing the origin and destination, respectively), and lon is a (listof nodes) representing the route from the origin to the destination.
+
+;test-on-all-nodes : graph -> (listof (listof node-path))
+;Tests find-route for all possible pairs of nodes in G. We first generate all possible permutations of node pairs and we apply find-route to each node pair. We then return the resulting (listof node-paths), each node-path being a list containing the origin, destination, and the (listof nodes) taken to get from the origin to the destination.
+
+;find-route : node node graph -> (listof nodes) or false
+
+(define (test-on-all-nodes G)
+ (map (lambda (x)
+ (list (first x)
+ (second x)
+ (find-route (first x) (second x) G)))
+ (generate-pairs (extract-nodes G))))
+
+;extract-nodes : graph -> (listof nodes)
+;Extracts the nodes from G and returns them as a (listof nodes).
+
+(define (extract-nodes G)
+ (map (lambda (x) (first x)) G))
+
+;generate-pairs : (listof nodes) -> (listof (listof nodes))
+;Generates all possible pairs of nodes from alon and returns it as a (listof (listof nodes)), each element containing a pair of nodes.
+
+;generate-pairs : (listof nodes) (listof nodes) -> (listof (listof nodes))
+;Pair the first element of current-lon with the entire complete-lon, and repeat the process to return a (listof (listof nodes)), each element containing a pair of nodes, to give all possible pairings.
+
+
+(define (generate-pairs alon)
+ (local ((define (generate-pairs current-lon complete-lon)
+ (cond
+ [(empty? current-lon) empty]
+ [else (append (pair (first current-lon)
+ (remove (first current-lon) complete-lon))
+ (generate-pairs (rest current-lon) complete-lon))])))
+ (generate-pairs alon alon)))
+
+;pair : node (listof nodes) -> (listof (listof nodes))
+;Given anode and alon, generate all possible pairs of anode with elements in alon.
+
+(define (pair anode alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (list anode (first alon))
+ (pair anode (rest alon)))]))
+
+;remove : X (listof X) -> (listof X)
+;Given x and alox, removes the first instance of x in alox and returns the remaining list. If x is not present in alox, simply returns alox.
+
+(define (remove x alox)
+ (cond
+ [(empty? alox) empty]
+ [(equal? x (first alox)) (rest alox)]
+ [else (cons (first alox)
+ (remove x (rest alox)))]))
+(equal? (find-route 'B 'C Graph2) '(B E C))
\ No newline at end of file
blob - /dev/null
blob + 99aa9b142edf148a0ea7ee9e93d001ad295dcc94 (mode 644)
--- /dev/null
+++ 28.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;A row is either
+;1. empty or
+;2. (cons bool ro)
+;where bool is a boolean (true/false), and ro is a row.
+
+;A chessboard is either
+;1. empty or
+;2. (cons r cb)
+;where r is a row and cb is a chessboard.
+
+;Specifically, an nxn chessboard is a (listof (listof booleans)) such that the length of each element in the chessboard is the same as the length of the chessboard itself. That is, the chessboard is square. A false value in a chessboard represents a tile that is either occupied by a queen or threatened by one; a true value represents an available square for the non-threatened placement of a new chess piece.
+
+;build-board : N (N N -> boolean) -> board
+;Creates a square chessboard with dimensions n by n, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. The board's first entry is the top left corner, 1 x 1 (not 0 x 0).
+
+;build-board : N N (N N -> boolean) -> board
+;Creates a chessboard with dimensions rows by cols, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. Build-board utilizes structural recursion on rows, and thus must ultimately terminate.
+
+;board-ref : board N[>=1] N[>=1] -> board
+;Returns the value of the i x j entry in a-board.
+
+;threatened? : posn posn -> boolean
+;Determine if posn1 can threaten posn2.
+
+;threatened-loq? : posn (listof posns) -> boolean
+;Determine if aposn is threatened by aloq.
+
+;vertical : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same vertical column.
+
+;horizontal : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same horizontal row.
+
+;diagonal : posn posn -> boolean
+;Determines if posn1 and posn2 lie on a diagonal. If two posns lie on a negative-sloping diagonal, then their difference is a multiple of (1,1). If two posns lie on a positive-sloping diagonal, their difference is a multiple of (1,-1). In general, two posns lie on the same diagonal if the absolute value of the differences between the coordinates are equal.
+
+
+
+(define (build-board n f)
+ (local ((define (build-board-rows-cols rows cols f)
+ (cond
+ [(or (zero? rows)
+ (zero? cols)) empty]
+ [else (append (build-board-rows-cols (sub1 rows) cols f)
+ (list (build-list cols (lambda (x) (f rows (+ x 1))))))])))
+ (build-board-rows-cols n n f)))
+
+(define (board-ref a-board i j)
+ (cond
+ [(> i 1) (board-ref (rest a-board) (sub1 i) j)]
+ [else (list-ref (first a-board) (- j 1))]))
+
+(define (threatened? posn1 posn2)
+ (local ((define (vertical posn1 posn2)
+ (= (posn-y posn1)
+ (posn-y posn2)))
+ (define (horizontal posn1 posn2)
+ (= (posn-x posn1)
+ (posn-x posn2)))
+ (define (diagonal posn1 posn2)
+ (= (abs (- (posn-x posn1)
+ (posn-x posn2)))
+ (abs (- (posn-y posn1)
+ (posn-y posn2))))))
+ (or (vertical posn1 posn2)
+ (horizontal posn1 posn2)
+ (diagonal posn1 posn2))))
+
+(define (threatened-loq? aposn aloq)
+ (ormap (lambda (aqueen) (threatened? aposn aqueen)) aloq))
+
+(define (build-board-loq n aloq)
+ (build-board n
+ (lambda (row col)
+ (cond
+ [(threatened-loq? (make-posn row col) aloq) false]
+ [else true]))))
+
+;placement : N (listof posns) -> board or false
+;Place n queens on a square 8x8 chessboard, returning the board if the placement is possible and false otherwise.
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns) or false
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false.
+
+;place-queen : N (listof posns) -> (listof posns)
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns)
+;Place n queens in the remaining spaces such that
+
+;build-board-loq : n (listof posns) -> board
+;Builds an n by n board with occupied or threatened squares filled in given by aloq (a list of queens represented by (listof posns)).
+#|
+(define (placement n aloq)
+ (build-board-loq 8 (place-queen n empty)))
+|#
+
+(define (test-place-queen n)
+ (place-queen n empty))
+
+(define (place-queen n aloq)
+ (cond
+ [(zero? n) aloq]
+ [else (local ((define spaces (empty-spaces dim dim aloq))
+ (define new-loq (place-queen-spaces n spaces aloq)))
+ (cond
+ [(boolean? new-loq) false]
+ [else new-loq]))]))
+
+(define (place-queen-spaces n spaces aloq)
+ (cond
+ [(zero? n) aloq]
+ [(empty? spaces) false]
+ [else
+ (local ((define first-guess (place-queen (sub1 n) (cons (first spaces) aloq))))
+ (cond
+ [(boolean? first-guess)
+ (place-queen-spaces n (rest spaces) aloq)]
+ [else (place-queen (sub1 n) (cons (first spaces) aloq))]))]))
+
+;empty-spaces : N N (listof posns) -> (listof posns)
+;Given aloq, determine the empty spaces on an mxn chessboard.
+
+(define (empty-spaces m n aloq)
+ (local ((define filled-board (build-board-loq n aloq))
+ (define posn-list (create-posn-list m n)))
+ (filter (lambda (p) (board-ref filled-board (posn-x p) (posn-y p))) posn-list)))
+
+
+;create-posn-list : N N -> (listof posns)
+;Given rows and cols, creates a (listof posns) representing the chessboard of dimensions rows by cols. Each element represents the index of a tile in the rows by cols chessboard.
+
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 0) empty]
+ [(> rows 0) (append (create-posn-list (sub1 rows) cols)
+ (build-list cols (lambda (c) (make-posn rows (+ c 1)))))]))
+
+(define dim 8)
+(test-place-queen dim)
\ No newline at end of file
blob - /dev/null
blob + 361e8e85c514922200f7701d7cc546f5620478d7 (mode 644)
--- /dev/null
+++ 28.2.1-0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 0) empty]
+ [(> rows 0) (append (create-posn-list (sub1 rows) cols)
+ (build-list cols (lambda (c) (make-posn rows (+ c 1)))))]))
+
+
+ (cond
+ [(or (zero? rows)
+ (zero? cols)) empty]
+ [else (append (build- (sub1 rows) cols f)
+ (list (build-list cols (lambda (x) (make-posn rows (+ x 1))))))]))
+
blob - /dev/null
blob + 2e095deb6f0e8a66c2a4bfd17192694210c551a9 (mode 644)
--- /dev/null
+++ 28.2.1-0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 1) ]
+ [(> rows 1) (append (create-posn-list (sub1 rows) cols)
+ (build-list (lambda (c) (make-posn rows c)) cols))]))
+
+
+ (cond
+ [(or (zero? rows)
+ (zero? cols)) empty]
+ [else (append (build- (sub1 rows) cols f)
+ (list (build-list cols (lambda (x) (make-posn rows (+ x 1))))))]))
+
blob - /dev/null
blob + c893b046473dd14d72f7ea2a7ba53971257c66d2 (mode 644)
--- /dev/null
+++ 28.2.1-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;A row is either
+;1. empty or
+;2. (cons bool ro)
+;where bool is a boolean (true/false), and ro is a row.
+
+;A chessboard is either
+;1. empty or
+;2. (cons r cb)
+;where r is a row and cb is a chessboard.
+
+;Specifically, an nxn chessboard is a (listof (listof booleans)) such that the length of each element in the chessboard is the same as the length of the chessboard itself. That is, the chessboard is square. A false value in a chessboard represents a tile that is either occupied by a queen or threatened by one; a true value represents an available square for the non-threatened placement of a new chess piece.
+
+;build-board : N (N N -> boolean) -> board
+;Creates a square chessboard with dimensions n by n, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. The board's first entry is the top left corner, 1 x 1 (not 0 x 0).
+
+;build-board : N N (N N -> boolean) -> board
+;Creates a chessboard with dimensions rows by cols, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. Build-board utilizes structural recursion on rows, and thus must ultimately terminate.
+
+;board-ref : board N[>=1] N[>=1] -> board
+;Returns the value of the i x j entry in a-board.
+
+;threatened? : posn posn -> boolean
+;Determine if posn1 can threaten posn2.
+
+;threatened-loq? : posn (listof posns) -> boolean
+;Determine if aposn is threatened by aloq.
+
+;vertical : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same vertical column.
+
+;horizontal : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same horizontal row.
+
+;diagonal : posn posn -> boolean
+;Determines if posn1 and posn2 lie on a diagonal. If two posns lie on a negative-sloping diagonal, then their difference is a multiple of (1,1). If two posns lie on a positive-sloping diagonal, their difference is a multiple of (1,-1). In general, two posns lie on the same diagonal if the absolute value of the differences between the coordinates are equal.
+
+
+
+(define (build-board n f)
+ (local ((define (build-board-rows-cols rows cols f)
+ (cond
+ [(or (zero? rows)
+ (zero? cols)) empty]
+ [else (append (build-board-rows-cols (sub1 rows) cols f)
+ (list (build-list cols (lambda (x) (f rows (+ x 1))))))])))
+ (build-board-rows-cols n n f)))
+
+(define (board-ref a-board i j)
+ (cond
+ [(> i 1) (board-ref (rest a-board) (sub1 i) j)]
+ [else (list-ref (first a-board) (- j 1))]))
+
+(define (threatened? posn1 posn2)
+ (local ((define (vertical posn1 posn2)
+ (= (posn-y posn1)
+ (posn-y posn2)))
+ (define (horizontal posn1 posn2)
+ (= (posn-x posn1)
+ (posn-x posn2)))
+ (define (diagonal posn1 posn2)
+ (= (abs (- (posn-x posn1)
+ (posn-x posn2)))
+ (abs (- (posn-y posn1)
+ (posn-y posn2))))))
+ (or (vertical posn1 posn2)
+ (horizontal posn1 posn2)
+ (diagonal posn1 posn2))))
+
+(define (threatened-loq? aposn aloq)
+ (ormap (lambda (aqueen) (threatened? aposn aqueen)) aloq))
+
+(define (build-board-loq n aloq)
+ (build-board n
+ (lambda (row col)
+ (cond
+ [(threatened-loq? (make-posn row col) aloq) false]
+ [else true]))))
+
+;placement : N (listof posns) -> board or false
+;Place n queens on a square 8x8 chessboard, returning the board if the placement is possible and false otherwise.
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns) or false
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false.
+
+;place-queen : N (listof posns) -> (listof posns)
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns)
+;Place n queens in the remaining spaces such that
+
+;build-board-loq : n (listof posns) -> board
+;Builds an n by n board with occupied or threatened squares filled in given by aloq (a list of queens represented by (listof posns)).
+#|
+(define (placement n aloq)
+ (build-board-loq 8 (place-queen n empty)))
+|#
+
+(define (test-place-queen n)
+ (place-queen n empty))
+
+(define (place-queen n aloq)
+ (cond
+ [(zero? n) aloq]
+ [else (local ((define spaces (empty-spaces dim dim aloq))
+ (define new-loq (place-queen-spaces n spaces aloq)))
+ (cond
+ [(boolean? new-loq) false]
+ [else new-loq]))]))
+
+(define (place-queen-spaces n spaces aloq)
+ (cond
+ [(zero? n) aloq]
+ [(empty? spaces) false]
+ [else
+ (local ((define first-guess (place-queen (sub1 n) (cons (first spaces) aloq))))
+ (cond
+ [(boolean? first-guess)
+ (place-queen-spaces n (rest spaces) aloq)]
+ [else (place-queen (sub1 n) (cons (first spaces) aloq))]))]))
+
+;empty-spaces : N N (listof posns) -> (listof posns)
+;Given aloq, determine the empty spaces on an mxn chessboard.
+
+(define (empty-spaces m n aloq)
+ (local ((define posn-list (create-posn-list m n)))
+ (filter (lambda (p) (not (threatened-loq? p aloq))) posn-list)))
+
+;Tests
+;(empty-spaces 8 8 (list (make-posn 4 1)
+; (make-posn 8 5)))
+
+;create-posn-list : N N -> (listof posns)
+;Given rows and cols, creates a (listof posns) representing the chessboard of dimensions rows by cols. Each element represents the index of a tile in the rows by cols chessboard.
+
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 0) empty]
+ [(> rows 0) (append (create-posn-list (sub1 rows) cols)
+ (build-list cols (lambda (c) (make-posn rows (+ c 1)))))]))
+
+(define dim 10)
+(test-place-queen dim)
\ No newline at end of file
blob - /dev/null
blob + 99aa9b142edf148a0ea7ee9e93d001ad295dcc94 (mode 644)
--- /dev/null
+++ 28.2.1-2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;A row is either
+;1. empty or
+;2. (cons bool ro)
+;where bool is a boolean (true/false), and ro is a row.
+
+;A chessboard is either
+;1. empty or
+;2. (cons r cb)
+;where r is a row and cb is a chessboard.
+
+;Specifically, an nxn chessboard is a (listof (listof booleans)) such that the length of each element in the chessboard is the same as the length of the chessboard itself. That is, the chessboard is square. A false value in a chessboard represents a tile that is either occupied by a queen or threatened by one; a true value represents an available square for the non-threatened placement of a new chess piece.
+
+;build-board : N (N N -> boolean) -> board
+;Creates a square chessboard with dimensions n by n, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. The board's first entry is the top left corner, 1 x 1 (not 0 x 0).
+
+;build-board : N N (N N -> boolean) -> board
+;Creates a chessboard with dimensions rows by cols, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. Build-board utilizes structural recursion on rows, and thus must ultimately terminate.
+
+;board-ref : board N[>=1] N[>=1] -> board
+;Returns the value of the i x j entry in a-board.
+
+;threatened? : posn posn -> boolean
+;Determine if posn1 can threaten posn2.
+
+;threatened-loq? : posn (listof posns) -> boolean
+;Determine if aposn is threatened by aloq.
+
+;vertical : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same vertical column.
+
+;horizontal : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same horizontal row.
+
+;diagonal : posn posn -> boolean
+;Determines if posn1 and posn2 lie on a diagonal. If two posns lie on a negative-sloping diagonal, then their difference is a multiple of (1,1). If two posns lie on a positive-sloping diagonal, their difference is a multiple of (1,-1). In general, two posns lie on the same diagonal if the absolute value of the differences between the coordinates are equal.
+
+
+
+(define (build-board n f)
+ (local ((define (build-board-rows-cols rows cols f)
+ (cond
+ [(or (zero? rows)
+ (zero? cols)) empty]
+ [else (append (build-board-rows-cols (sub1 rows) cols f)
+ (list (build-list cols (lambda (x) (f rows (+ x 1))))))])))
+ (build-board-rows-cols n n f)))
+
+(define (board-ref a-board i j)
+ (cond
+ [(> i 1) (board-ref (rest a-board) (sub1 i) j)]
+ [else (list-ref (first a-board) (- j 1))]))
+
+(define (threatened? posn1 posn2)
+ (local ((define (vertical posn1 posn2)
+ (= (posn-y posn1)
+ (posn-y posn2)))
+ (define (horizontal posn1 posn2)
+ (= (posn-x posn1)
+ (posn-x posn2)))
+ (define (diagonal posn1 posn2)
+ (= (abs (- (posn-x posn1)
+ (posn-x posn2)))
+ (abs (- (posn-y posn1)
+ (posn-y posn2))))))
+ (or (vertical posn1 posn2)
+ (horizontal posn1 posn2)
+ (diagonal posn1 posn2))))
+
+(define (threatened-loq? aposn aloq)
+ (ormap (lambda (aqueen) (threatened? aposn aqueen)) aloq))
+
+(define (build-board-loq n aloq)
+ (build-board n
+ (lambda (row col)
+ (cond
+ [(threatened-loq? (make-posn row col) aloq) false]
+ [else true]))))
+
+;placement : N (listof posns) -> board or false
+;Place n queens on a square 8x8 chessboard, returning the board if the placement is possible and false otherwise.
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns) or false
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false.
+
+;place-queen : N (listof posns) -> (listof posns)
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns)
+;Place n queens in the remaining spaces such that
+
+;build-board-loq : n (listof posns) -> board
+;Builds an n by n board with occupied or threatened squares filled in given by aloq (a list of queens represented by (listof posns)).
+#|
+(define (placement n aloq)
+ (build-board-loq 8 (place-queen n empty)))
+|#
+
+(define (test-place-queen n)
+ (place-queen n empty))
+
+(define (place-queen n aloq)
+ (cond
+ [(zero? n) aloq]
+ [else (local ((define spaces (empty-spaces dim dim aloq))
+ (define new-loq (place-queen-spaces n spaces aloq)))
+ (cond
+ [(boolean? new-loq) false]
+ [else new-loq]))]))
+
+(define (place-queen-spaces n spaces aloq)
+ (cond
+ [(zero? n) aloq]
+ [(empty? spaces) false]
+ [else
+ (local ((define first-guess (place-queen (sub1 n) (cons (first spaces) aloq))))
+ (cond
+ [(boolean? first-guess)
+ (place-queen-spaces n (rest spaces) aloq)]
+ [else (place-queen (sub1 n) (cons (first spaces) aloq))]))]))
+
+;empty-spaces : N N (listof posns) -> (listof posns)
+;Given aloq, determine the empty spaces on an mxn chessboard.
+
+(define (empty-spaces m n aloq)
+ (local ((define filled-board (build-board-loq n aloq))
+ (define posn-list (create-posn-list m n)))
+ (filter (lambda (p) (board-ref filled-board (posn-x p) (posn-y p))) posn-list)))
+
+
+;create-posn-list : N N -> (listof posns)
+;Given rows and cols, creates a (listof posns) representing the chessboard of dimensions rows by cols. Each element represents the index of a tile in the rows by cols chessboard.
+
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 0) empty]
+ [(> rows 0) (append (create-posn-list (sub1 rows) cols)
+ (build-list cols (lambda (c) (make-posn rows (+ c 1)))))]))
+
+(define dim 8)
+(test-place-queen dim)
\ No newline at end of file
blob - /dev/null
blob + eaef90c32d353e1dd876b9529a9369b95d268950 (mode 644)
--- /dev/null
+++ 28.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+Exercise 28.2.1. Develop a data definition for chessboards.
+
+Hint: Use lists. Represent tiles with true and false. A value of true should indicate that a position is available for the placement of a queen; false should indicate that a position is occupied by, or threatened by, a queen. Solution
+
+A row is either
+1. empty or
+2. (cons bool ro)
+where bool is a boolean (true/false), and ro is a row.
+
+A chessboard is either
+1. empty or
+2. (cons r cb)
+where r is a row and cb is a chessboard.
+
+Specifically, an nxn chessboard is a (listof (listof booleans)) such that the length of each element in the chessboard is the same as the length of the chessboard itself. That is, the chessboard is square.
\ No newline at end of file
blob - /dev/null
blob + 255be9fd27547a007ad9645bdf0efa4fc83b2172 (mode 644)
--- /dev/null
+++ 29.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |29|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+Exercise 29.1.1. A number tree is either a number or a pair of number trees. Develop the function sum-tree, which determines the sum of the numbers in a tree. How should we measure the size of a tree? What is its abstract running time? Solution
+
+Exercise 29.1.2. Hand-evaluate (maxi2 (list 0 1 2 3)) in a manner similar to our evaluation of (maxi (list 0 1 2 3)). What is the abstract running time of maxi2? Solution
+
+A number tree is either
+1. a number or
+2. (make-tree nt1 nt2)
+where nt1 and nt2 are number trees.
+
+(define-struct tree left right)
\ No newline at end of file
blob - /dev/null
blob + b5e7a377e0b7c039990ec0bf7ebb0f97244a7980 (mode 644)
--- /dev/null
+++ 29.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |29.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;Exercise 29.1.1. A number tree is either a number or a pair of number trees. Develop the function sum-tree, which determines the sum of the numbers in a tree. How should we measure the size of a tree? What is its abstract running time? Solution
+;
+;Exercise 29.1.2. Hand-evaluate (maxi2 (list 0 1 2 3)) in a manner similar to our evaluation of (maxi (list 0 1 2 3)). What is the abstract running time of maxi2? Solution
+;
+;A number tree (nt) is either
+;1. a number or
+;2. (make-tree nt1 nt2)
+;where nt1 and nt2 are number trees.
+
+(define-struct tree (left right))
+
+;sum-tree : nt -> number
+;Sums all the numbers in a number tree.
+(define (sum-tree ant)
+ (cond
+ [(number? ant) ant]
+ [else (+ (sum-tree (tree-left ant))
+ (sum-tree (tree-right ant)))]))
+
+(define tree1 (make-tree (make-tree (make-tree 4 9)
+ (make-tree 2 7))
+ (make-tree 5 -3)))
+
+(sum-tree tree1)
+
+The size of a tree can be measured either by the number of nested trees it contains or by the length of the most nested tree. (if so, then the running time is on the order of N) I prefer the first since its definition allows easier calculation of the abstract running time. Or it could be considered the number of numbers (on the order of N?).
+
+(+ (sum-tree (tree-left ant))
+ (sum-tree (tree-right ant)))
+
+(+ (+ (sum-tree (tree-left ant))
+ (sum-tree (tree-right ant)))
+ (sum-tree (tree-right ant)))
\ No newline at end of file
blob - /dev/null
blob + 83d644c4d12e110c5acc578a7bf05e3bf597ebb7 (mode 644)
--- /dev/null
+++ 29.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |29.1|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+Exercise 29.1.1. A number tree is either a number or a pair of number trees. Develop the function sum-tree, which determines the sum of the numbers in a tree. How should we measure the size of a tree? What is its abstract running time? Solution
+
+Exercise 29.1.2. Hand-evaluate (maxi2 (list 0 1 2 3)) in a manner similar to our evaluation of (maxi (list 0 1 2 3)). What is the abstract running time of maxi2? Solution
+
+A number tree is either
+1. a number or
+2. (make-tree nt1 nt2)
+where nt1 and nt2 are number trees.
+
+(define-struct tree left right)
\ No newline at end of file
blob - /dev/null
blob + 277538078bd9cbe11b501f323a27dafce90781aa (mode 644)
--- /dev/null
+++ 29.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;A graph is a (vectorof (listof nodes)).
+
+;neighbors : node graph -> (listof nodes)
+;Return the neighbors of anode given agraph.
+
+(define (neighbors anode agraph)
+ (vector-ref agraph anode))
+
+
+(define G (vector '(1 4)
+ '(4 5)
+ '(3)
+ empty
+ '(2 5)
+ '(3 6)
+ empty))
+
+;find-route : node node graph -> (listof nodes)
+;Find a route from ori to dest given G and return the route as a (listof nodes).
+
+(define (find-route ori dest G)
+ (cond
+ [(= ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+;find-route/list : (listof nodes) node graph -> (listof nodes)
+;Find a route from lo-ori (listof nodes) to dest given G and return the route as a (listof nodes).
+
+(define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond
+ [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
blob - /dev/null
blob + a4779399c8e55d4d31ccf231423a4fee37a806e9 (mode 644)
--- /dev/null
+++ 29.3.14
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+#|
+Exercise 29.3.14. Develop a vector representation for chessboards of size n × n for n in N. Then develop the following two functions on chessboards:
+
+;; build-board : N (N N -> boolean) -> board
+;; to create a board of size n x n,
+;; fill each position with indices i and j with (f i j)
+(define (build-board n f) ...)
+
+;; board-ref : board N N -> boolean
+;; to access a position with indices i, j on a-board
+(define (board-ref a-board i j) ...)
+|#
+;A row is a (vectorof booleans), and the length of the row (the number of columns) is equivalent to (vector-length r), where r is the row in question.
+
+;A chessboard is a (vectorof (vectorof booleans)). Specifically, an rxc chessboard has a length of r, and each element in the chessboard has a length of c. A chessboard is square if r is the same as c. A false value in a chessboard represents a tile that is either occupied by a queen or threatened by one, whereas a true value represents an available square for the non-threatened placement of a new chess piece.
+
+;build-board : N (N N -> boolean) -> board
+;Creates a square chessboard with dimensions n by n, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. The board's first entry is the top left corner, 1 x 1 (not 0 x 0).
+
+(define (build-board n f)
+ (build-board-rows-cols n n f))
+
+;build-board : N N (N N -> boolean) -> board
+;Creates a chessboard with dimensions rows by cols, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices.
+
+(define (build-board-rows-cols rows cols f)
+ (build-vector rows (lambda (r)
+ (build-vector cols (lambda (c) (f (+ r 1) (+ c 1)))))))
+
+;board-ref : board N[>=1] N[>=1] -> board
+;Returns the value of the i x j entry in a-board.
+
+(define (board-ref a-board i j)
+ (vector-ref (vector-ref a-board (sub1 i)) (sub1 j)))
+
+#|
+;Tests
+
+(define board-1 (vector (vector true true true)
+ (vector false true false)))
+(vector (vector (board-ref board-1 1 1) (board-ref board-1 1 2) (board-ref board-1 1 3))
+ (vector (board-ref board-1 2 1) (board-ref board-1 2 2) (board-ref board-1 2 3)))
+|#
+
+;threatened? : posn posn -> boolean
+;Determine if posn1 can threaten posn2.
+
+(define (threatened? posn1 posn2)
+ (local ((define (vertical posn1 posn2)
+ (= (posn-y posn1)
+ (posn-y posn2)))
+ (define (horizontal posn1 posn2)
+ (= (posn-x posn1)
+ (posn-x posn2)))
+ (define (diagonal posn1 posn2)
+ (= (abs (- (posn-x posn1)
+ (posn-x posn2)))
+ (abs (- (posn-y posn1)
+ (posn-y posn2))))))
+ (or (vertical posn1 posn2)
+ (horizontal posn1 posn2)
+ (diagonal posn1 posn2))))
+
+
+
+;threatened-loq? : posn (listof posns) -> boolean
+;Determine if aposn is threatened by aloq.
+
+;vertical : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same vertical column.
+
+;horizontal : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same horizontal row.
+
+;diagonal : posn posn -> boolean
+;Determines if posn1 and posn2 lie on a diagonal. If two posns lie on a negative-sloping diagonal, then their difference is a multiple of (1,1). If two posns lie on a positive-sloping diagonal, their difference is a multiple of (1,-1). In general, two posns lie on the same diagonal if the absolute value of the differences between the coordinates are equal.
+
+
+#|
+;Test
+(build-board-rows-cols 8 8 (lambda (x y)
+ (cond
+ [(< x y) true]
+ [else false])))
+|#
+
+(define (place-queen n aloq)
+ (cond
+ [(zero? n) aloq]
+ [else (local ((define spaces (empty-spaces dim dim aloq))
+ (define new-loq (place-queen-spaces n spaces aloq)))
+ (cond
+ [(boolean? new-loq) false]
+ [else new-loq]))]))
+
+(define (place-queen-spaces n spaces aloq)
+ (cond
+ [(zero? n) aloq]
+ [(empty? spaces) false]
+ [else
+ (local ((define first-guess (place-queen (sub1 n) (cons (first spaces) aloq))))
+ (cond
+ [(boolean? first-guess)
+ (place-queen-spaces n (rest spaces) aloq)]
+ [else first-guess]))]))
+
+(define (threatened-loq? aposn aloq)
+ (ormap (lambda (aqueen) (threatened? aposn aqueen)) aloq))
+
+;empty-spaces : N N (listof posns) -> (listof posns)
+;Given aloq, determine the empty spaces on an mxn chessboard.
+
+(define (empty-spaces m n aloq)
+ (local ((define posn-list (create-posn-list m n)))
+ (filter (lambda (p) (not (threatened-loq? p aloq))) posn-list)))
+
+;create-posn-list : N N -> (listof posns)
+;Given rows and cols, creates a (listof posns) representing the chessboard of dimensions rows by cols. Each element represents the index of a tile in the rows by cols chessboard.
+
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 0) empty]
+ [(> rows 0) (append (create-posn-list (sub1 rows) cols)
+ (build-list cols (lambda (c) (make-posn rows (+ c 1)))))]))
+
+(define dim 8)
+(place-queen dim empty)
+
+
+#|
+
+
+(define (build-board-loq n aloq)
+ (build-board n
+ (lambda (row col)
+ (cond
+ [(threatened-loq? (make-posn row col) aloq) false]
+ [else true]))))
+
+;placement : N (listof posns) -> board or false
+;Place n queens on a square 8x8 chessboard, returning the board if the placement is possible and false otherwise.
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns) or false
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false.
+
+;place-queen : N (listof posns) -> (listof posns)
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns)
+;Place n queens in the remaining spaces such that
+
+;build-board-loq : n (listof posns) -> board
+;Builds an n by n board with occupied or threatened squares filled in given by aloq (a list of queens represented by (listof posns)).
+#|
+(define (placement n aloq)
+ (build-board-loq 8 (place-queen n empty)))
+|#
+
+(define (test-place-queen n)
+ (place-queen n empty))
+
+
+;empty-spaces : N N (listof posns) -> (listof posns)
+;Given aloq, determine the empty spaces on an mxn chessboard.
+
+(define (empty-spaces m n aloq)
+ (local ((define posn-list (create-posn-list m n)))
+ (filter (lambda (p) (not (threatened-loq? p aloq))) posn-list)))
+
+;Tests
+;(empty-spaces 8 8 (list (make-posn 4 1)
+; (make-posn 8 5)))
+
+
+(define dim 10)
+(test-place-queen dim)
+|#
blob - /dev/null
blob + b5c1ffee3c5c46995149ef4cb464e051abfcf88e (mode 644)
--- /dev/null
+++ 29.3.14~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;A row is either
+;1. empty or
+;2. (cons bool ro)
+;where bool is a boolean (true/false), and ro is a row.
+
+;A chessboard is either
+;1. empty or
+;2. (cons r cb)
+;where r is a row and cb is a chessboard.
+
+;Specifically, an nxn chessboard is a (listof (listof booleans)) such that the length of each element in the chessboard is the same as the length of the chessboard itself. That is, the chessboard is square. A false value in a chessboard represents a tile that is either occupied by a queen or threatened by one; a true value represents an available square for the non-threatened placement of a new chess piece.
+
+;build-board : N (N N -> boolean) -> board
+;Creates a square chessboard with dimensions n by n, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. The board's first entry is the top left corner, 1 x 1 (not 0 x 0).
+
+;build-board : N N (N N -> boolean) -> board
+;Creates a chessboard with dimensions rows by cols, with the i x j position filled with (f i j) where f is a function that returns a boolean given the two indices. Each time we build a row that is cols wide. Build-board utilizes structural recursion on rows, and thus must ultimately terminate.
+
+;board-ref : board N[>=1] N[>=1] -> board
+;Returns the value of the i x j entry in a-board.
+
+;threatened? : posn posn -> boolean
+;Determine if posn1 can threaten posn2.
+
+;threatened-loq? : posn (listof posns) -> boolean
+;Determine if aposn is threatened by aloq.
+
+;vertical : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same vertical column.
+
+;horizontal : posn posn -> boolean
+;Given posn1 and posn2, determine if the two posns lie in the same horizontal row.
+
+;diagonal : posn posn -> boolean
+;Determines if posn1 and posn2 lie on a diagonal. If two posns lie on a negative-sloping diagonal, then their difference is a multiple of (1,1). If two posns lie on a positive-sloping diagonal, their difference is a multiple of (1,-1). In general, two posns lie on the same diagonal if the absolute value of the differences between the coordinates are equal.
+
+
+
+(define (build-board n f)
+ (local ((define (build-board-rows-cols rows cols f)
+ (cond
+ [(or (zero? rows)
+ (zero? cols)) empty]
+ [else (append (build-board-rows-cols (sub1 rows) cols f)
+ (list (build-list cols (lambda (x) (f rows (+ x 1))))))])))
+ (build-board-rows-cols n n f)))
+
+(define (board-ref a-board i j)
+ (cond
+ [(> i 1) (board-ref (rest a-board) (sub1 i) j)]
+ [else (list-ref (first a-board) (- j 1))]))
+
+(define (threatened? posn1 posn2)
+ (local ((define (vertical posn1 posn2)
+ (= (posn-y posn1)
+ (posn-y posn2)))
+ (define (horizontal posn1 posn2)
+ (= (posn-x posn1)
+ (posn-x posn2)))
+ (define (diagonal posn1 posn2)
+ (= (abs (- (posn-x posn1)
+ (posn-x posn2)))
+ (abs (- (posn-y posn1)
+ (posn-y posn2))))))
+ (or (vertical posn1 posn2)
+ (horizontal posn1 posn2)
+ (diagonal posn1 posn2))))
+
+(define (threatened-loq? aposn aloq)
+ (ormap (lambda (aqueen) (threatened? aposn aqueen)) aloq))
+
+(define (build-board-loq n aloq)
+ (build-board n
+ (lambda (row col)
+ (cond
+ [(threatened-loq? (make-posn row col) aloq) false]
+ [else true]))))
+
+;placement : N (listof posns) -> board or false
+;Place n queens on a square 8x8 chessboard, returning the board if the placement is possible and false otherwise.
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns) or false
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false.
+
+;place-queen : N (listof posns) -> (listof posns)
+;Given n and aloq, return a new (listof posns) with a new queen placed if possible. Otherwise, return false
+
+;place-queen-spaces : N (listof posns) (listof posns) -> (listof posns)
+;Place n queens in the remaining spaces such that
+
+;build-board-loq : n (listof posns) -> board
+;Builds an n by n board with occupied or threatened squares filled in given by aloq (a list of queens represented by (listof posns)).
+#|
+(define (placement n aloq)
+ (build-board-loq 8 (place-queen n empty)))
+|#
+
+(define (test-place-queen n)
+ (place-queen n empty))
+
+(define (place-queen n aloq)
+ (cond
+ [(zero? n) aloq]
+ [else (local ((define spaces (empty-spaces dim dim aloq))
+ (define new-loq (place-queen-spaces n spaces aloq)))
+ (cond
+ [(boolean? new-loq) false]
+ [else new-loq]))]))
+
+(define (place-queen-spaces n spaces aloq)
+ (cond
+ [(zero? n) aloq]
+ [(empty? spaces) false]
+ [else
+ (local ((define first-guess (place-queen (sub1 n) (cons (first spaces) aloq))))
+ (cond
+ [(boolean? first-guess)
+ (place-queen-spaces n (rest spaces) aloq)]
+ [else (place-queen (sub1 n) (cons (first spaces) aloq))]))]))
+
+;empty-spaces : N N (listof posns) -> (listof posns)
+;Given aloq, determine the empty spaces on an mxn chessboard.
+
+(define (empty-spaces m n aloq)
+ (local ((define posn-list (create-posn-list m n)))
+ (filter (lambda (p) (not (threatened-loq? p aloq))) posn-list)))
+
+;Tests
+;(empty-spaces 8 8 (list (make-posn 4 1)
+; (make-posn 8 5)))
+
+;create-posn-list : N N -> (listof posns)
+;Given rows and cols, creates a (listof posns) representing the chessboard of dimensions rows by cols. Each element represents the index of a tile in the rows by cols chessboard.
+
+(define (create-posn-list rows cols)
+ (cond
+ [(= rows 0) empty]
+ [(> rows 0) (append (create-posn-list (sub1 rows) cols)
+ (build-list cols (lambda (c) (make-posn rows (+ c 1)))))]))
+
+(define dim 10)
+(test-place-queen dim)
\ No newline at end of file
blob - /dev/null
blob + 349fe434f352f9f96f754543221086c44c33d238 (mode 644)
--- /dev/null
+++ 29.3.15
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;A matrix is a (vectorof (vectorof numbers)). Specifically, an rxc matrix has a vector-length of r, and each element has a vector-length of c.
+
+;build-matrix : N N (N N -> number) -> matrix
+;Given rows and cols, builds a matrix according to f. f takes in two N's and returns a number (f rows cols).
+
+(define (build-matrix rows cols f)
+ (build-vector rows (lambda (r)
+ (build-vector cols (lambda (c) (f (+ r 1) (+ c 1)))))))
+
+(define (transpose a-matrix)
+ (build-matrix (vector-length (vector-ref a-matrix 0))
+ (vector-length a-matrix)
+ (lambda (r c) (vector-ref (vector-ref a-matrix (sub1 c)) (sub1 r)))))
+
+(define matrix-A (vector (vector 1 0 -1)
+ (vector 2 0 9)
+ (vector 1 1 1)))
+(transpose matrix-A)
\ No newline at end of file
blob - /dev/null
blob + 72abf94ddd05aa460c712f1d1cbb65f46409805c (mode 644)
--- /dev/null
+++ 29.3.15~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+A matrix is a (vectorof (vectorof numbers)). Specifically, an rxc matrix has a vector-length of r, and each element has a vector-length of c.
+
+(define (build-matrix rows cols f)
+ (build-vector rows (lambda (r)
+ (build-vector cols (lambda (c) (f (+ r 1) (+ c 1)))))))
+
+(define (transpose a-matrix)
\ No newline at end of file
blob - /dev/null
blob + 559d424ba90d8c0c25d4badde8336034cc8c8902 (mode 644)
--- /dev/null
+++ 29.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+A graph is a (vectorof (listof nodes)).
+
+neighbors : node graph -> (listof nodes)
+Return the neighbors of anode given agraph.
+
+(define (neighbors anode agraph)
+ (vector-ref agraph anode))
+
+
blob - /dev/null
blob + c0f8161c3e30fb300900310ffa8b6464c59793b6 (mode 644)
--- /dev/null
+++ 29.3.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+(define G1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+(define G2 (vector '(1 4)
+ '(4 5)
+ '(3)
+ empty
+ '(2 5)
+ '(3 6)
+ empty))
+
+(define (find-route1 ori dest G)
+ (local ((define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+ (define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+ (define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+ (define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G)))))
+ (find-route ori dest G)))
+
+(define (find-route2 ori dest G)
+ (local ((define (find-route ori dest G)
+ (cond
+ [(= ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+ (define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond
+ [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+ (define (neighbors anode agraph)
+ (vector-ref agraph anode)))
+ (find-route ori dest G)))
+
+(define n 100000)
+(time (andmap (lambda (x) (equal? (find-route1 'A 'G G1)
+ (list 'A 'B 'E 'F 'G))) (build-list n identity)))
+(time (andmap (lambda (x) (equal? (find-route2 0 6 G2)
+ (list 0 1 4 5 6))) (build-list n identity)))
\ No newline at end of file
blob - /dev/null
blob + faadb9eb4fc734bdbfd3c0b2e1665b58e78c6ab5 (mode 644)
--- /dev/null
+++ 29.3.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+(define (find-route1 ori dest G)
+ (local ((define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+ (define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+ (define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G)))))
+ find-route ori dest G))
+
+(define (neighbors anode agraph)
+ (vector-ref agraph anode))
+
+
+(define G (vector '(1 4)
+ '(4 5)
+ '(3)
+ empty
+ '(2 5)
+ '(3 6)
+ empty))
+
+;find-route : node node graph -> (listof nodes)
+;Find a route from ori to dest given G and return the route as a (listof nodes).
+
+(define (find-route ori dest G)
+ (cond
+ [(= ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+;find-route/list : (listof nodes) node graph -> (listof nodes)
+;Find a route from lo-ori (listof nodes) to dest given G and return the route as a (listof nodes).
+
+(define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond
+ [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
\ No newline at end of file
blob - /dev/null
blob + a016b89430528cdfd8f578dc9f2a4c8f91a76d6a (mode 644)
--- /dev/null
+++ 29.3.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+(define G2 (vector '(1 4)
+ '(4 5)
+ '(1 3)
+ empty
+ '(2 5)
+ '(3 6)
+ empty))
\ No newline at end of file
blob - /dev/null
blob + c0f8161c3e30fb300900310ffa8b6464c59793b6 (mode 644)
--- /dev/null
+++ 29.3.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+(define G1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+(define G2 (vector '(1 4)
+ '(4 5)
+ '(3)
+ empty
+ '(2 5)
+ '(3 6)
+ empty))
+
+(define (find-route1 ori dest G)
+ (local ((define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+ (define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+ (define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+ (define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G)))))
+ (find-route ori dest G)))
+
+(define (find-route2 ori dest G)
+ (local ((define (find-route ori dest G)
+ (cond
+ [(= ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+ (define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond
+ [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+ (define (neighbors anode agraph)
+ (vector-ref agraph anode)))
+ (find-route ori dest G)))
+
+(define n 100000)
+(time (andmap (lambda (x) (equal? (find-route1 'A 'G G1)
+ (list 'A 'B 'E 'F 'G))) (build-list n identity)))
+(time (andmap (lambda (x) (equal? (find-route2 0 6 G2)
+ (list 0 1 4 5 6))) (build-list n identity)))
\ No newline at end of file
blob - /dev/null
blob + 6d19d20f13c031225cd80cd7bcb09c20e6cc394c (mode 644)
--- /dev/null
+++ 29.3.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;vector-sum : vector -> number
+;Given avector, sum all its entries.
+
+(define (vector-sum avector)
+ (local ((define (vector-sum-aux i)
+ (cond
+ [(zero? i) 0]
+ [else (+ (vector-ref avector (sub1 i))
+ (vector-sum-aux (sub1 i)))])))
+ (vector-sum-aux (vector-length avector))))
+
+;vector-sum-aux : vector N -> number
+;Given avector and i, sum up the numbers within a vector in [0,i) starting from i-1 to 0.
+
+
+;vector-sum-lr : vector -> number
+;Given avector, sums the vector from left to right (like English-reading humans would do).
+
+(define (vector-sum-lr avector)
+ (local ((define avec-length (vector-length avector))
+ (define (vector-sum-lr-aux i)
+ (cond
+ [(= avec-length i) 0]
+ [else (+ (vector-ref avector i)
+ (vector-sum-lr-aux (add1 i)))])))
+ (vector-sum-lr-aux 0)))
+
+;vector-sum-lr-aux : vector N -> number
+;Given avector and i, sum up the elements within the vector from [0,i) from left to right.
+
+
+(define vector1 (vector 5 6 7 8))
+(equal? (vector-sum vector1) 26)
+(equal? (vector-sum vector1) (vector-sum-lr vector1))
blob - /dev/null
blob + c786c758a0e4435a268d17cc482a9151046b6f55 (mode 644)
--- /dev/null
+++ 29.3.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+Exercise 29.3.4. Evaluate (vector-sum-aux (vector -1 3/4 1/4) 3) by hand. Show the major steps only. Check the evaluation with DrScheme's stepper. In what order does the function add up the numbers of the vector?
+
+Use a local-expression to define a single function vector-sum. Then remove the vector argument from the inner function definition. Why can we do that? Solution
\ No newline at end of file
blob - /dev/null
blob + edf7825f7b50e3d9221b219ac7ef0ee642f0819f (mode 644)
--- /dev/null
+++ 29.3.7
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;norm : vector -> number
+;Produces the square root of the sum of the numbers in avector.
+
+(define (norm avector)
+ (sqrt (sum-of-squares avector 0)))
+
+;sum-of-squares : vector N -> number
+;Given avector and i, square the element in avector from [i,vector-length) and then sum them
+
+(define (sum-of-squares avector i)
+ (cond
+ [(= (vector-length avector) i) 0]
+ [else (+ (sqr (vector-ref avector i))
+ (sum-of-squares avector (add1 i)))]))
+
+;vector-contains-doll? : (vectorof symbols) -> boolean
+;Given avector, determine if it contains 'doll.
+
+(define (vector-contains-doll? avector)
+ (vector-contains-doll?-aux avector 0))
+
+;vector-contains-doll?-aux : (vectorof symbols) N -> boolean
+;Given avector and i, determine if avector contains 'doll.
+
+(define (vector-contains-doll?-aux avector i)
+ (cond
+ [(= (vector-length avector) i) false]
+ [else (or (symbol=? (vector-ref avector i) 'doll)
+ (vector-contains-doll?-aux avector (add1 i)))]))
+(define vector2 (vector 'robot
+ 'car
+ 'eraser
+ 'pen
+ 'motorcycle
+ 'bicycle
+ 'helmet
+ 'monitor
+ 'dolly
+ 'policeman
+ 'diamond))
+(vector-contains-doll? vector2)
\ No newline at end of file
blob - /dev/null
blob + 3aa7b81a642bdb619e6c1dea0b031bca51ae2dbe (mode 644)
--- /dev/null
+++ 29.3.7~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;norm : vector -> number
+;Produces the square root of the sum of the numbers in avector.
+
+(define (norm avector)
+ (sqrt (sum-of-squares avector 0)))
+
+;sum-of-squares : vector N -> number
+;Given avector and i, square the element in avector from [i,vector-length) and then sum them
+
+(define (sum-of-squares avector i)
+ (cond
+ [(= (vector-length avector) i) 0]
+ [else (+ (sqr (vector-ref avector i))
+ (sum-of-squares avector (add1 i)))]))
\ No newline at end of file
blob - /dev/null
blob + 9ddcc10e24a0eb8e1a403f72e9f6134d8b11bc45 (mode 644)
--- /dev/null
+++ 29.3.9
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;binary-contains? : vector N -> N or false
+;Given avector and key, returns the index of the key in avector if possible and returns false if key is not in avector.
+
+(define (binary-contains? avector key)
+ (binary-contains?-aux avector key 0 (sub1 (vector-length avector))))
+
+;binary-contains?-aux : (vectorof number) [sorted] N N -> N or false
+;Given avector (sorted), key, left, and right (the boundaries of avector to be searched), binary-contains?-aux determines the index of the key in the vector if it occurs using the binary-search algorithm. Otherwise, returns false.
+;Termination Argument: Each interval must necessarily reduce in size by at least 50% each recursion. Since the midpoint is not included in the subsequent recursion, we are guaranteed that the interval must actually decrease in size each recursion until both left and right are equal and the interval consists of only a single number. Hence, we are guaranteed that the function will terminate.
+
+(define (binary-contains?-aux avector key left right)
+ (local ((define mid (round (+ left (/ (- right left) 2)))))
+ (cond
+ [(= (vector-ref avector mid) key) mid]
+ [(= left right) false]
+ [(< (vector-ref avector mid) key) (binary-contains?-aux avector key (+ mid 1) right)]
+ [else (binary-contains?-aux avector key left (- mid 1))])))
+
+#|
+
+Tests
+
+(define v1 (vector 1 4 6 7 10
+ 15 16 17 19 23
+ 25 26 27 28))
+
+(define v2 (build-vector 10000000 identity))
+
+(binary-contains? v1 27)
+(time (binary-contains? v2 9638723))
+|#
+;abstract run-time is log2(x)?
+
+;vector-count : (vectorof symbols) symbol -> N
+;Given v and s, determine the number of times s occurs in v.
+
+(define (vector-count v s)
+ (vector-count-aux v s 0))
+
+;vector-count-aux : (vectorof symbols) symbol N -> N
+;Given v and s, determine the number of times s occurs in v using i, which indicates the current index.
+
+(define (vector-count-aux v s i)
+ (cond
+ [(= (vector-length v) i) 0]
+ [(symbol=? (vector-ref v i) s) (+ 1
+ (vector-count-aux v s (add1 i)))]
+ [else (vector-count-aux v s (add1 i))]))
+#|
+Test
+
+(define v3 (vector 'hi 'my 'name 'is 'sam 'and 'I 'am 'a 'programmer 'how 'about 'you
+ 'are 'you 'a 'programmer 'too?))
+(vector-count v3 'programmer)
+
+|#
+
+;scalar-product : (vectorof number) number -> (vectorof number)
+;Multiply each element in v by s to compute the scalar product.
+
+(define (scalar-product v s)
+ (build-vector (vector-length v)
+ (lambda (x) (* s (vector-ref v x)))))
+
+(define v4 (vector 5 6 10 3))
+(scalar-product v4 -2)
+
+;id-vector : N -> (vectorof 1's)
+;Returns a vector containing n number of 1's.
+
+(define (id-vector n)
+ (build-vector n (lambda (x) 1)))
+
+(equal? (id-vector 6) (vector 1 1 1 1 1 1))
+
+;vector+ : (vectorof numbers) (vectorof numbers) -> (vectorof numbers)
+;Computes the sum of v1 and v2.
+;ASSUMPTION : v1 and v2 have the same length.
+
+;(define (vector+ v1 v2)
+; (build-vector (vector-length v1)
+; (lambda (x) (+ (vector-ref v1 x)
+; (vector-ref v2 x)))))
+
+;vector-op : (vectorof numbers) (vectorof numbers) (number number -> number) -> (vectorof numbers)
+;
+;Given v1 and v2, build a new list of vectors where each element in the new vector is created by performing op on the corresponding elements of v1 and v2.
+
+(define (vector-op v1 v2 op)
+ (build-vector (vector-length v1)
+ (lambda (x) (op (vector-ref v1 x)
+ (vector-ref v2 x)))))
+
+(define (vector+ v1 v2)
+ (vector-op v1 v2 +))
+(define (vector- v1 v2)
+ (vector-op v1 v2 -))
+
+(define v5 (vector 1 9 4 2 -3))
+(define v6 (vector -5 -6 2 9 0))
+(vector+ v5 v6)
+(vector- v5 v6)
+
+;checked-vector+ : (vectorof numbers) (vectorof numbers) -> (vectorof numbers)
+
+(define (checked-vector+ v1 v2)
+ (cond
+ [(and (vector? v1)
+ (vector? v2)
+ (= (vector-length v1) (vector-length v2))) (vector+ v1 v2)]
+ [else (error 'checked-vector+ "expected arg: 2 vectors")]))
+
+;checked-vector- : (vectorof numbers) (vectorof numbers) -> (vectorof numbers)
+
+(define (checked-vector- v1 v2)
+ (cond
+ [(and (vector? v1)
+ (vector? v2)
+ (= (vector-length v1) (vector-length v2))) (vector- v1 v2)]
+ [else (error 'checked-vector- "expected arg: 2 vectors")]))
\ No newline at end of file
blob - /dev/null
blob + 4dfb4b5c971ed3e28a0e1ee6a53341bd88ce9278 (mode 644)
--- /dev/null
+++ 29.3.9~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#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")))))
+;binary-contains? : (vectorof number) [sorted] N -> N or false
+Given avector (sorted) and key, determines the index of the key in the vector if it occurs using the binary-search algorithm. Otherwise, returns false.
+
+(define (binary-contains? avector key)
+ (cond
+ []
+ []))
+
+#|
+
+Exercise 29.3.9. Develop the function binary-contains?. It consumes a sorted vector of numbers and a key, which is also a number. The goal is to determine the index of the key, if it occurs in the vector, or false. Use the binary-search algorithm from section 27.3.
+
+Determine the abstract running time of binary-contains? and compare with that of contains?, the function that searches for a key in a vector in the linear fashion of vector-contains-doll?.
+
+Suppose we are to represent a collection of numbers. The only interesting problem concerning the collection is to determine whether it contains some given number. Which data representation is preferable for the collection: lists or vectors? Why?
+
+|#
\ No newline at end of file
blob - /dev/null
blob + 9a3d6848c28737058e328845745e7cb7553f0f65 (mode 644)
--- /dev/null
+++ 3.14.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |3.14|) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; profit : number -> number
+;; Calculates profit as a difference between profit and revenue depending on the ticket-price
+;; Example: (profit 5) should give 415.2, (profit 4) should give 889.2, (profit 3) should give 1063.2
+
+(define (profit ticket-price)
+ (- (revenue ticket-price) (costs ticket-price)))
+
+;; revenue : number -> number
+;; Calculates revenue, which is given as the ticket-price times the number of attendees.
+;; Example: (revenue 5) should give 600, (revenue 4) should give 1080, and (revenue 3) should give 1260
+(define (revenue ticket-price)
+ (* ticket-price (attendees ticket-price)))
+
+;; costs : number -> number
+;; Calculates costs, which has a fixed cost plus a variable cost that depends on the ticket-price
+;; Example: (costs 5) should give 184.8, (costs 4) should give 190.8, and (costs 3) should give 196.8
+
+(define (costs ticket-price)
+ (+ 180 (* 0.04 (attendees ticket-price))))
+
+;; attendees : number -> number
+;; Calculates the number of attendees as a function of the ticket price
+;; Example: (attendees 5) should give 120
+;; Example: (attendees 4) should give 270
+;; Example: (attendees 3) should give 420
+
+(define (attendees ticket-price)
+ (+ 120 (* (/ (- 5 ticket-price) 0.1) 15)))
\ No newline at end of file
blob - /dev/null
blob + 963b3dcd4f80a74bb37cad287ae7bc42bc064b9e (mode 644)
--- /dev/null
+++ 3.14.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |3.14|) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; profit : number -> number
+;; Calculates profit as a difference between profit and revenue depending on the ticket-price
+
+(define (profit ticket-price)
+ (- (revenue ticket-price) (costs ticket-price)))
+
+;; revenue : number -> number
+;; Calculates revenue, which is given as the ticket-price times the number of attendees.
+
+(define (revenue ticket-price)
+ (* ticket-price (attendees ticket-price)))
+
+;; costs : number -> number
+;; Calculates costs, which has a fixed cost plus a variable cost that depends on the ticket-price
+
+(define (costs ticket-price)
+ (* 1.50 (attendees ticket-price)))
+
+;; attendees : number -> number
+;; Calculates the number of attendees as a function of the ticket price
+;; Example: (attendees 5) should give 120
+;; Example: (attendees 4) should give 270
+;; Example: (attendees 3) should give 420
+
+(define (attendees ticket-price)
+ (+ 120 (* (/ (- 5 ticket-price) 0.1) 15)))
\ No newline at end of file
blob - /dev/null
blob + 1c1b4d52d45fefa94bf69f426856de1dfac06836 (mode 644)
--- /dev/null
+++ 3.2.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.2.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; profit : number -> number
+;; Calculates profit as a difference between profit and revenue depending on the ticket-price
+;; Example: (profit 5) should give 415.2, (profit 4) should give 889.2, (profit 3) should give 1063.2
+
+(define (profit ticket-price)
+ (- (revenue ticket-price) (costs ticket-price)))
+
+;; revenue : number -> number
+;; Calculates revenue, which is given as the ticket-price times the number of attendees.
+;; Example: (revenue 5) should give 600, (revenue 4) should give 1080, and (revenue 3) should give 1260
+(define (revenue ticket-price)
+ (* ticket-price (attendees ticket-price)))
+
+;; costs : number -> number
+;; Calculates costs, which has a fixed cost plus a variable cost that depends on the ticket-price
+;; Example: (costs 5) should give 184.8, (costs 4) should give 190.8, and (costs 3) should give 196.8
+
+(define (costs ticket-price)
+ (+ 180 (* 0.04 (attendees ticket-price))))
+
+;; attendees : number -> number
+;; Calculates the number of attendees as a function of the ticket price
+;; Example: (attendees 5) should give 120
+;; Example: (attendees 4) should give 270
+;; Example: (attendees 3) should give 420
+
+(define (attendees ticket-price)
+ (+ 120 (* (/ (- 5 ticket-price) 0.1) 15)))
\ No newline at end of file
blob - /dev/null
blob + 65bfa0d8ede522196077bc71737cc8e32de94e9b (mode 644)
--- /dev/null
+++ 3.2.1.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.2.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define FIXED 180)
+(define VARY 0.04)
+(define BASALATTENDANCE 120)
+(define BASALPRICE 5)
+(define INCRATTEND 15)
+(define INCRPRICE 0.1)
+
+;; profit : number -> number
+;; Calculates profit as a difference between profit and revenue depending on the ticket-price
+;; Example: (profit 5) should give 415.2, (profit 4) should give 889.2, (profit 3) should give 1063.2
+
+(define (profit ticket-price)
+ (- (revenue ticket-price) (costs ticket-price)))
+
+;; revenue : number -> number
+;; Calculates revenue, which is given as the ticket-price times the number of attendees.
+;; Example: (revenue 5) should give 600, (revenue 4) should give 1080, and (revenue 3) should give 1260
+(define (revenue ticket-price)
+ (* ticket-price (attendees ticket-price)))
+
+;; costs : number -> number
+;; Calculates costs, which has a fixed cost plus a variable cost that depends on the ticket-price
+;; Example: (costs 5) should give 184.8, (costs 4) should give 190.8, and (costs 3) should give 196.8
+
+(define (costs ticket-price)
+ (+ FIXED (* VARY (attendees ticket-price))))
+
+;; attendees : number -> number
+;; Calculates the number of attendees as a function of the ticket price
+;; Example: (attendees 5) should give 120
+;; Example: (attendees 4) should give 270
+;; Example: (attendees 3) should give 420
+
+(define (attendees ticket-price)
+ (+ BASALATTENDANCE (* (/ (- BASALPRICE ticket-price) INCRPRICE) INCRATTEND)))
\ No newline at end of file
blob - /dev/null
blob + d20d669ba75cea6c3be903622259b8f2c7ffc79a (mode 644)
--- /dev/null
+++ 3.3.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define INCHES->CM 2.54)
+(define FEET->INCHES 12)
+(define YARDS->FEET 3)
+(define RODS->YARDS 5.5)
+
+;; inches->cm : number -> number
+;; Converts inches to cm by multiplying by the conversion factor INCHES->CM
+
+(define (inches->cm inches)
+ (* inches INCHES->CM))
+
+;; feet->inches : number -> number
+;; Converts feet to inches by multiplying by the conversion factor FEET->INCHES
+
+(define (feet->inches feet)
+ (* feet FEET->INCHES))
+
+;; yards->feet : number -> number
+;; Converts yards to feet by multiplying by the conversion factor YARDS->FEET
+
+(define (yards->feet yards)
+ (* yards YARDS->FEET))
+
+;; rods->yards : number -> number
+;; Converts rods to yards by multiplying by the conversion factor RODS->YARDS
+
+(define (rods->yards rods)
+ (* rods RODS->YARDS))
\ No newline at end of file
blob - /dev/null
blob + 582cba398fa072d488c6618ec246ddd8f4766316 (mode 644)
--- /dev/null
+++ 3.3.1.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define INCHES->CM 2.54)
+(define FEET->INCHES 12)
+(define YARDS->FEET 3)
+(define RODS->YARDS 5.5)
+(define FURLONGS->RODS 40)
+(define MILES->FURLONGS 8)
+
+;; inches->cm : number -> number
+;; Converts inches to cm by multiplying by the conversion factor INCHES->CM
+
+(define (inches->cm inches)
+ (* inches INCHES->CM))
+
+;; feet->inches : number -> number
+;; Converts feet to inches by multiplying by the conversion factor FEET->INCHES
+
+(define (feet->inches feet)
+ (* feet FEET->INCHES))
+
+;; yards->feet : number -> number
+;; Converts yards to feet by multiplying by the conversion factor YARDS->FEET
+
+(define (yards->feet yards)
+ (* yards YARDS->FEET))
+
+;; rods->yards : number -> number
+;; Converts rods to yards by multiplying by the conversion factor RODS->YARDS
+
+(define (rods->yards rods)
+ (* rods RODS->YARDS))
+
+;; furlongs->rods : number -> number
+
+(define (furlongs->rods furlongs)
+ (* furlongs FURLONGS->RODS))
+
+;; miles->furlongs : number -> number
+
+(define (miles->furlongs miles)
+ (* miles MILES->FURLONGS))
+
+;; feet->cm : number -> number
+;; Converts feet to cm by first converting to inches
+
+(define (feet->cm feet)
+ (inches->cm (feet->inches feet)))
+
+;; yards->cm : number -> number
+;; Converts yards to cm by first converting to feet
+
+(define (yards->cm yards)
+ (feet->cm (yards->feet yards)))
+
+;; rods->inches : number -> number
+;; Converts rods to inches by first converting to yards, then converting to feet, then converting to inches
+
+(define (rods->inches rods)
+ (feet->inches
+ (yards->feet
+ (rods->yards rods))))
+
+;; miles->feet: number -> number
+;; Converts miles to feet by first converting to furlongs, then to rods, then to yards, then to feet
+
+(define (miles->feet miles)
+ (yards->feet
+ (rods->yards
+ (furlongs->rods
+ (miles->furlongs miles)))))
\ No newline at end of file
blob - /dev/null
blob + d2036d736d1afe4b8488e4ac2307b18018931cbd (mode 644)
--- /dev/null
+++ 3.3.2-3.3.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.2-3.3.4) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define PI 3.14)
+
+;; area-of-circle : number -> number
+;; Computes the area of the circle given the radius
+
+(define (area-of-circle radius)
+ (* PI (sqr radius)))
+
+;; area-of-ring : number number -> number
+;; Computes the area of a ring given the inner and outer radii
+
+(define (area-of-ring inner outer)
+ (- (area-of-circle outer) (area-of-circle inner)))
+
+;; volume-cylinder : number number -> number
+;; Computes the volume of a cylinder given the radius and height
+
+(define (volume-cylinder radius height)
+ (* (area-of-circle radius) height))
+
+;; area-cylinder : number number -> number
+;; Computes the surface area of a cylinder given the radius and height
+
+(define (area-cylinder radius height)
+ (+ (area-of-circle radius)
\ No newline at end of file
blob - /dev/null
blob + ddf035cde8d2802e279d1292cbba88c2bed34a12 (mode 644)
--- /dev/null
+++ 3.3.2-3.3.4.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.2-3.3.4) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define PI 3.14)
+
+;; area-of-circle : number -> number
+;; Computes the area of the circle given the radius
+
+(define (area-of-circle radius)
+ (* PI (sqr radius)))
+
+;; area-of-ring : number number -> number
+;; Computes the area of a ring given the inner and outer radii.
+;; It does so by subtracting the area of the inner circle from the outer circle.
+
+(define (area-of-ring inner outer)
+ (- (area-of-circle outer) (area-of-circle inner)))
+
+;; volume-cylinder : number number -> number
+;; Computes the volume of a cylinder given the radius and height.
+;; It does so by multiplying the area of the base by the height.
+
+(define (volume-cylinder radius height)
+ (* (area-of-circle radius) height))
+
+;; lateral-surface-area : number number -> number
+;; Computes the lateral surface area of a cylinder given the radius and height (the circumference times the height)
+
+(define (lateral-surface-area radius height)
+ (* 2 PI radius height))
+
+;; area-cylinder : number number -> number
+;; Computes the surface area of a cylinder given the radius and height
+;; It does so by adding 2 times the area of the base by the lateral surface area.
+
+(define (area-cylinder radius height)
+ (+
+ (* 2 (area-of-circle radius))
+ (lateral-surface-area radius height)))
+
+;; area-pipe : number number number -> number
+;; Computes the surface area of a pipe given its inner radii, thickness, and height.
+;; It does so by finding the lateral surface area of the outer shell and the inner shell and adding this to two times the surface area of either the top or bottom ring.
+
+(define (area-pipe inner thick height)
+ (+
+ (lateral-surface-area (+ inner thick) height)
+ (lateral-surface-area inner height)
+ (* 2 (area-of-ring inner (+ inner thick)))))
+
+;; area-pipe2 : number number number -> number
+;; Computes the surface area of a pipe according the the following formula
+;; A = 2*PI*(inner+thick)*height)+(2*PI*inner*height)+2*PI*((inner+thick)^2-inner^2)
+
+(define (area-pipe2 inner thick height)
+ (+
+ (* 2 PI (+ inner thick) height)
+ (* 2 PI inner height)
+ (* 2 PI
+ (- (sqr (+ inner thick)) (sqr inner)))))
\ No newline at end of file
blob - /dev/null
blob + 920372712290d0419957d77eceed149699d52343 (mode 644)
--- /dev/null
+++ 3.3.5.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.5) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; velocity : number number -> number
+;; Computes the velocity at time given the acceleration constant g
+
+(define (velocity time g)
+ (* time g))
+
+;; height : number number -> number
+;; Consumes the parameters time and g.
+;; Computes the height at time t given the velocity and the time by multiplying the two and dividing by two.
+
+(define (height time g)
+ (* 0.5 (velocity time g) time))
\ No newline at end of file
blob - /dev/null
blob + a08189ff6ab536e7ecc7c25cdc8cda4afab5ba00 (mode 644)
--- /dev/null
+++ 3.3.6.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.6) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; Celsius->Fahrenheit : number -> number
+;; Computes the Fahrenheit temperature given the Celsius temperature
+
+(define (Celsius->Fahrenheit Celsius Fahrenheit)
+ (+ (* 9/5 Celsius) 32))
+
+;; Fahrenheit->Celsius : number -> number
+;; Computes the Celsius temperature given the Fahrenheit temperature
+
+(define (Fahrenheit->Celsius Celsius Fahrenheit)
+ (* 5/9 (- Fahrenheit 32)))
+
+;; I : number -> number
\ No newline at end of file
blob - /dev/null
blob + 41d13a5d5222f32246e391f4b46b54337e8ac437 (mode 644)
--- /dev/null
+++ 3.3.6.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.6) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; Celsius->Fahrenheit : number -> number
+;; Computes the Fahrenheit temperature given the Celsius temperature
+
+(define (Celsius->Fahrenheit Celsius)
+ (+ (* 9/5 Celsius) 32))
+
+;; Fahrenheit->Celsius : number -> number
+;; Computes the Celsius temperature given the Fahrenheit temperature
+
+(define (Fahrenheit->Celsius Fahrenheit)
+ (* 5/9 (- Fahrenheit 32)))
+
+;; I : number -> number
+;; to convert a Fahrenheit temperature to Celsius and back
+(define (I f)
+ (Celsius->Fahrenheit (Fahrenheit->Celsius f)))
\ No newline at end of file
blob - /dev/null
blob + 93166e4161e51bbc57155588729b2b1ccfc6bcbe (mode 644)
--- /dev/null
+++ 30.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |30.1|) (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")))))
+;relative-2-absolute : (listof numbers) -> (listof numbers)
+;Convert alon into absolute distances. The first element is (first alon) away from the origin.
+
+(define (relative-2-absolute alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (first alon)
+ (add-to-each (first alon) (relative-2-absolute (rest alon))))]))
+
+(define (add-to-each n alon)
+ (map (lambda (x) (+ n x)) alon))
+
+;On the order of N^2
\ No newline at end of file
blob - /dev/null
blob + a864926cf6620b356bd1ac023cf365ebb3912bb0 (mode 644)
--- /dev/null
+++ 30.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |30.1|) (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")))))
+relative-2-absolute : (listof numbers) -> (listof numbers)
+Convert alon into absolute distances. The first element is (first alon) away from the origin.
+
+(define (relative-2-absolute alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (first alon)
+ (relative-2-absolute (add-to-each (first alon) (rest alon))))]))
\ No newline at end of file
blob - /dev/null
blob + a3600c79e778591c8eff8ddd94bfbe14c12ac784 (mode 644)
--- /dev/null
+++ 30.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |30.2|) (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")))))
+;A node is a symbol.
+;
+;A pair is a list
+;(cons n1 (cons n2)), ie, (list n1 n2)
+;where n1 and n2 are symbols representing nodes.
+;
+;A simple-graph is a (listof pairs).
+
+;route-exists? : node node simple-graph -> boolean
+;Determines if there exists a route from orig to dest given the simple-graph sg.
+
+;route-exists?-aux : node (listof nodes) -> boolean
+;Determine if there exists a route from orig to dest given the simple-graph sg. accu-seen represents nodes that have been visited before. If a node is visited twice and a route is not determined, return false.
+
+(define (route-exists? orig dest sg)
+ (local ((define (route-exists?-aux orig accu-seen)
+ (cond
+ [(symbol=? orig dest) true]
+ [(contains orig accu-seen) false]
+ [else (route-exists?-aux (neighbor orig sg) (cons orig accu-seen))])))
+ (route-exists?-aux orig empty)))
+
+;neighbor : node simple-graph -> node
+;Given anode, find its neighbor in simple-graph.
+
+(define (neighbor anode sg)
+ (cond
+ [(empty? sg) (error 'neighbor "node does not exist")]
+ [(symbol=? (first (first sg)) anode) (second (first sg))]
+ [else (neighbor anode (rest sg))]))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+
+(define (contains x alox)
+ (ormap (lambda (item) (equal? x item)) alox))
+#|
+ Old Body
+ (cond
+ [(empty? alox) false]
+ [(equal? x (first alox)) true]
+ [else (contains x (rest alox))]))
+|#
+(define SimpleG
+ '((A B)
+ (B C)
+ (C E)
+ (D E)
+ (E B)
+ (F F)))
+
+(not (route-exists? 'A 'D SimpleG))
+(route-exists? 'D 'B SimpleG)
+(not (route-exists? 'F 'D SimpleG))
+(route-exists? 'D 'C SimpleG)
\ No newline at end of file
blob - /dev/null
blob + b06f6a18cc3f68be65b767f1a368bd46689f9acd (mode 644)
--- /dev/null
+++ 30.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |30.2|) (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")))))
+A node is a symbol.
+
+A pair is a list
+(cons n1 (cons n2)), ie, (list n1 n2)
+where n1 and n2 are symbols representing nodes.
+
+A simple-graph is a (listof pairs).
+
+route-exists? : node node sg (listof nodes) -> boolean
\ No newline at end of file
blob - /dev/null
blob + c29cc244af0fafc5961a20a64ff097671c720d73 (mode 644)
--- /dev/null
+++ 30.2.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |30.2|) (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")))))
+;A node is a symbol.
+;
+;A pair is a vector
+;(vector n1 n2)
+;where n1 and n2 are symbols representing nodes.
+;
+;A simple-graph is a (vectorof pairs), that is, a (vectorof (vector n1 n2)), where n1 and n2 are nodes.
+
+;route-exists? : node node simple-graph -> boolean
+;Determines if there exists a route from orig to dest given the simple-graph sg.
+
+;route-exists?-aux : node (listof nodes) -> boolean
+;Determine if there exists a route from orig to dest given the simple-graph sg. accu-seen represents nodes that have been visited before. If a node is visited twice and a route is not determined, return false.
+
+(define (route-exists? orig dest sg)
+ (local ((define (route-exists?-aux orig accu-seen)
+ (cond
+ [(symbol=? orig dest) true]
+ [(contains orig accu-seen) false]
+ [else (route-exists?-aux (neighbor orig sg) (cons orig accu-seen))])))
+ (route-exists?-aux orig empty)))
+
+;neighbor : node simple-graph -> node
+;Given anode, find its neighbor in simple-graph.
+
+(define (neighbor anode sg)
+ (neighbor-aux anode sg 0))
+
+;neighbor-aux : node simple-graph N -> node
+;Find the neighbor of anode in sg using the index i.
+
+(define (neighbor-aux anode sg i)
+ (cond
+ [(= (vector-length sg) i) (error 'neighbor-aux "node not found")]
+ [(symbol=? (vector-ref (vector-ref sg i) 0) anode) (vector-ref (vector-ref sg i) 1)]
+ [else (neighbor-aux anode sg (add1 i))]))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+
+(define (contains x alox)
+ (ormap (lambda (item) (equal? x item)) alox))
+#|
+ Old Body
+ (cond
+ [(empty? alox) false]
+ [(equal? x (first alox)) true]
+ [else (contains x (rest alox))]))
+|#
+(define SimpleG
+ (vector (vector 'A 'B)
+ (vector 'B 'C)
+ (vector 'C 'E)
+ (vector 'D 'E)
+ (vector 'E 'B)
+ (vector 'F 'F)))
+
+(not (route-exists? 'A 'D SimpleG))
+(route-exists? 'D 'B SimpleG)
+(not (route-exists? 'F 'D SimpleG))
+(route-exists? 'D 'C SimpleG)
\ No newline at end of file
blob - /dev/null
blob + a295c938165478767d5a59fbf603f4b0f4cdb0f5 (mode 644)
--- /dev/null
+++ 30.2.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |30.2|) (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")))))
+;A node is a symbol.
+;
+;A pair is a vector
+;(vector n1 n2)
+;where n1 and n2 are symbols representing nodes.
+;
+;A simple-graph is a (vectorof pairs), that is, a (vectorof (vector n1 n2)), where n1 and n2 are nodes.
+
+;route-exists? : node node simple-graph -> boolean
+;Determines if there exists a route from orig to dest given the simple-graph sg.
+
+;route-exists?-aux : node (listof nodes) -> boolean
+;Determine if there exists a route from orig to dest given the simple-graph sg. accu-seen represents nodes that have been visited before. If a node is visited twice and a route is not determined, return false.
+
+(define (route-exists? orig dest sg)
+ (local ((define (route-exists?-aux orig accu-seen)
+ (cond
+ [(symbol=? orig dest) true]
+ [(contains orig accu-seen) false]
+ [else (route-exists?-aux (neighbor orig sg) (cons orig accu-seen))])))
+ (route-exists?-aux orig empty)))
+
+;neighbor : node simple-graph -> node
+;Given anode, find its neighbor in simple-graph.
+
+(define (neighbor anode sg)
+ (cond
+ [(empty? sg) (error 'neighbor "node does not exist")]
+ [(symbol=? (first (first sg)) anode) (second (first sg))]
+ [else (neighbor anode (rest sg))]))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+
+(define (contains x alox)
+ (ormap (lambda (item) (equal? x item)) alox))
+#|
+ Old Body
+ (cond
+ [(empty? alox) false]
+ [(equal? x (first alox)) true]
+ [else (contains x (rest alox))]))
+|#
+(define SimpleG
+ '((A B)
+ (B C)
+ (C E)
+ (D E)
+ (E B)
+ (F F)))
+
+(not (route-exists? 'A 'D SimpleG))
+(route-exists? 'D 'B SimpleG)
+(not (route-exists? 'F 'D SimpleG))
+(route-exists? 'D 'C SimpleG)
\ No newline at end of file
blob - /dev/null
blob + 79740543628f04a2aa1710ddfc986259530853d0 (mode 644)
--- /dev/null
+++ 30.2.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |30.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+(define Graph2
+ '((A (B E))
+ (B (E F))
+ (C (B D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+
+;A node is a symbol.
+;
+;A path is a list of the form
+;(cons no lon)
+;where no is a node and lon is a (listof nodes).
+;
+;A graph is either
+;1. empty or
+;2. (cons pa gr)
+;where pa is a path and gr is a graph.
+
+;find-route : node node graph (listof nodes) -> (listof nodes) or false
+;Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false. If a node that has already been traversed before is traversed again, return false (to prevent infinite loops).
+
+(define (find-route ori dest G accu-seen)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [(contains ori accu-seen) false]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G (cons ori accu-seen))))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+;find-route/list : (listof nodes) node graph (listof nodes)-> (listof nodes) or false
+;Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+(define (find-route/list lo-ori dest G accu-seen)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G accu-seen)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G accu-seen)]
+ [else possible-route]))]))
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+(define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G))))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+
+(define (contains x alox)
+ (ormap (lambda (item) (equal? x item)) alox))
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+(define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+
+(find-route 'A 'G Graph2 empty)
+(find-route 'C 'G Graph2 empty)
+(find-route 'F 'G Graph2 empty)
+
+#|
+
+;A node-path is a list
+;(cons no1 no2 lon)
+;where no1, no2 are nodes (representing the origin and destination, respectively), and lon is a (listof nodes) representing the route from the origin to the destination.
+
+;test-on-all-nodes : graph -> (listof (listof node-path))
+;Tests find-route for all possible pairs of nodes in G. We first generate all possible permutations of node pairs and we apply find-route to each node pair. We then return the resulting (listof node-paths), each node-path being a list containing the origin, destination, and the (listof nodes) taken to get from the origin to the destination.
+
+;find-route : node node graph -> (listof nodes) or false
+
+(define (test-on-all-nodes G)
+ (map (lambda (x)
+ (list (first x)
+ (second x)
+ (find-route (first x) (second x) G)))
+ (generate-pairs (extract-nodes G))))
+
+;extract-nodes : graph -> (listof nodes)
+;Extracts the nodes from G and returns them as a (listof nodes).
+
+(define (extract-nodes G)
+ (map (lambda (x) (first x)) G))
+
+;generate-pairs : (listof nodes) -> (listof (listof nodes))
+;Generates all possible pairs of nodes from alon and returns it as a (listof (listof nodes)), each element containing a pair of nodes.
+
+;generate-pairs : (listof nodes) (listof nodes) -> (listof (listof nodes))
+;Pair the first element of current-lon with the entire complete-lon, and repeat the process to return a (listof (listof nodes)), each element containing a pair of nodes, to give all possible pairings.
+
+
+(define (generate-pairs alon)
+ (local ((define (generate-pairs current-lon complete-lon)
+ (cond
+ [(empty? current-lon) empty]
+ [else (append (pair (first current-lon)
+ (remove (first current-lon) complete-lon))
+ (generate-pairs (rest current-lon) complete-lon))])))
+ (generate-pairs alon alon)))
+
+;pair : node (listof nodes) -> (listof (listof nodes))
+;Given anode and alon, generate all possible pairs of anode with elements in alon.
+
+(define (pair anode alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (list anode (first alon))
+ (pair anode (rest alon)))]))
+
+;remove : X (listof X) -> (listof X)
+;Given x and alox, removes the first instance of x in alox and returns the remaining list. If x is not present in alox, simply returns alox.
+
+(define (remove x alox)
+ (cond
+ [(empty? alox) empty]
+ [(equal? x (first alox)) (rest alox)]
+ [else (cons (first alox)
+ (remove x (rest alox)))]))
+(equal? (find-route 'B 'C Graph2) '(B E C))
+
+|#
\ No newline at end of file
blob - /dev/null
blob + 4bd581b1b78fb97c0f318e0822cad3e355ff239a (mode 644)
--- /dev/null
+++ 30.2.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |30.2|) (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 #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define Graph1
+ '((A (B E))
+ (B (E F))
+ (C (D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+(define Graph2
+ '((A (B E))
+ (B (E F))
+ (C (B D))
+ (D ())
+ (E (C F))
+ (F (D G))
+ (G ())))
+
+
+;A node is a symbol.
+;
+;A path is a list of the form
+;(cons no lon)
+;where no is a node and lon is a (listof nodes).
+;
+;A graph is either
+;1. empty or
+;2. (cons pa gr)
+;where pa is a path and gr is a graph.
+
+;find-route : node node graph -> (listof nodes) or false
+;Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
+
+(define (find-route ori dest G)
+ (cond
+ [(symbol=? ori dest) (list ori)]
+ [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
+ (cond
+ [(boolean? possible-route) false]
+ [else (cons ori possible-route)]))]))
+
+;find-route/list : (listof nodes) node graph -> (listof nodes) or false
+;Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
+
+(define (find-route/list lo-ori dest G)
+ (cond
+ [(empty? lo-ori) false]
+ [else (local ((define possible-route (find-route (first lo-ori) dest G)))
+ (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
+ [else possible-route]))]))
+
+;neighbors : node graph -> (listof nodes)
+;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
+
+(define (neighbors anode G)
+ (first (rest (assf (lambda (x) (equal? anode x)) G))))
+
+;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
+;; to find the first item on alop for whose first item p? holds
+
+(define (assf op aloxy)
+ (cond
+ [(empty? aloxy) false]
+ [(op (first (first aloxy))) (first aloxy)]
+ [else (assf op (rest aloxy))]))
+
+;(find-route 'A 'G Graph)
+;(find-route 'C 'G Graph)
+
+;A node-path is a list
+;(cons no1 no2 lon)
+;where no1, no2 are nodes (representing the origin and destination, respectively), and lon is a (listof nodes) representing the route from the origin to the destination.
+
+;test-on-all-nodes : graph -> (listof (listof node-path))
+;Tests find-route for all possible pairs of nodes in G. We first generate all possible permutations of node pairs and we apply find-route to each node pair. We then return the resulting (listof node-paths), each node-path being a list containing the origin, destination, and the (listof nodes) taken to get from the origin to the destination.
+
+;find-route : node node graph -> (listof nodes) or false
+
+(define (test-on-all-nodes G)
+ (map (lambda (x)
+ (list (first x)
+ (second x)
+ (find-route (first x) (second x) G)))
+ (generate-pairs (extract-nodes G))))
+
+;extract-nodes : graph -> (listof nodes)
+;Extracts the nodes from G and returns them as a (listof nodes).
+
+(define (extract-nodes G)
+ (map (lambda (x) (first x)) G))
+
+;generate-pairs : (listof nodes) -> (listof (listof nodes))
+;Generates all possible pairs of nodes from alon and returns it as a (listof (listof nodes)), each element containing a pair of nodes.
+
+;generate-pairs : (listof nodes) (listof nodes) -> (listof (listof nodes))
+;Pair the first element of current-lon with the entire complete-lon, and repeat the process to return a (listof (listof nodes)), each element containing a pair of nodes, to give all possible pairings.
+
+
+(define (generate-pairs alon)
+ (local ((define (generate-pairs current-lon complete-lon)
+ (cond
+ [(empty? current-lon) empty]
+ [else (append (pair (first current-lon)
+ (remove (first current-lon) complete-lon))
+ (generate-pairs (rest current-lon) complete-lon))])))
+ (generate-pairs alon alon)))
+
+;pair : node (listof nodes) -> (listof (listof nodes))
+;Given anode and alon, generate all possible pairs of anode with elements in alon.
+
+(define (pair anode alon)
+ (cond
+ [(empty? alon) empty]
+ [else (cons (list anode (first alon))
+ (pair anode (rest alon)))]))
+
+;remove : X (listof X) -> (listof X)
+;Given x and alox, removes the first instance of x in alox and returns the remaining list. If x is not present in alox, simply returns alox.
+
+(define (remove x alox)
+ (cond
+ [(empty? alox) empty]
+ [(equal? x (first alox)) (rest alox)]
+ [else (cons (first alox)
+ (remove x (rest alox)))]))
+(equal? (find-route 'B 'C Graph2) '(B E C))
\ No newline at end of file
blob - /dev/null
blob + fa43deb3d8604c012d5bc8926e2c610b927504ff (mode 644)
--- /dev/null
+++ 31.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+;sum-2 : (listof numbers) -> number
+(define (sum-1 alon)
+ (cond
+ [(empty? alon) 0]
+ [else (+ (first alon)
+ (sum-1 (rest alon)))]))
+
+;sum-2 : (listof numbers) -> number
+
+;sum-a : (listof numbers) number -> number
+
+(define (sum-2 alon)
+ (local ;;accumulator represents the sum of all the numbers preceding alon in alon0
+ ((define (sum-a alon accumulator)
+ (cond
+ [(empty? alon) accumulator]
+ [else (sum-a (rest alon) (+ (first alon) accumulator))])))
+ (sum-a alon 0)))
+
+(define (g-series n)
+ (cond
+ [(zero? n) empty]
+ [else (cons (expt -0.99 n) (g-series (sub1 n)))]))
+
+(sum-1 (g-series #i100))
+(sum-2 (g-series #i100))
+
+(* 10e15 (sum-1 (g-series #i100)))
+(* 10e15 (sum-2 (g-series #i100)))
+
+;right->left has errors (abs much larger than 0)
+;left->right is zero
+;But strange, not what I predicted
\ No newline at end of file
blob - /dev/null
blob + df9b4c6cf327027f20bc73c4a2db4c2368bed74a (mode 644)
--- /dev/null
+++ 31.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+;sum-2 : (listof numbers) -> number
+(define (sum-1 alon)
+ (cond
+ [(empty? alon) 0]
+ [else (+ (first alon)
+ (sum-1 (rest alon)))]))
+
+;sum-2 : (listof numbers) -> number
+
+;sum-a : (listof numbers) number -> number
+
+(define (sum-2 alon)
+ (local ;;accumulator represents the sum of all the numbers preceding alon in alon0
+ ((define (sum-a alon accumulator)
+ (cond
+ [(empty? alon) accumulator]
+ [else (sum-a (rest alon) (+ (first alon) accumulator))])))
+ (sum-a alon 0)))
+
+(define (g-series n)
+ (cond
+ [(zero? n) empty]
+ [else (cons (expt -0.99 n) (g-series (sub1 n)))]))
+
+(sum-1 (g-series #i100000))
+(sum-2 (g-series #i100000))
+
+(* 10e15 (sum-1 (g-series #i100000)))
+(* 10e15 (sum-2 (g-series #i100000)))
+
+;right->left has errors (abs much larger than 0)
+;left->right is zero
+;But strange, not what I predicted
\ No newline at end of file
blob - /dev/null
blob + 88e345319d10ac362010f4462d72bde4e19b072f (mode 644)
--- /dev/null
+++ 31.3.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+;!-1 : N -> number
+;Computes the factorial of n using structural recursion.
+
+(define (!-1 n)
+ (cond
+ [(zero? n) 1]
+ [else (* n (!-2 (sub1 n)))]))
+
+;!-2 : N -> number
+;Computes the factorial of n using an accumulator.
+
+(define (!-2 n)
+ (local ;the accumulator represents the product of the natural numbers from (x,n]
+ ((define (!-aux x accumulator)
+ (cond
+ [(zero? x) accumulator]
+ [else (!-aux (sub1 x) (* x accumulator))])))
+ (!-aux n 1)))
+
+
+;check-time : N N (N -> N) -> true
+;To evaluate (f x) t number of times.
+
+(define (check-time t x f)
+ (cond
+ [(= t 1) (f x)]
+ [else (check-time (sub1 t) x f))]))
+
+;(time (check-time 1000 10000 !-1))
+;(time (check-time 1000 10000 !-2))
+
+cpu time: 191024 real time: 192079 gc time: 26418
+cpu time: 194636 real time: 195881 gc time: 26174
\ No newline at end of file
blob - /dev/null
blob + db8f4ef017734279f826eeaf59577c65cf5e5a41 (mode 644)
--- /dev/null
+++ 31.3.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+! : N -> number
+Computes the factorial of n using structural recursion.
+
+(define (! n)
+ (cond
+ [(zero? n) 1]
+ [else (* n (! (sub1 n)))]))
+
\ No newline at end of file
blob - /dev/null
blob + 989b0dd243d87f46cde7e2c3c1e3023f34a1015a (mode 644)
--- /dev/null
+++ 31.3.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+(define-struct node (left right))
+
+;A binary-tree (bt) is either
+;1. empty or
+;2. (make-node l r)
+;where l,r are binary-trees (bt).
+;
+;height-1 : bt -> number
+;Determines the height (depth) of a binary tree using structural recursion.
+
+(define (height-1 abt)
+ (cond
+ [(empty? abt) 0]
+ [else (+ (max (height-1 (node-left abt))
+ (height-1 (node-right abt)))
+ 1)]))
+
+;height-2 : bt -> number
+;Determines the height (depth) of a binary tree using an accumulator.
+
+(define (height-2 abt)
+ (local ;; the accumulator represents the number of nodes passed in going from abt to bt0
+ ((define (height-aux bt0 accumulator)
+ (cond
+ [(empty? bt0) accumulator]
+ [else (max (height-aux (node-left bt0) (+ 1 accumulator))
+ (height-aux (node-right bt0) (+ 1 accumulator)))])))
+ (height-aux abt 0)))
+
+(define bt1 (make-node
+ (make-node
+ empty
+ (make-node empty empty))
+ empty))
+(height-1 bt1)
+(height-2 bt1)
\ No newline at end of file
blob - /dev/null
blob + e0f1ea15669f4105f80fbc3d6b578b421b4b7330 (mode 644)
--- /dev/null
+++ 31.3.3-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+;product : (listof numbers) -> numbers
+;Computes the product of alon0.
+
+(define (product alon0)
+ (local ;; the accumulator represents the product of all the numbers preceding alon1 in alon0,
+ ;; ie, it represents the product of (alon1,alon0]
+ ((define (product-accu alon1 accumulator)
+ (cond
+ [(empty? alon1) accumulator]
+ [else (product-accu (rest alon1) (* (first alon1) accumulator))])))
+ (product-accu alon0 1)))
+
+(equal? (product '(1 2 3 4 5 6)) 720)
+
+;how-many : (listof X) -> number
+;Determines how many items there are in alox0.
+
+(define (how-many alox0)
+ (local ;;the accumulator represents the number of items preceding alox1 in alox0
+ ((define (how-many-accu alox1 accumulator)
+ (cond
+ [(empty? alox1) accumulator]
+ [else (how-many-accu (rest alox1) (+ 1 accumulator))])))
+ (how-many-accu alox0 0)))
+
+(equal? (how-many '(5 hey joe 5 1 0 true true false)) 9)
+
+;add-to-pi : N -> number
+;Adds pi to n.
+
+(define (add-to-pi n0)
+ (local ;; the accumulator represents n0-n1+pi.
+ ((define (add-to-pi-accu n1 accumulator)
+ (cond
+ [(zero? n1) accumulator]
+ [else (add-to-pi-accu (sub1 n1) (add1 accumulator))])))
+ (add-to-pi-accu n0 pi)))
+
+;add-to-x : N -> number
+;Adds x to n.
+
+(define (add-to-x n0 x)
+ (local ;; the accumulator represents n0-n1+x.
+ ((define (add-to-x-accu n1 accumulator)
+ (cond
+ [(zero? n1) accumulator]
+ [else (add-to-x-accu (sub1 n1) (add1 accumulator))])))
+ (add-to-x-accu n0 x)))
+
+(equal? (add-to-x 5 6) 11)
+
+;make-palindrome : (listof X) -> (listof X)
+;Creates a palindrome from alox (non-empty list).
+
+(define (make-palindrome alox0)
+ (local ;The accumulator represents the items in alox0 preceding alox1
+ ;in reverse order as in alox0.
+ ((define (make-palindrome-accu alox1 accumulator)
+ (cond
+ [(empty? alox1) empty]
+ [(empty? (rest alox1)) (cons (first alox1) accumulator)]
+ [else (cons (first alox1)
+ (make-palindrome-accu (rest alox1) (cons (first alox1) accumulator)))])))
+ (make-palindrome-accu alox0 empty)))
+
+(make-palindrome '(a b c 1 5 3))
+
+;is-prime? : N -> boolean
+;Determines if n is a prime number.
+
+(define (is-prime? n0)
+ (local ;;accumulator i represents the numbers tested from [2,i) in order to
+ ;;determine if n1 is prime
+ ((define (is-prime?-accu n1 i)
+ (cond
+ [(= n1 i) true]
+ [(= (remainder n1 i) 0) false]
+ [else (is-prime?-accu n1 (add1 i))])))
+ (is-prime?-accu n0 2)))
+
+(and (is-prime? 2)
+ (is-prime? 3)
+ (not (is-prime? 4))
+ (is-prime? 5)
+ (not (is-prime? 6))
+ (is-prime? 7))
\ No newline at end of file
blob - /dev/null
blob + dbdbd8d73e16a8cede4e5a046d86df12d60b84e1 (mode 644)
--- /dev/null
+++ 31.3.3-2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+product : (listof numbers) -> numbers
+(define (product alon0)
+ (local ((define (product-accu alon1 accumulator)
+ (cond
+ []
+ [])))
+ (product alon0 ...)))
\ No newline at end of file
blob - /dev/null
blob + 7f16313dd2ee37a8be8f1c3aeef3dc807ff37aea (mode 644)
--- /dev/null
+++ 31.3.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+(define-struct node (left right))
+
+A binary-tree (bt) is either
+1. empty or
+2. (make-node l r)
+where l,r are binary-trees (bt).
+
+height : bt -> number
+Determines the height (depth) of a binary tree.
+
+(define (height abt)
+ (cond
+ [(empty? abt) 0]
+ [else (+ (max (height (node-left abt))
+ (height (node-right abt)))
+ 1)]))
\ No newline at end of file
blob - /dev/null
blob + a77a3c124ba66e67243a2eda81bf59da346f05d5 (mode 644)
--- /dev/null
+++ 31.3.7
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+;A digit is an N >=0 and <=9.
+
+;to10 : (listof digits) -> number
+;Converts alod1 into the corresponding number in base 10.
+
+;Examples:
+;(= (to10 (list 1 0 2))
+; 102)
+;
+;(= (to10 (list 2 1))
+; 21)
+
+(define (to10 alod0)
+ (local ;; accu represents the digits preceding alod1 in alod0 that have been converted
+ ;; to base 10
+ ((define (to10-accu alod1 accu)
+ (cond
+ [(empty? alod1) accu]
+ [else (to10-accu (rest alod1) (+ (* accu 10)
+ (first alod1)))])))
+ (to10-accu alod0 0)))
+
+(= (to10 (list 1 0 2 8 3 9 2 3))
+ 10283923)
+
+(= (to10 (list 2 1 9 8 7 2 3 4))
+ 21987234)
+
+;A b-digit is an N >=0 and <=(b-1), where b is an N.
+
+;to-b : (listof b-digits) N -> number
+;Converts alod1 into the corresponding number in base b.
+
+(define (to-b b alod0)
+ (local ;; accu represents the digits preceding alod1 in alod0 that have been converted
+ ;; to base 10
+ ((define (to-b-accu alod1 accu)
+ (cond
+ [(empty? alod1) accu]
+ [else (to-b-accu (rest alod1) (+ (* accu b)
+ (first alod1)))])))
+ (to-b-accu alod0 0)))
+
+(equal? (to-b 8 '(1 0 2)) 66)
+(equal? (to-b 10 '(1 0 2)) 102)
+(equal? (to-b 16 '(1 0 2 6 4 3)) 1058371)
\ No newline at end of file
blob - /dev/null
blob + e2c7b3033670b38a0c1a34c96b5b87f722c7133f (mode 644)
--- /dev/null
+++ 31.3.7~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.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")))))
+;A digit is an N >=0 and <=9.
+
+to10 : (listof digits) -> number
+
+Examples:
+(= (to10 (list 1 0 2))
+ 102)
+
+(= (to10 (list 2 1))
+ 21)
+
+(define (to10 alod0)
+ (local ;; accu represents the accumulator
+ ((define (to10-accu alod1 accu)
+ (cond
+ [(empty? alod1) 0]
+ [else (first alod1) (rest alod1) accu])))
+ (to10-accu alod0 ...)))
\ No newline at end of file
blob - /dev/null
blob + 2b5760da13db91d7c4ff378af9f4f6dab876ca34 (mode 644)
--- /dev/null
+++ 32.1.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.1|) (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")))))
+(define-struct child (father mother name date eyes))
+
+;A ftn (family tree node) is either
+;1. empty or
+;2. (make-child f m na da ec) where f, m are ftns, na, ec are symbols, and da is a number.
+;
+;all-blue-eyed-ancestors : ftn -> (listof symbol)
+;Given aftree0, return a list of all blue-eyed-ancestors as a (listof symbols).
+
+(define (all-blue-eyed-ancestors aftree0)
+ (local
+ ;accumulator represents all the blue-eyed ancestors on the mother side of tree paths
+ ;from [aftree0,aftree1)
+ ((define (all-a aftree1 accumulator)
+ (cond
+ [(empty? aftree1) accumulator]
+ [else
+ (local
+ ((define in-parents
+ (all-a (child-father aftree1)
+ (all-a (child-mother aftree1)
+ accumulator))))
+ (cond
+ [(symbol=? 'blue (child-eyes aftree1))
+ (cons (child-name aftree1)
+ in-parents)]
+ [else in-parents]))])))
+ (all-a aftree0 empty)))
+
+(define eight (make-child empty empty 'eight 1999 'blue))
+(define nine (make-child empty empty 'nine 1999 'blue))
+(define ten (make-child empty empty 'ten 1999 'blue))
+(define eleven (make-child empty empty 'eleven 1999 'blue))
+(define twelve (make-child empty empty 'twelve 1999 'blue))
+(define thirteen (make-child empty empty 'thirteen 1999 'blue))
+(define fourteen (make-child empty empty 'fourteen 1999 'blue))
+(define fifteen (make-child empty empty 'fifteen 1999 'blue))
+(define four (make-child eight nine 'four 1999 'blue))
+(define five (make-child ten eleven 'five 1999 'blue))
+(define six (make-child twelve thirteen 'six 1999 'blue))
+(define seven (make-child fourteen fifteen 'seven 1999 'blue))
+(define two (make-child four five 'two 1999 'blue))
+(define three (make-child six seven 'three 1999 'blue))
+(define one (make-child two three 'one 1999 'blue))
+
+(all-blue-eyed-ancestors one)
+
+#|
+(define Carl (make-child empty empty 'Carl 1926 'green))
+(define Bettina (make-child empty empty 'Bettina 1926 'green))
+(define Adam (make-child Carl Bettina 'Adam 1950 'yellow))
+(define Dave (make-child Carl Bettina 'Dave 1955 'black))
+(define Eva (make-child Carl Bettina 'Eva 1965 'blue))
+(define Fred (make-child empty empty 'Fred 1966 'pink))
+(define Gustav (make-child Fred Eva 'Gustav 1988 'brown))
+|#
+
+;all-blue-eyed-ancestors2 : ftn -> (listof symbols)
+
+(define (all-blue-eyed-ancestors2 aftree0)
+ (local ;the accumulator todo represents a list of nodes we have yet to process
+ ;counting from [aftree0,aftree1)
+ ((define (all-a aftree1 todo)
+ (cond
+ [(empty? aftree1)
+ (cond
+ [(empty? todo) empty]
+ [else (all-a (first todo) (rest todo))])]
+ [else (local
+ ((define in-parents
+ (all-a (child-father aftree1) (cons (child-mother aftree1) todo))))
+ (cond
+ [(symbol=? (child-eyes aftree1) 'blue)
+ (cons (child-name aftree1) in-parents)]
+ [else in-parents]))])))
+ (all-a aftree0 empty)))
+
+(all-blue-eyed-ancestors2 one)
\ No newline at end of file
blob - /dev/null
blob + 43db88c3174b93d1259dd48c2cdcb1093f201866 (mode 644)
--- /dev/null
+++ 32.1.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.1|) (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")))))
+(define-struct child (father mother name date eyes))
+
+A ftn (family tree node) is either
+1. empty or
+2. (make-child f m na da ec) where f, m are ftns, na, ec are symbols, and da is a number.
+
+all-blue-eyed-ancestors : ftn -> (listof symbol)
+Given aftree0, return a list of all blue-eyed-ancestors as a (listof symbols).
+
+(define (all-blue-eyed-ancestors aftree0)
+ (local ((define (all-a aftree1 accumulator)
+ ...))
+ (all-a aftree0 ...)))
\ No newline at end of file
blob - /dev/null
blob + 51d0c3d07201d05700dc7e366d43584bada5623e (mode 644)
--- /dev/null
+++ 32.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.1|) (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")))))
+;A SchemeData (a representation of a Scheme expression) is either
+;1. a number,
+;2. a symbol,
+;3. an operator structure, or
+;4. a function structure.
+;5. a Lam structure.
+
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+(define-struct function (name arg))
+(define-struct definition (function parameter body))
+(define-struct Lam (parameter body))
+
+;An operator is a structure
+;(make-operator left right)
+;where operator is replaced by one of the four operators:
+;1. add (addition)
+;2. sub (subtraction)
+;3. mul (multiplication)
+;4. div (division)
+;and left and right are SchemeData. It represents the expression
+;(operator left right)
+;in Scheme.
+
+;A function is a structure
+;(make-function name arg)
+;where name is a symbol and arg is a SchemeData. It represents the expression
+;(name arg)
+
+;A definition is a structure
+;(make-definition function parameter body)
+;where function and parameter are symbols and body is a SchemeData.
+
+;A Lam is a structure
+;(make-Lam p b)
+;where p is a symbol (representing a variable) and b is a SchemeData (representing an expression).
+
+;numeric? : SchemeData -> boolean
+;Given a-data, determine if the expression it represents is numeric. That is, numeric? evaluates true if the SchemeData lacks symbols, which corresponds to an expression which lacks variables.
+
+(define (numeric? a-data)
+ (cond
+ [(number? a-data) true]
+ [(add? a-data) (and (numeric? (add-left a-data))
+ (numeric? (add-right a-data)))]
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+ (numeric? (sub-right a-data)))]
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+ (numeric? (mul-right a-data)))]
+ [(div? a-data) (and (numeric? (div-left a-data))
+ (numeric? (div-right a-data)))]
+ [else false]))
+
+;evaluate-expression : SchemeData -> number
+;Given a-data, evaluates the numeric expression it represents and returns the value.
+
+(define (evaluate-expression a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+ (evaluate-expression (add-right a-data)))]
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+ (evaluate-expression (sub-right a-data)))]
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+ (evaluate-expression (mul-right a-data)))]
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+ (evaluate-expression (div-right a-data)))]))
+
+;subst : symbol SchemeData SchemeData -> SchemeData
+;Given the representation of a variable V (symbol), the expression E, and a SchemeData which represents an expression, produce a new SchemeData representing an expression where all occurrences of the variable V (symbol) have been replaced with the expression E.
+
+(define (subst V E a-data)
+ (cond
+ [(number? a-data) a-data]
+ [(symbol? a-data) (cond
+ [(symbol=? a-data V) E]
+ [else 'free])]
+ [(add? a-data) (make-add (subst V E (add-left a-data))
+ (subst V E (add-right a-data)))]
+ [(sub? a-data) (make-sub (subst V E (sub-left a-data))
+ (subst V E (sub-right a-data)))]
+ [(mul? a-data) (make-mul (subst V E (mul-left a-data))
+ (subst V E (mul-right a-data)))]
+ [(div? a-data) (make-div (subst V E (div-left a-data))
+ (subst V E (div-right a-data)))]
+ [(Lam? a-data) (make-Lam (Lam-parameter a-data)
+ (subst V E (Lam-body a-data)))]
+ [else a-data]))
+
+;evaluate-with-one-def : SchemeData definition -> number
+;Given an-exp and P, evaluate the argument an-exp, substitute that for the parameter in P, and then evaluate the body of P.
+
+(define (evaluate-with-one-def an-exp P)
+ (cond
+ [(and (definition? P)
+ (numeric? an-exp)) (evaluate-expression (subst (definition-parameter P)
+ (evaluate-expression an-exp)
+ (definition-body P)))]
+ [else (error 'evaluate-with-one-def "unexpected error")]))
+
+;evaluate-with-defs : SchemeData list-of-definitions -> list-of-numbers
+;Given an-exp and defs, evaluate an-exp, substitute this value in the body for each definition in the list-of-definitions in place of each one's parameter and evaluate the resulting body.
+
+(define (evaluate-with-defs an-exp defs)
+ (cond
+ [(empty? defs) empty]
+ [(cons? defs) (cons (evaluate-with-one-def an-exp (first defs))
+ (evaluate-with-defs an-exp (rest defs)))]))
+
+;test-evaluate SchemeData list-of-definitions list-of-numbers -> boolean
+
+;Given an-exp, defs, and expected-result, evaluate an-exp, substitute it for the parameter for the body of each of the function definitions in defs, evaluate the resulting expressions, and compare that with expected-result. Return true if the two list-of-numbers are identical, false otherwise.
+
+(define (test-evaluate an-exp defs expected-result)
+ (equal? (evaluate-with-defs an-exp defs) expected-result))
+
+;Exercise 32.1.1
+
+;(make-Lam 'y 'x)
+;(make-Lam 'x 'x)
+;
+;(lambda (y) ((lambda (x) x) x))
+;
+;((lambda (y) x)
+; (lambda (x) x))
+
+;Exercise 32.1.2. Develop the function
+
+;; free-or-bound : Lam -> Lam
+;; to replace each non-binding occurrence of a variable in a-lam
+;; with 'free or 'bound, depending on whether the
+;; occurrence is bound or not.
+(define (free-or-bound a-lam)
+ (subst (Lam-parameter a-lam) 'bound a-lam))
+
+;Tests
+;(equal? (free-or-bound (make-Lam 'x 'x)) (make-Lam 'x 'bound))
+;(equal? (free-or-bound (make-Lam 'x 'y)) (make-Lam 'x 'free))
+
+;;Exercise 32.1.3. Develop the function
+
+;; unique-binding : Lam -> Lam
+;; to replace variables names of binding occurrences and their bound
+;; counterparts so that no name is used twice in a binding occurrence
+(define (unique-binding a-lam)
+ (local ;; the accumulator contains the name of the parameter whose scope is the current expression
+ ((define (unique-binding-accu a-lam accu)
+ (cond
+ [(not (Lam? a-lam)) ...]
+ [else
+ (local ((define new-sym (gensym (Lam-parameter a-lam))))
+ (make-Lam new-sym
+ (unique-binding (Lam-body a-lam))))])))
+ (unique-binding-accu a-lam ...)))
+
+gensym
blob - /dev/null
blob + b59b46beef6f4fe93a2ab4f750d38484198cdb70 (mode 644)
--- /dev/null
+++ 32.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.1|) (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")))))
+;A SchemeData (a representation of a Scheme expression) is either
+;1. a number,
+;2. a symbol,
+;3. an operator structure, or
+;4. a function structure.
+
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+
+;An operator is a structure
+;(make-operator left right)
+;where operator is replaced by one of the four operators:
+;1. add (addition)
+;2. sub (subtraction)
+;3. mul (multiplication)
+;4. div (division)
+;and left and right are SchemeData.
+
+;
+
+;An operator structure
+
+;(make-operator left right)
+
+;represents the expression
+
+;(operator left right)
+
+;in Scheme.
+
+
+
+(define-struct function (name arg))
+
+
+
+;A function is a structure
+
+;(make-function name arg)
+
+;where name is a symbol and arg is a SchemeData.
+
+;
+
+;A function structure
+
+;(make-function name arg)
+
+;represents the expression
+
+;(name arg)
+
+
+
+(define-struct definition (function parameter body))
+
+
+
+;A definition is a structure
+
+;(make-definition function parameter body)
+
+;where function and parameter are symbols and body is a SchemeData.
+
+;numeric? : SchemeData -> boolean
+
+;Given a-data, determine if the expression it
+
+;represents is numeric. That is,
+
+;numeric? evaluates true if the SchemeData lacks symbols,
+
+;which represents an expression which
+
+;lacks variables.
+
+
+
+(define (numeric? a-data)
+
+ (cond
+
+ [(number? a-data) true]
+
+ [(add? a-data) (and (numeric? (add-left a-data))
+
+ (numeric?(add-right a-data)))]
+
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+
+ (numeric? (sub-right a-data)))]
+
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+
+ (numeric? (mul-right a-data)))]
+
+ [(div? a-data) (and (numeric? (div-left a-data))
+
+ (numeric? (div-right a-data)))]
+
+ [else false]))
+
+
+
+;evaluate-expression : SchemeData -> number
+
+;Given a-data, evaluates the numeric expression it represents
+
+;and returns the value.
+
+
+
+(define (evaluate-expression a-data)
+
+ (cond
+
+ [(number? a-data) a-data]
+
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+
+ (evaluate-expression (add-right a-data)))]
+
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+
+ (evaluate-expression (sub-right a-data)))]
+
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+
+ (evaluate-expression (mul-right a-data)))]
+
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+
+ (evaluate-expression (div-right a-data)))]))
+
+
+
+;subst : symbol number SchemeData -> SchemeData
+
+;Given the representation of a variable V (symbol),
+
+;the number N, and a SchemeData which represents an expression,
+
+;produce a new SchemeData representing an expression
+
+;where all occurrences of the variable V (symbol)
+
+;have been replaced with the number N.
+
+
+
+(define (subst V N a-data)
+
+ (cond
+
+ [(number? a-data) a-data]
+
+ [(symbol? a-data) (cond
+
+ [(symbol=? a-data V) N]
+
+ [else a-data])]
+
+ [(add? a-data) (make-add (subst V N (add-left a-data))
+
+ (subst V N (add-right a-data)))]
+
+ [(sub? a-data) (make-sub (subst V N (sub-left a-data))
+
+ (subst V N (sub-right a-data)))]
+
+ [(mul? a-data) (make-mul (subst V N (mul-left a-data))
+
+ (subst V N (mul-right a-data)))]
+
+ [(div? a-data) (make-div (subst V N (div-left a-data))
+
+ (subst V N (div-right a-data)))]
+
+ [else a-data]))
+
+
+
+;evaluate-with-one-def : SchemeData definition -> number
+
+;Given an-exp and P, evaluate the argument an-exp, substitute that for the parameter in P, and then evaluate the body of P.
+
+
+
+(define (evaluate-with-one-def an-exp P)
+
+ (cond
+
+ [(and (definition? P)
+
+ (numeric? an-exp)) (evaluate-expression (subst (definition-parameter P)
+
+ (evaluate-expression an-exp)
+
+ (definition-body P)))]
+
+ [else (error 'evaluate-with-one-def "unexpected error")]))
+
+
+
+;evaluate-with-defs : SchemeData list-of-definitions -> list-of-numbers
+
+;Given an-exp and defs, evaluate an-exp, substitute this value in the body for each definition in the list-of-definitions in place of each one's parameter and evaluate the resulting body.
+
+(define (evaluate-with-defs an-exp defs)
+
+ (cond
+
+ [(empty? defs) empty]
+
+ [(cons? defs) (cons (evaluate-with-one-def an-exp (first defs))
+
+ (evaluate-with-defs an-exp (rest defs)))]))
+
+
+
+
+
+;test-evaluate SchemeData list-of-definitions list-of-numbers -> boolean
+
+;Given an-exp, defs, and expected-result, evaluate an-exp, substitute it for the parameter for the body of each of the function definitions in defs, evaluate the resulting expressions, and compare that with expected-result. Return true if the two list-of-numbers are identical, false otherwise.
+
+
+
+(define (test-evaluate an-exp defs expected-result)
+
+ (equal? (evaluate-with-defs an-exp defs) expected-result))
+
blob - /dev/null
blob + b59b46beef6f4fe93a2ab4f750d38484198cdb70 (mode 644)
--- /dev/null
+++ 32.1.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.1|) (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")))))
+;A SchemeData (a representation of a Scheme expression) is either
+;1. a number,
+;2. a symbol,
+;3. an operator structure, or
+;4. a function structure.
+
+(define-struct add (left right))
+(define-struct sub (left right))
+(define-struct mul (left right))
+(define-struct div (left right))
+
+;An operator is a structure
+;(make-operator left right)
+;where operator is replaced by one of the four operators:
+;1. add (addition)
+;2. sub (subtraction)
+;3. mul (multiplication)
+;4. div (division)
+;and left and right are SchemeData.
+
+;
+
+;An operator structure
+
+;(make-operator left right)
+
+;represents the expression
+
+;(operator left right)
+
+;in Scheme.
+
+
+
+(define-struct function (name arg))
+
+
+
+;A function is a structure
+
+;(make-function name arg)
+
+;where name is a symbol and arg is a SchemeData.
+
+;
+
+;A function structure
+
+;(make-function name arg)
+
+;represents the expression
+
+;(name arg)
+
+
+
+(define-struct definition (function parameter body))
+
+
+
+;A definition is a structure
+
+;(make-definition function parameter body)
+
+;where function and parameter are symbols and body is a SchemeData.
+
+;numeric? : SchemeData -> boolean
+
+;Given a-data, determine if the expression it
+
+;represents is numeric. That is,
+
+;numeric? evaluates true if the SchemeData lacks symbols,
+
+;which represents an expression which
+
+;lacks variables.
+
+
+
+(define (numeric? a-data)
+
+ (cond
+
+ [(number? a-data) true]
+
+ [(add? a-data) (and (numeric? (add-left a-data))
+
+ (numeric?(add-right a-data)))]
+
+ [(sub? a-data) (and (numeric? (sub-left a-data))
+
+ (numeric? (sub-right a-data)))]
+
+ [(mul? a-data) (and (numeric? (mul-left a-data))
+
+ (numeric? (mul-right a-data)))]
+
+ [(div? a-data) (and (numeric? (div-left a-data))
+
+ (numeric? (div-right a-data)))]
+
+ [else false]))
+
+
+
+;evaluate-expression : SchemeData -> number
+
+;Given a-data, evaluates the numeric expression it represents
+
+;and returns the value.
+
+
+
+(define (evaluate-expression a-data)
+
+ (cond
+
+ [(number? a-data) a-data]
+
+ [(add? a-data) (+ (evaluate-expression (add-left a-data))
+
+ (evaluate-expression (add-right a-data)))]
+
+ [(sub? a-data) (- (evaluate-expression (sub-left a-data))
+
+ (evaluate-expression (sub-right a-data)))]
+
+ [(mul? a-data) (* (evaluate-expression (mul-left a-data))
+
+ (evaluate-expression (mul-right a-data)))]
+
+ [(div? a-data) (/ (evaluate-expression (div-left a-data))
+
+ (evaluate-expression (div-right a-data)))]))
+
+
+
+;subst : symbol number SchemeData -> SchemeData
+
+;Given the representation of a variable V (symbol),
+
+;the number N, and a SchemeData which represents an expression,
+
+;produce a new SchemeData representing an expression
+
+;where all occurrences of the variable V (symbol)
+
+;have been replaced with the number N.
+
+
+
+(define (subst V N a-data)
+
+ (cond
+
+ [(number? a-data) a-data]
+
+ [(symbol? a-data) (cond
+
+ [(symbol=? a-data V) N]
+
+ [else a-data])]
+
+ [(add? a-data) (make-add (subst V N (add-left a-data))
+
+ (subst V N (add-right a-data)))]
+
+ [(sub? a-data) (make-sub (subst V N (sub-left a-data))
+
+ (subst V N (sub-right a-data)))]
+
+ [(mul? a-data) (make-mul (subst V N (mul-left a-data))
+
+ (subst V N (mul-right a-data)))]
+
+ [(div? a-data) (make-div (subst V N (div-left a-data))
+
+ (subst V N (div-right a-data)))]
+
+ [else a-data]))
+
+
+
+;evaluate-with-one-def : SchemeData definition -> number
+
+;Given an-exp and P, evaluate the argument an-exp, substitute that for the parameter in P, and then evaluate the body of P.
+
+
+
+(define (evaluate-with-one-def an-exp P)
+
+ (cond
+
+ [(and (definition? P)
+
+ (numeric? an-exp)) (evaluate-expression (subst (definition-parameter P)
+
+ (evaluate-expression an-exp)
+
+ (definition-body P)))]
+
+ [else (error 'evaluate-with-one-def "unexpected error")]))
+
+
+
+;evaluate-with-defs : SchemeData list-of-definitions -> list-of-numbers
+
+;Given an-exp and defs, evaluate an-exp, substitute this value in the body for each definition in the list-of-definitions in place of each one's parameter and evaluate the resulting body.
+
+(define (evaluate-with-defs an-exp defs)
+
+ (cond
+
+ [(empty? defs) empty]
+
+ [(cons? defs) (cons (evaluate-with-one-def an-exp (first defs))
+
+ (evaluate-with-defs an-exp (rest defs)))]))
+
+
+
+
+
+;test-evaluate SchemeData list-of-definitions list-of-numbers -> boolean
+
+;Given an-exp, defs, and expected-result, evaluate an-exp, substitute it for the parameter for the body of each of the function definitions in defs, evaluate the resulting expressions, and compare that with expected-result. Return true if the two list-of-numbers are identical, false otherwise.
+
+
+
+(define (test-evaluate an-exp defs expected-result)
+
+ (equal? (evaluate-with-defs an-exp defs) expected-result))
+
blob - /dev/null
blob + fb48d373a7719a5e265a13f9b03cb0d0cfb3e7be (mode 644)
--- /dev/null
+++ 32.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.2|) (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")))))
+(define MC 3)
+(define BOAT-CAPACITY 2)
+
+(define-struct state (initial river final))
+
+;A state is a structure
+;(make-state i r f)
+;where i, r are (list m c) where m, c are numbers, where m represents the number of missionaries, c the number of cannibals, on the respective side of the river; and r is a symbol (either 'initial or 'final).
+
+;The initial state is
+;(make-state (list 3 3) 'initial (list 0 0))
+;The final state (solved) is
+;(make-state (list 0 0) 'final (list 3 3))
+
+;A boat load is a list
+;(list m c)
+;where m represents the number of missionaries using the boat and c the number of cannibals. By definition, the sum of m and c must be less than or equal to BOAT-CAPACITY. In Scheme,
+;(<= (+ m c) BOAT-CAPACITY)
+
+;make-BOAT-LOADS : N -> (listof (list N N))
+;Determine the possible boat-loads given maxc (maximum-capacity) and return the possibilities as a (listof (list N N)) where the first number in each pair represents the number of missionaries, the second the number of cannibals.
+
+(define (make-BOAT-LOADS maxc)
+ (rest ;;removes the first entry, which corresponds to no one in the boat
+ (foldr append empty ;;converts the (listof (listof (list N N))) into (listof (list N N))
+ (build-list (+ maxc 1)
+ (lambda (m)
+ (build-list (+ (- maxc m) 1) (lambda (c) (list m c))))))))
+
+;possible-successor : state -> (listof states)
+;Given astate0, return a (listof states) of all possible successor states.
+
+(define (possible-successor astate0)
+ (local ;;boat-loads represent the remaining boat-loads that have not been tried yet
+ ((define (possible-successor-accu astate1 boat-loads)
+ (cond
+ [(empty? boat-loads) empty]
+ [else
+ (local
+ ((define sub-initial (sub-list (state-initial astate1)
+ (first boat-loads)))
+ (define sub-final (sub-list (state-final astate1)
+ (first boat-loads)))
+ (define add-initial (add-list (state-initial astate1)
+ (first boat-loads)))
+ (define add-final (add-list (state-final astate1)
+ (first boat-loads)))
+ (define initial-state (make-state add-initial
+ 'initial
+ sub-final))
+ (define final-state (make-state sub-initial
+ 'final
+ add-final))
+ (define remaining-states (possible-successor-accu astate1 (rest boat-loads))))
+ (cond
+ [(and (symbol=? (state-river astate1) 'initial)
+ (non-negative-list? sub-initial))
+ (cons final-state
+ remaining-states)]
+ [(and (symbol=? (state-river astate1) 'final)
+ (non-negative-list? sub-final))
+ (cons initial-state
+ remaining-states)]
+ [else remaining-states]))])))
+ (possible-successor-accu astate0 (make-BOAT-LOADS BOAT-CAPACITY))))
+
+;op-pair : (number number -> number) (list number number) (list number number) -> (list number number)
+;Performs operation element by element on two lists.
+
+(define (op-pair op list1 list2)
+ (cond
+ [(empty? list1) empty]
+ [else (cons (op (first list1) (first list2))
+ (op-pair op (rest list1) (rest list2)))]))
+
+(define (add-list list1 list2)
+ (op-pair + list1 list2))
+(define (sub-list list1 list2)
+ (op-pair - list1 list2))
+
+;non-negative-list? : (listof numbers) -> boolean
+(define (non-negative-list? alist)
+ (andmap (lambda (x) (>= x 0)) alist))
+
+;possible-successor/list : (listof states) -> (listof states)
+;Given alos, determine all possible successor states (both legal and illegal states).
+
+(define (possible-successor/list alos)
+ (cond
+ [(empty? alos) empty]
+ [else (append (possible-successor (first alos))
+ (possible-successor/list (rest alos)))]))
+
+;legal-state? : state -> boolean
+;Determines if a state is legal.
+
+(define (legal-state? astate)
+ (cond
+ [(and (equal? (add-list (state-initial astate)
+ (state-final astate)) (list MC MC))
+ (or (zero? (first (state-initial astate)))
+ (>= (first (state-initial astate))
+ (second (state-initial astate))))
+ (or (zero? (first (state-final astate)))
+ (>= (first (state-final astate))
+ (second (state-final astate))))) true]
+ [else false]))
+
+;legal-state/list : (listof states) -> (listof states)
+;Returns all legal states in alos.
+(define (legal-state/list alos)
+ (filter legal-state? alos))
+
+;state-final? : state -> boolean
+;Determines if a state is final.
+
+(define (state-final? astate)
+ (and (equal? (list 0 0) (state-initial astate))
+ (symbol=? 'final (state-river astate))
+ (equal? (list MC MC) (state-final astate))))
+
+;state-final/list : (listof states) -> (listof states)
+;Returns the subset of final states from alos.
+
+(define (state-final/list alos)
+ (filter state-final? alos))
+
+;mc-solvable? : (listof states) -> boolean
+;Determines if there is a solution for alos by generating successor states until a final state is reached. We use two auxiliary definitions, mc-solvable?/list-accu and mc-solvable?-accu:
+
+;mc-solvable?/list-accu : (listof states) (listof states) -> boolean
+;mc-solvable?-accu : state (listof states) -> boolean
+;
+;First, we examine if alos is empty. Clearly, if it is empty, the problem cannot be solved. Next, we see if the first item on the list is the final-state. If it is, clearly the state is solved. Otherwise, we produce a list of legal successor states for (first alos), and we re-apply mc-solvable? on those new successor states. We use an accumulator to keep track of which states have already occurred. If a successor state is identical to a previous state, we return false (to prevent infinite loops). We use backtracking to end searches if a cycle is reached or if there are no legal successor states.
+;previous is an accumulator, a (listof states) that records which states have been previously accessed in order to get from alos0 to alos1. That is, alos1 is a list of successor states, and previous includes all the states from alos0 (previous includes a single state from alos0) up to alos1 (not inclusive) in order to obtain alos0.
+
+(define (mc-solvable? alos0)
+ (local ;previous accumulates all states necessary to go from alos0 to alos1, including
+ ;the necessary state in alos0 but not including the states in alos1
+ ((define (mc-solvable?/list-accu alos1 previous)
+ (cond
+ [(empty? alos1) false]
+ [else (or (mc-solvable?-accu (first alos1) previous)
+ (mc-solvable?/list-accu (rest alos1) previous))]))
+ (define (mc-solvable?-accu astate previous)
+ (cond
+ [(equal? astate final-state) true]
+ [(contains astate previous) false]
+ [else (mc-solvable?/list-accu
+ (legal-state/list (possible-successor astate))
+ (append previous (list astate)))]))
+ (define final-state (make-state (list 0 0) 'final (list 3 3))))
+ (mc-solvable?/list-accu alos0 empty)))
+
+;mc-solution : (listof states) -> (listof states) or false
+;Determines a solution for alos0, which is a (listof states), if a solution is possible; returns false otherwise. mc-solution generates successor states until a final state is reached. We use two auxiliary definitions, mc-solution/list-accu and mc-solution-accu:
+
+;mc-solution/list-accu : (listof states) (listof states) -> (listof states) boolean
+;mc-solution-accu : state (listof states) -> (listof states) or boolean
+;
+;The algorithm is similar to mc-solvable?.
+
+
+(define (mc-solution alos0)
+ (local
+ ;previous accumulates all states necessary to go from alos0 to alos1, including
+ ;the necessary state in alos0 but not including the states in alos1
+ ((define (mc-solution/list-accu alos1 previous)
+ (cond
+ [(empty? alos1) false]
+ [(cons? (mc-solution-accu (first alos1) previous)) (mc-solution-accu (first alos1) previous)]
+ [else (mc-solution/list-accu (rest alos1) previous)]))
+ (define (mc-solution-accu astate previous)
+ (cond
+ [(equal? astate final-state) (append previous (list astate))]
+ [(contains astate previous) false]
+ [else (mc-solution/list-accu
+ (legal-state/list (possible-successor astate))
+ (append previous (list astate)))]))
+ (define final-state (make-state (list 0 0) 'final (list 3 3))))
+ (mc-solution/list-accu alos0 empty)))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+(define (contains x alox)
+ (ormap (lambda (an-x) (equal? x an-x)) alox))
+
+;mc-solvable?-accu : state (listof states) -> boolean
+
+
+;Tests: op-pair
+;(op-pair + '(5 6 7)
+; '(2 1 3))
+;(op-pair - '(5 6 7)
+; '(2 1 3))
+
+;Tests: non-negative-list?
+;(not (non-negative-list? '(5 2 -4 5 3)))
+;(non-negative-list? '(4 1 2 1 4))
+
+;Tests: possible-successor
+;(define initial-state (make-state (list 3 3) 'initial (list 0 0)))
+;(define second-state (make-state (list 2 2) 'final (list 1 1)))
+;(define final-state (make-state (list 0 0) 'final (list 3 3)))
+;(possible-successor initial-state)
+;(possible-successor second-state)
+
+;Tests: possible-successor/list
+;(possible-successor/list (possible-successor initial-state))
+
+;Tests : legal-state?
+;(map legal-state? (possible-successor/list (possible-successor/list (possible-successor initial-state))))
+;(map legal-state? (legal-state/list (possible-successor/list (possible-successor/list (possible-successor initial-state)))))
+
+;Tests : state-final?
+;(not (ormap state-final? (legal-state/list (possible-successor/list (possible-successor/list (possible-successor initial-state))))))
+;(state-final? final-state)
+
+;Tests : mc-solution
+;(mc-solution (list initial-state))
\ No newline at end of file
blob - /dev/null
blob + 8dd8007949801e62f08a18e66ccbea022dd8511b (mode 644)
--- /dev/null
+++ 32.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.2|) (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")))))
+(define MC 3)
+(define BOAT-CAPACITY 2)
\ No newline at end of file
blob - /dev/null
blob + ca71c5bc3b83a336d4a4ccde091a9f95fb327698 (mode 644)
--- /dev/null
+++ 32.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2))
+ (define need-length-x (+ peg-x 3))
+ (define need-length-y (+ peg-y 3)))
+ (cond
+ ;;is there even a peg?
+ [(not (vector-ref (vector-ref aboard peg-y) peg-x)) false]
+ ;;jumping down
+ [(and (>= (vector-length aboard) need-length-y)
+ (not (vector-ref (vector-ref aboard next-peg-y) peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) peg-x)) true]
+ ;;jumping right
+ [(and (>= (vector-length (vector-ref aboard peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard peg-y) next-peg-x-removes)) true]
+ ;;jumping up
+ [(and (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) peg-x)) true]
+ ;;jumping left
+ [(and (not (negative? prev-peg-x))
+ (not (vector-ref (vector-ref aboard peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard peg-y) prev-peg-x-removes)) true]
+ ;;jumping diagonal (up)
+ [(and (not (negative? prev-peg-x))
+ (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) prev-peg-x-removes)) true]
+ ;;jumping diagonal (down)
+ [(and (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard next-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard next-peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) next-peg-x-removes)) true]
+ [else false])))
+
+(define trueboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false true true true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true false)
+ (vector true true true false true true)
+ (vector false false true false false false true))))
+
+(define falseboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true false true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true false true true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false false true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))))
+(map (lambda (b) (enabled? (make-posn 3 5) b)) trueboard)
+(map (lambda (b) (not (enabled? (make-posn 3 5) b))) falseboard)
\ No newline at end of file
blob - /dev/null
blob + a7a674ea5a9398b46b8100ccb84caddbbabf485a (mode 644)
--- /dev/null
+++ 32.3.1 Test Suite
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;tests enabled?
+(define trueboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false true true true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true false)
+ (vector true true true false true true)
+ (vector false false true false false false true))))
+
+(define falseboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true false true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true false true true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false false true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))))
+
+
+(define trueboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define trueboard3 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+(define trueboard4 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector false true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define falseboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true false true)
+ (vector true false true true true true true))))
+(define falseboard3 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true false false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false false true true true)
+ (vector false true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true false true true)
+ (vector false true false true false true)
+ (vector true false false true true true true))))
+(andmap (lambda (b) (enabled? (make-posn 3 5) b)) trueboard)
+(andmap (lambda (b) (not (enabled? (make-posn 3 5) b))) falseboard)
+(andmap (lambda (b) (enabled? (make-posn 7 7) b)) trueboard2)
+(andmap (lambda (b) (enabled? (make-posn 1 1) b)) trueboard3)
+(andmap (lambda (b) (enabled? (make-posn 1 7) b)) trueboard4)
+(andmap (lambda (b) (not (enabled? (make-posn 7 7) b))) falseboard2)
+(andmap (lambda (b) (not (enabled? (make-posn 1 7) b))) falseboard3)
+
+;Tests build-board
+
+(equal? (build-board 5 (lambda (x y) true))
+ (vector
+ (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)))
+(equal? (build-board 7 (lambda (x y)
+ (cond
+ [(<= (+ x y) 4) true]
+ [else false])))
+ (vector
+ (vector true)
+ (vector true true)
+ (vector true false false)
+ (vector false false false false)
+ (vector false false false false false)
+ (vector false false false false false false)
+ (vector false false false false false false false)))
+
+(equal? (build-board 7 (lambda (x y)
+ (cond
+ [(<= (- y x) 2) true]
+ [else false])))
+ (vector
+ (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector false true true true)
+ (vector false false true true true)
+ (vector false false false true true true)
+ (vector false false false false true true true)))
+
+
+(define jumpboard (vector (vector true)
+ (vector true true)
+ (vector false true false)
+ (vector true true true true)
+ (vector false true true true false)
+ (vector true true true true true true)
+ (vector true true false true false true true)))
+
+
+;test enabled-pegs
+(equal?
+ (enabled-pegs (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true)))
+ (list
+ (make-posn 1 1)
+ (make-posn 1 2)
+ (make-posn 2 2)
+ (make-posn 3 3)
+ (make-posn 1 5)
+ (make-posn 1 6)
+ (make-posn 6 6)
+ (make-posn 7 7)))
+
+;test next-board
+
+(define testboard2 (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true)))
+
+(equal? (next-board testboard2 (make-posn 1 1))
+ (list
+ (make-state
+ (vector
+ (vector false)
+ (vector false true)
+ (vector true true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))
+ (list (make-posn 1 1) (make-posn 1 3)))))
+(equal? (next-board testboard2 (make-posn 1 2))
+ (list
+ (make-state
+ (vector
+ (vector true)
+ (vector false true)
+ (vector false false true)
+ (vector true false true true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))
+ (list (make-posn 1 2) (make-posn 3 4)))))
+(equal? (next-board testboard2 (make-posn 2 2))
+ (list
+ (make-state
+ (vector
+ (vector true)
+ (vector true false)
+ (vector false false true)
+ (vector true true false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))
+ (list (make-posn 2 2) (make-posn 2 4)))))
+(equal? (next-board testboard2 (make-posn 3 1)) empty)
+(equal?
+ (next-board testboard2 (make-posn 3 3))
+ (list
+ (make-state
+ (vector
+ (vector true)
+ (vector true true)
+ (vector true false false)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))
+ (list (make-posn 3 3) (make-posn 1 3)))
+ (make-state
+ (vector
+ (vector true)
+ (vector true true)
+ (vector false true false)
+ (vector true false false false)
+ (vector true false true false true)
+ (vector true true false false true true)
+ (vector false false true false false false true))
+ (list (make-posn 3 3) (make-posn 5 5)))))
+
+(next-board INITIAL-BOARD (make-posn 1 3))
\ No newline at end of file
blob - /dev/null
blob + 937fa68714e5c54c908c2405ab8cc46e494c2d97 (mode 644)
--- /dev/null
+++ 32.3.1 Test Suite~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2)))
+ (cond
+ ;;first, is there even a peg?
+ ;;if so, test jump down, jump right, jump up, jump left, jump diagonal (up), jump diagonal (down), in that order
+ [(vector-ref (vector-ref aboard peg-y) peg-x)
+ (or (jump? peg-x next-peg-y peg-x next-peg-y-removes aboard)
+ (jump? next-peg-x peg-y next-peg-x-removes peg-y aboard)
+ (jump? peg-x prev-peg-y peg-x prev-peg-y-removes aboard)
+ (jump? prev-peg-x peg-y prev-peg-x-removes peg-y aboard)
+ (jump? prev-peg-x prev-peg-y prev-peg-x-removes prev-peg-y-removes aboard)
+ (jump? next-peg-x next-peg-y next-peg-x-removes next-peg-y-removes aboard))]
+ [else false])))
+
+;jump? : N N N N board-> boolean
+;Given new-peg-x, new-peg-y, remove-peg-x, remove-peg-y, and aboard, determine if it is possible to make a jump. All coordinates are in terms of vector indices. E.g, 0,0 represents the first element in the first vector.
+
+(define (jump? new-peg-x new-peg-y remove-peg-x remove-peg-y aboard)
+ (local ((define need-length-x (add1 new-peg-x))
+ (define need-length-y (add1 new-peg-y)))
+ (and (not (negative? new-peg-x))
+ (not (negative? new-peg-y))
+ (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard new-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard new-peg-y) new-peg-x))
+ (vector-ref (vector-ref aboard remove-peg-y) remove-peg-x))))
+
+;jump : board posn -> (listof boards)
+;Given aboard and aposn,
+(define trueboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false true true true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true false)
+ (vector true true true false true true)
+ (vector false false true false false false true))))
+
+(define falseboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true false true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true false true true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false false true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))))
+
+
+(define trueboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define trueboard3 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+(define trueboard4 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector false true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define falseboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true false true)
+ (vector true false true true true true true))))
+(define falseboard3 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true false false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false false true true true)
+ (vector false true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true false true true)
+ (vector false true false true false true)
+ (vector true false false true true true true))))
+(andmap (lambda (b) (enabled? (make-posn 3 5) b)) trueboard)
+(andmap (lambda (b) (not (enabled? (make-posn 3 5) b))) falseboard)
+(andmap (lambda (b) (enabled? (make-posn 7 7) b)) trueboard2)
+(andmap (lambda (b) (enabled? (make-posn 1 1) b)) trueboard3)
+(andmap (lambda (b) (enabled? (make-posn 1 7) b)) trueboard4)
+(andmap (lambda (b) (not (enabled? (make-posn 7 7) b))) falseboard2)
+(andmap (lambda (b) (not (enabled? (make-posn 1 7) b))) falseboard3)
\ No newline at end of file
blob - /dev/null
blob + f29e8b53b1ca540d7bc3542b98673c681c98baa8 (mode 644)
--- /dev/null
+++ 32.3.1-2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2))
+ (define need-length-x (+ peg-x 3))
+ (define need-length-y (+ peg-y 3)))
+ (cond
+ ;;is there even a peg?
+ [(not (vector-ref (vector-ref aboard peg-y) peg-x)) false]
+ ;;jumping down
+ [(and (>= (vector-length aboard) need-length-y)
+ (not (vector-ref (vector-ref aboard next-peg-y) peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) peg-x)) true]
+ ;;jumping right
+ [(and (>= (vector-length (vector-ref aboard peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard peg-y) next-peg-x-removes)) true]
+ ;;jumping up
+ [(and (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) peg-x)) true]
+ ;;jumping left
+ [(and (not (negative? prev-peg-x))
+ (not (vector-ref (vector-ref aboard peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard peg-y) prev-peg-x-removes)) true]
+ ;;jumping diagonal (up)
+ [(and (not (negative? prev-peg-x))
+ (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) prev-peg-x-removes)) true]
+ ;;jumping diagonal (down)
+ [(and (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard next-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard next-peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) next-peg-x-removes)) true]
+ [else false])))
blob - /dev/null
blob + ca71c5bc3b83a336d4a4ccde091a9f95fb327698 (mode 644)
--- /dev/null
+++ 32.3.1-2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2))
+ (define need-length-x (+ peg-x 3))
+ (define need-length-y (+ peg-y 3)))
+ (cond
+ ;;is there even a peg?
+ [(not (vector-ref (vector-ref aboard peg-y) peg-x)) false]
+ ;;jumping down
+ [(and (>= (vector-length aboard) need-length-y)
+ (not (vector-ref (vector-ref aboard next-peg-y) peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) peg-x)) true]
+ ;;jumping right
+ [(and (>= (vector-length (vector-ref aboard peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard peg-y) next-peg-x-removes)) true]
+ ;;jumping up
+ [(and (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) peg-x)) true]
+ ;;jumping left
+ [(and (not (negative? prev-peg-x))
+ (not (vector-ref (vector-ref aboard peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard peg-y) prev-peg-x-removes)) true]
+ ;;jumping diagonal (up)
+ [(and (not (negative? prev-peg-x))
+ (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) prev-peg-x-removes)) true]
+ ;;jumping diagonal (down)
+ [(and (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard next-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard next-peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) next-peg-x-removes)) true]
+ [else false])))
+
+(define trueboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false true true true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true false)
+ (vector true true true false true true)
+ (vector false false true false false false true))))
+
+(define falseboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true false true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true false true true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false false true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))))
+(map (lambda (b) (enabled? (make-posn 3 5) b)) trueboard)
+(map (lambda (b) (not (enabled? (make-posn 3 5) b))) falseboard)
\ No newline at end of file
blob - /dev/null
blob + 937fa68714e5c54c908c2405ab8cc46e494c2d97 (mode 644)
--- /dev/null
+++ 32.3.1-3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2)))
+ (cond
+ ;;first, is there even a peg?
+ ;;if so, test jump down, jump right, jump up, jump left, jump diagonal (up), jump diagonal (down), in that order
+ [(vector-ref (vector-ref aboard peg-y) peg-x)
+ (or (jump? peg-x next-peg-y peg-x next-peg-y-removes aboard)
+ (jump? next-peg-x peg-y next-peg-x-removes peg-y aboard)
+ (jump? peg-x prev-peg-y peg-x prev-peg-y-removes aboard)
+ (jump? prev-peg-x peg-y prev-peg-x-removes peg-y aboard)
+ (jump? prev-peg-x prev-peg-y prev-peg-x-removes prev-peg-y-removes aboard)
+ (jump? next-peg-x next-peg-y next-peg-x-removes next-peg-y-removes aboard))]
+ [else false])))
+
+;jump? : N N N N board-> boolean
+;Given new-peg-x, new-peg-y, remove-peg-x, remove-peg-y, and aboard, determine if it is possible to make a jump. All coordinates are in terms of vector indices. E.g, 0,0 represents the first element in the first vector.
+
+(define (jump? new-peg-x new-peg-y remove-peg-x remove-peg-y aboard)
+ (local ((define need-length-x (add1 new-peg-x))
+ (define need-length-y (add1 new-peg-y)))
+ (and (not (negative? new-peg-x))
+ (not (negative? new-peg-y))
+ (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard new-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard new-peg-y) new-peg-x))
+ (vector-ref (vector-ref aboard remove-peg-y) remove-peg-x))))
+
+;jump : board posn -> (listof boards)
+;Given aboard and aposn,
+(define trueboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false true true true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true false)
+ (vector true true true false true true)
+ (vector false false true false false false true))))
+
+(define falseboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true false true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true false true true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false false true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))))
+
+
+(define trueboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define trueboard3 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+(define trueboard4 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector false true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define falseboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true false true)
+ (vector true false true true true true true))))
+(define falseboard3 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true false false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false false true true true)
+ (vector false true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true false true true)
+ (vector false true false true false true)
+ (vector true false false true true true true))))
+(andmap (lambda (b) (enabled? (make-posn 3 5) b)) trueboard)
+(andmap (lambda (b) (not (enabled? (make-posn 3 5) b))) falseboard)
+(andmap (lambda (b) (enabled? (make-posn 7 7) b)) trueboard2)
+(andmap (lambda (b) (enabled? (make-posn 1 1) b)) trueboard3)
+(andmap (lambda (b) (enabled? (make-posn 1 7) b)) trueboard4)
+(andmap (lambda (b) (not (enabled? (make-posn 7 7) b))) falseboard2)
+(andmap (lambda (b) (not (enabled? (make-posn 1 7) b))) falseboard3)
\ No newline at end of file
blob - /dev/null
blob + f29e8b53b1ca540d7bc3542b98673c681c98baa8 (mode 644)
--- /dev/null
+++ 32.3.1-3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2))
+ (define need-length-x (+ peg-x 3))
+ (define need-length-y (+ peg-y 3)))
+ (cond
+ ;;is there even a peg?
+ [(not (vector-ref (vector-ref aboard peg-y) peg-x)) false]
+ ;;jumping down
+ [(and (>= (vector-length aboard) need-length-y)
+ (not (vector-ref (vector-ref aboard next-peg-y) peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) peg-x)) true]
+ ;;jumping right
+ [(and (>= (vector-length (vector-ref aboard peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard peg-y) next-peg-x-removes)) true]
+ ;;jumping up
+ [(and (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) peg-x)) true]
+ ;;jumping left
+ [(and (not (negative? prev-peg-x))
+ (not (vector-ref (vector-ref aboard peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard peg-y) prev-peg-x-removes)) true]
+ ;;jumping diagonal (up)
+ [(and (not (negative? prev-peg-x))
+ (not (negative? prev-peg-y))
+ (not (vector-ref (vector-ref aboard prev-peg-y) prev-peg-x))
+ (vector-ref (vector-ref aboard prev-peg-y-removes) prev-peg-x-removes)) true]
+ ;;jumping diagonal (down)
+ [(and (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard next-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard next-peg-y) next-peg-x))
+ (vector-ref (vector-ref aboard next-peg-y-removes) next-peg-x-removes)) true]
+ [else false])))
blob - /dev/null
blob + b02aeab9d324f3ac548fe005f837472b4feb1319 (mode 644)
--- /dev/null
+++ 32.3.1-4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+;the parameters for the position of the new peg as well as the peg to be removed are passed to jump?.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2)))
+ (cond
+ ;;first, is there even a peg?
+ ;;if so, test jump down, jump right, jump up, jump left, jump diagonal (up), jump diagonal (down), in that order
+ [(vector-ref (vector-ref aboard peg-y) peg-x)
+ (or (jump? peg-x next-peg-y peg-x next-peg-y-removes aboard)
+ (jump? next-peg-x peg-y next-peg-x-removes peg-y aboard)
+ (jump? peg-x prev-peg-y peg-x prev-peg-y-removes aboard)
+ (jump? prev-peg-x peg-y prev-peg-x-removes peg-y aboard)
+ (jump? prev-peg-x prev-peg-y prev-peg-x-removes prev-peg-y-removes aboard)
+ (jump? next-peg-x next-peg-y next-peg-x-removes next-peg-y-removes aboard))]
+ [else false])))
+
+;jump? : N N N N board-> boolean
+;Given new-peg-x, new-peg-y, remove-peg-x, remove-peg-y, and aboard, determine if it is possible to make a jump. All coordinates are in terms of vector indices. E.g, 0,0 represents the first element in the first vector.
+
+(define (jump? new-peg-x new-peg-y remove-peg-x remove-peg-y aboard)
+ (local ((define need-length-x (add1 new-peg-x))
+ (define need-length-y (add1 new-peg-y)))
+ (and (not (negative? new-peg-x))
+ (not (negative? new-peg-y))
+ (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard new-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard new-peg-y) new-peg-x))
+ (vector-ref (vector-ref aboard remove-peg-y) remove-peg-x))))
+
+;next-board : board posn -> (listof boards) or false
+;Given aboard and aposn, return all possible board configurations if the peg specified by aposn is jumped. (since there may be more than one possible jump, we must list the results as a listof boards)
+
+(define (next-board aboard aposn)
+ (cond
+ [(enabled? aposn aboard)
+ (append (jump aboard aposn) ;down
+ (jump aboard aposn) ;right
+ (jump aboard aposn) ;up
+ (jump-left aboard aposn) ;left
+ (jump-diagonal-up aboard aposn) ;diagonal-up
+ (jump-diagonal-down aboard aposn))] ;diagonal-down
+ [else false]))
+
+jump : board posn posn -> board
+Using aboard, return a new board with old-peg replaced with false and new-peg replaced with true. The intermediate peg is removed.
+
+(define (jump aboard new-peg old-peg)
+ (cond))
\ No newline at end of file
blob - /dev/null
blob + 937fa68714e5c54c908c2405ab8cc46e494c2d97 (mode 644)
--- /dev/null
+++ 32.3.1-4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2)))
+ (cond
+ ;;first, is there even a peg?
+ ;;if so, test jump down, jump right, jump up, jump left, jump diagonal (up), jump diagonal (down), in that order
+ [(vector-ref (vector-ref aboard peg-y) peg-x)
+ (or (jump? peg-x next-peg-y peg-x next-peg-y-removes aboard)
+ (jump? next-peg-x peg-y next-peg-x-removes peg-y aboard)
+ (jump? peg-x prev-peg-y peg-x prev-peg-y-removes aboard)
+ (jump? prev-peg-x peg-y prev-peg-x-removes peg-y aboard)
+ (jump? prev-peg-x prev-peg-y prev-peg-x-removes prev-peg-y-removes aboard)
+ (jump? next-peg-x next-peg-y next-peg-x-removes next-peg-y-removes aboard))]
+ [else false])))
+
+;jump? : N N N N board-> boolean
+;Given new-peg-x, new-peg-y, remove-peg-x, remove-peg-y, and aboard, determine if it is possible to make a jump. All coordinates are in terms of vector indices. E.g, 0,0 represents the first element in the first vector.
+
+(define (jump? new-peg-x new-peg-y remove-peg-x remove-peg-y aboard)
+ (local ((define need-length-x (add1 new-peg-x))
+ (define need-length-y (add1 new-peg-y)))
+ (and (not (negative? new-peg-x))
+ (not (negative? new-peg-y))
+ (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard new-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard new-peg-y) new-peg-x))
+ (vector-ref (vector-ref aboard remove-peg-y) remove-peg-x))))
+
+;jump : board posn -> (listof boards)
+;Given aboard and aposn,
+(define trueboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false true true true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true false)
+ (vector true true true false true true)
+ (vector false false true false false false true))))
+
+(define falseboard (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true false true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true true true)
+ (vector true false true true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false true true true)
+ (vector false false true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true false false false true true)
+ (vector false false true false false false true))
+ (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true false false true)
+ (vector true false true false false)
+ (vector true true false false true true)
+ (vector false false true false false false true))))
+
+
+(define trueboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define trueboard3 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector true true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+(define trueboard4 (list (vector (vector true)
+ (vector true true)
+ (vector false true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true true true)
+ (vector true true false true false true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true false)
+ (vector true true true true)
+ (vector false true true true false)
+ (vector true true true true true true)
+ (vector true true true true true true true))))
+
+(define falseboard2 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true false true true true)
+ (vector true true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true true true true)
+ (vector true true true true false true)
+ (vector true false true true true true true))))
+(define falseboard3 (list (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true true true true true true true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector true true false true true)
+ (vector true true true true true true)
+ (vector true false false true true true false))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false false true true true)
+ (vector false true true true true true)
+ (vector true true true true true false true))
+ (vector (vector true)
+ (vector true true)
+ (vector true true true)
+ (vector true true true true)
+ (vector false true false true true)
+ (vector false true false true false true)
+ (vector true false false true true true true))))
+(andmap (lambda (b) (enabled? (make-posn 3 5) b)) trueboard)
+(andmap (lambda (b) (not (enabled? (make-posn 3 5) b))) falseboard)
+(andmap (lambda (b) (enabled? (make-posn 7 7) b)) trueboard2)
+(andmap (lambda (b) (enabled? (make-posn 1 1) b)) trueboard3)
+(andmap (lambda (b) (enabled? (make-posn 1 7) b)) trueboard4)
+(andmap (lambda (b) (not (enabled? (make-posn 7 7) b))) falseboard2)
+(andmap (lambda (b) (not (enabled? (make-posn 1 7) b))) falseboard3)
\ No newline at end of file
blob - /dev/null
blob + 63d11dd361f9449de8f0c83a1b5a559d452427e4 (mode 644)
--- /dev/null
+++ 32.3.1-5
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;A move is a list
+;(list o n)
+;where o,n are posns. o represents the original position of the peg and n represents the new position of the peg.
+
+(define-struct state (board move))
+
+;A state is a structure
+;(make-state b m)
+;where b is a board and m is a move.
+
+;By default, we specify the coordinates of a peg with a posn (x,y), where x refers to horizontal distance (the column number) and y refers to the vertical distance (the row number). The top position of any given board has an index (make-posn 1 1). When referencing a given peg in the board by using vector indices, we will explicitly state that we are using vector indices 0,0 to reference the top position in the board. Otherwise, assume (make-posn 1 1) specifies the first position in the board.
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by apeg is enabled in aboard (enabled means that the peg is capable of jumping).
+
+(define (enabled? apeg aboard)
+ (local ((define peg-x (posn-x apeg))
+ (define peg-y (posn-y apeg))
+ (define right-peg-x (+ peg-x 2))
+ (define down-peg-y (+ peg-y 2))
+ (define left-peg-x (- peg-x 2))
+ (define up-peg-y (- peg-y 2))
+ (define down-peg (make-posn peg-x down-peg-y))
+ (define right-peg (make-posn right-peg-x peg-y))
+ (define up-peg (make-posn peg-x up-peg-y))
+ (define left-peg (make-posn left-peg-x peg-y))
+ (define diagonal-up-peg (make-posn left-peg-x up-peg-y))
+ (define diagonal-down-peg (make-posn right-peg-x down-peg-y)))
+ (cond
+ ;;first, is there even a peg?
+ ;;if so, test jump down, jump right, jump up, jump left, jump diagonal (up), jump diagonal (down), in that order
+ [(peg-exists? apeg aboard)
+ (or (jump? apeg down-peg aboard)
+ (jump? apeg right-peg aboard)
+ (jump? apeg up-peg aboard)
+ (jump? apeg left-peg aboard)
+ (jump? apeg diagonal-up-peg aboard)
+ (jump? apeg diagonal-down-peg aboard))]
+ [else false])))
+
+;peg-exists? : posn board -> boolean
+;Determines if a peg exists given apeg and aboard. apeg is reported using an index that starts at 1,1. peg-exists? converts the coordinates to vector indices (in vector indices, 0,0 is the first element in the board).
+
+(define (peg-exists? apeg aboard)
+ (local ((define peg-x-v (sub1 (posn-x apeg)))
+ (define peg-y-v (sub1 (posn-y apeg))))
+ (vector-ref (vector-ref aboard peg-y-v) peg-x-v)))
+
+;jump? : posn posn board-> boolean
+;Given old-peg, new-peg, and aboard, determine if it is possible to make a jump. jump? converts these coordinates to vector indices, where 0,0 represents the first element in board. Conversions are denoted by -v.
+
+(define (jump? old-peg new-peg aboard)
+ (local ((define old-peg-x-v (sub1 (posn-x old-peg)))
+ (define old-peg-y-v (sub1 (posn-y old-peg)))
+ (define new-peg-x-v (sub1 (posn-x new-peg)))
+ (define new-peg-y-v (sub1 (posn-y new-peg)))
+ (define remove-peg-x-v (+ (/ (- new-peg-x-v old-peg-x-v) 2) old-peg-x-v))
+ (define remove-peg-y-v (+ (/ (- new-peg-y-v old-peg-y-v) 2) old-peg-y-v))
+ (define need-length-x (add1 new-peg-x-v))
+ (define need-length-y (add1 new-peg-y-v)))
+ (and (not (negative? new-peg-x-v))
+ (not (negative? new-peg-y-v))
+ (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard new-peg-y-v)) need-length-x)
+ (not (vector-ref (vector-ref aboard new-peg-y-v) new-peg-x-v))
+ (vector-ref (vector-ref aboard remove-peg-y-v) remove-peg-x-v))))
+
+;next-states : board posn -> (listof states)
+;Given aboard and apeg, create a (listof (make-state b moves)), ie, a (listof states), which return all possible board configurations with their corresponding moves. (since there may be more than one possible jump, we must list the results as a listof boards) 1,1 is the first position in the board, not 0,0.
+
+(define (next-states aboard apeg)
+ (local ((define peg-x (posn-x apeg))
+ (define peg-y (posn-y apeg))
+ (define down-peg (make-posn peg-x (+ peg-y 2)))
+ (define right-peg (make-posn (+ peg-x 2) peg-y))
+ (define up-peg (make-posn peg-x (- peg-y 2)))
+ (define left-peg (make-posn (- peg-x 2) peg-y))
+ (define diagonal-up-peg (make-posn (- peg-x 2) (- peg-y 2)))
+ (define diagonal-down-peg (make-posn (+ peg-x 2) (+ peg-y 2))))
+
+ (filter (lambda (astate) (not (empty? (state-board astate))))
+ (list (make-state (jump aboard apeg down-peg) (list apeg down-peg))
+ (make-state (jump aboard apeg right-peg) (list apeg right-peg))
+ (make-state (jump aboard apeg up-peg) (list apeg up-peg))
+ (make-state (jump aboard apeg left-peg) (list apeg left-peg))
+ (make-state (jump aboard apeg diagonal-up-peg) (list apeg diagonal-up-peg))
+ (make-state (jump aboard apeg diagonal-down-peg) (list apeg diagonal-down-peg))))))
+
+;jump : board posn posn -> board or empty
+;Using aboard, return a new board with old-peg replaced with false and new-peg replaced with true. The intermediate peg is removed.
+
+(define (jump aboard old-peg new-peg)
+ (local ((define old-peg-x (posn-x old-peg))
+ (define old-peg-y (posn-y old-peg))
+ (define new-peg-x (posn-x new-peg))
+ (define new-peg-y (posn-y new-peg))
+ (define remove-peg-x (+ (/ (- new-peg-x old-peg-x) 2) old-peg-x))
+ (define remove-peg-y (+ (/ (- new-peg-y old-peg-y) 2) old-peg-y)))
+ (cond
+ [(jump? old-peg new-peg aboard)
+ (build-board (vector-length aboard)
+ (lambda (x y)
+ (cond
+ [(and (= x old-peg-x)
+ (= y old-peg-y)) false]
+ [(and (= x new-peg-x)
+ (= y new-peg-y)) true]
+ [(and (= x remove-peg-x)
+ (= y remove-peg-y)) false]
+ [else (vector-ref (vector-ref aboard (sub1 y)) (sub1 x))])))]
+ [else empty])))
+
+;build-board : N (N N -> X) -> (vectorof (vectorof X))
+;Builds a size-n equilateral triangle according to f, where (f i j) specifies the value of the i,jth position of the board. The first value corresponds to (i,j)=(1,1). i represents the horizontal distance (the column number), j represents the vertical distance (the row number).
+
+(define (build-board n f)
+ (build-vector n (lambda (i)
+ (build-vector (add1 i) (lambda (j) (f (add1 j) (add1 i)))))))
+
+;solitaire : board -> (listof moves), empty, or false
+;Given aboard0, solve the solitaire problem and return a (listof moves). If aboard0 is itself a solution, return empty. If the board cannot be solved, return false.
+
+(define (solitaire aboard0)
+ ;;previous-moves is an accumulator that represents the necessary moves to go from
+ ;;aboard0 to aboard1
+ (local
+ ((define (solitaire-accu aboard1 previous-moves pegs)
+ (cond
+ [(solved? aboard1) previous-moves]
+ [(empty? pegs) false]
+ [else
+ (local
+ ((define first-los (next-states aboard1 (first pegs)))
+ (define search-first-peg (solitaire/list-accu first-los previous-moves)))
+ (cond
+ [(boolean? search-first-peg)
+ (solitaire-accu aboard1 previous-moves (rest pegs))]
+ [else search-first-peg]))]))
+ (define (solitaire/list-accu alos previous-moves)
+ (cond
+ [(empty? alos) false]
+ [else
+ (local
+ ((define new-moves (append previous-moves
+ (list (state-move (first alos)))))
+ (define new-board (state-board (first alos)))
+ (define search-first-move
+ (solitaire-accu new-board new-moves (enabled-pegs new-board))))
+ (cond
+ [(boolean? search-first-move)
+ (solitaire/list-accu (rest alos) previous-moves)]
+ [else search-first-move]))])))
+ (solitaire-accu aboard0 empty (enabled-pegs aboard0))))
+
+;solitaire-accu : board (listof moves) (listof posns) -> (listof moves) or false
+;Solves aboard1 if possible and returns the listof moves necessary to reach the solution state. Otherwise, returns false. pegs "remembers" the enabled-pegs in aboard1 that have yet to be tested.
+
+;solitaire/list-accu : (listof states) (listof moves) -> (listof moves) or false
+
+
+;solved? : board -> boolean
+;Determines if aboard is solved
+
+(define (solved? aboard)
+ (cond
+ [(equal? aboard SOLVED-BOARD) true]
+ [else false]))
+
+(define SOLVED-BOARD
+ (build-board 6 (lambda (x y)
+ (cond
+ [(and (= x 1)
+ (= y 1)) true]
+ [else false]))))
+(define INITIAL-BOARD
+ (build-board 6 (lambda (x y)
+ (cond
+ [(and (= x 1)
+ (= y 1)) false]
+ [else true]))))
+
+;enabled-pegs : board -> (listof posns)
+;Determines all enabled pegs in a given board.
+
+(define (enabled-pegs aboard)
+ (filter (lambda (peg) (enabled? peg aboard))
+ (build-peg-list (vector-length aboard) (lambda (x y) (make-posn x y)))))
+
+;build-peg-list : N (N N -> X) -> (listof X)
+;Builds a list that corresponds to positions of an n-sized equilaterial triangle.
+
+(define (build-peg-list n f)
+ (foldr append empty
+ (build-list n (lambda (i)
+ (build-list (add1 i) (lambda (j) (f (add1 j) (add1 i))))))))
+
+(solitaire INITIAL-BOARD)
+
+;Wish-list:
+;
+;next-states,
+;jump,
+;enabled-pegs,
\ No newline at end of file
blob - /dev/null
blob + b02aeab9d324f3ac548fe005f837472b4feb1319 (mode 644)
--- /dev/null
+++ 32.3.1-5~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+;A solitaire board (board) is a (vectorof (vectorof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a vector containing n booleans. We call a triangular board with n-pegs to a side a size-n triangle. For example, the representation of a size-4 equilaterial triangular board:
+
+;(vector (vector false)
+; (vector true true)
+; (vector true true true)
+; (vector true true true true))
+
+;enabled? : posn board -> boolean
+;Determines whether or not the peg specified by aposn is enabled in aboard (enabled means that the peg is capable of jumping). The top position of the board has the index (make-posn 1 1). The vertical axis is denoted by y, the horizontal by x.
+
+;next-peg-x represents the x-index where the peg will jump to if it jumps to the right
+;next-peg-y represents the y-index where the peg will jump to if it jumps down
+;prev-peg-x represents the x-index ... if the peg jumps to the left
+;prev-peg-x represents the y-index ... if the peg jumps up
+;need-length-x represents the necessary horizontal length of the board to jump to the right
+;need-length-y represents the necessary vertical length of the board to jump down
+;next-peg-x-removes represents the x-index of the peg that will be removed if the peg is jumped, etc.
+
+;the parameters for the position of the new peg as well as the peg to be removed are passed to jump?.
+
+(define (enabled? aposn aboard)
+ (local ((define peg-x (sub1 (posn-x aposn)))
+ (define peg-y (sub1 (posn-y aposn)))
+ (define next-peg-x-removes (+ peg-x 1))
+ (define next-peg-y-removes (+ peg-y 1))
+ (define prev-peg-x-removes (- peg-x 1))
+ (define prev-peg-y-removes (- peg-y 1))
+ (define next-peg-x (+ peg-x 2))
+ (define next-peg-y (+ peg-y 2))
+ (define prev-peg-x (- peg-x 2))
+ (define prev-peg-y (- peg-y 2)))
+ (cond
+ ;;first, is there even a peg?
+ ;;if so, test jump down, jump right, jump up, jump left, jump diagonal (up), jump diagonal (down), in that order
+ [(vector-ref (vector-ref aboard peg-y) peg-x)
+ (or (jump? peg-x next-peg-y peg-x next-peg-y-removes aboard)
+ (jump? next-peg-x peg-y next-peg-x-removes peg-y aboard)
+ (jump? peg-x prev-peg-y peg-x prev-peg-y-removes aboard)
+ (jump? prev-peg-x peg-y prev-peg-x-removes peg-y aboard)
+ (jump? prev-peg-x prev-peg-y prev-peg-x-removes prev-peg-y-removes aboard)
+ (jump? next-peg-x next-peg-y next-peg-x-removes next-peg-y-removes aboard))]
+ [else false])))
+
+;jump? : N N N N board-> boolean
+;Given new-peg-x, new-peg-y, remove-peg-x, remove-peg-y, and aboard, determine if it is possible to make a jump. All coordinates are in terms of vector indices. E.g, 0,0 represents the first element in the first vector.
+
+(define (jump? new-peg-x new-peg-y remove-peg-x remove-peg-y aboard)
+ (local ((define need-length-x (add1 new-peg-x))
+ (define need-length-y (add1 new-peg-y)))
+ (and (not (negative? new-peg-x))
+ (not (negative? new-peg-y))
+ (>= (vector-length aboard) need-length-y)
+ (>= (vector-length (vector-ref aboard new-peg-y)) need-length-x)
+ (not (vector-ref (vector-ref aboard new-peg-y) new-peg-x))
+ (vector-ref (vector-ref aboard remove-peg-y) remove-peg-x))))
+
+;next-board : board posn -> (listof boards) or false
+;Given aboard and aposn, return all possible board configurations if the peg specified by aposn is jumped. (since there may be more than one possible jump, we must list the results as a listof boards)
+
+(define (next-board aboard aposn)
+ (cond
+ [(enabled? aposn aboard)
+ (append (jump aboard aposn) ;down
+ (jump aboard aposn) ;right
+ (jump aboard aposn) ;up
+ (jump-left aboard aposn) ;left
+ (jump-diagonal-up aboard aposn) ;diagonal-up
+ (jump-diagonal-down aboard aposn))] ;diagonal-down
+ [else false]))
+
+jump : board posn posn -> board
+Using aboard, return a new board with old-peg replaced with false and new-peg replaced with true. The intermediate peg is removed.
+
+(define (jump aboard new-peg old-peg)
+ (cond))
\ No newline at end of file
blob - /dev/null
blob + 821894aca91818091353d55c1bcb4ae24d3e0a5c (mode 644)
--- /dev/null
+++ 32.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |32.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")))))
+A solitaire board (board) is a (listof (listof booleans)), where true represents a filled square, false an empty square. In particular, for any given board, the n-th element is a list containing n booleans. For example, the representation of a equilaterial triangular board with 4 pegs to a side, missing the top peg:
+
+(list (list false)
+ (list true true)
+ (list true true true)
+ (list true true true true))
+
+
+
+(listof (listof booleans))
+
+true represents a filled square, false an empty square
\ No newline at end of file
blob - /dev/null
blob + 3d295e8e082d90ed45d192f38815b4ab10cf991e (mode 644)
--- /dev/null
+++ 33.1.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (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")))))
+(define-struct inex (mantissa sign exponent))
+
+;An inexact number (inex) is a structure
+;(make-inex m s e)
+;where m, e are N in the interval [0,99] and s is either +1 or -1.
+;
+;create-inex : N N N -> inex
+;Creates an inex from mantissa, sign, and exponent.
+
+(define (create-inex mantissa sign exponent)
+ (cond
+ [(and (<= 0 mantissa 99)
+ (<= 0 exponent 99)
+ (= (abs sign) 1)) (make-inex mantissa sign exponent)]
+ [else (error 'create-inex "(<= 0 m 99), +1 or -1, (<= 0 e 99) expected")]))
+
+;inex->number : inex -> number
+;Given an-inex, convert it to an exact number.
+
+(define (inex->number an-inex)
+ (* (inex-mantissa an-inex)
+ (expt 10 (* (inex-sign an-inex) (inex-exponent an-inex)))))
+
+(inex->number (create-inex 55 -1 3))
blob - /dev/null
blob + 0e1239a13319cbc4f22d7cd603736a86618936e7 (mode 644)
--- /dev/null
+++ 33.1.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (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")))))
+(define-struct inex (mantissa sign exponent))
+
+An inexact number (inex) is a structure
+(make-inex m s e)
+where m, e are N in the interval [0,99] and s is either +1 or -1.
+
+create-inex : N N N -> inex
+Creates an inex from mantissa, sign, and exponent.
+
+(define (create-inex mantissa sign exponent)
+ (cond
+ [(and (<= 0 m 99)
+ (<= 0 e 99)
+ (= (abs s) 1)) (make-inex m s e)]
+ [else (error 'create-inex "(<= 0 m 99), +1 or -1, (<= 0 e 99) expected")]))
\ No newline at end of file
blob - /dev/null
blob + 79c6402bc458e8de715a33c33f4bc1d9ca72c498 (mode 644)
--- /dev/null
+++ 33.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (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")))))
+(define-struct inex (mantissa sign exponent))
+
+;An inexact number (inex) is a structure
+;(make-inex m s e)
+;where m, e are N in the interval [0,99] and s is either +1 or -1.
+;
+;create-inex : N N N -> inex
+;Creates an inex from mantissa, sign, and exponent.
+
+(define (create-inex mantissa sign exponent)
+ (cond
+ [(and (<= 0 mantissa 99)
+ (<= 0 exponent 99)
+ (= (abs sign) 1)) (make-inex mantissa sign exponent)]
+ [else (error 'create-inex "(<= 0 m 99), +1 or -1, (<= 0 e 99) expected")]))
+
+;inex->number : inex -> number
+;Given an-inex, convert it to an exact number.
+
+(define (inex->number an-inex)
+ (* (inex-mantissa an-inex)
+ (expt 10 (* (inex-sign an-inex) (inex-exponent an-inex)))))
+
+;;Test
+;(equal? (inex->number (create-inex 55 -1 3)) 0.055)
+
+#|
+
+;inex+ : inex inex -> inex
+;Adds inex1 to inex2 if the two exponents equal. Automatically changes the mantissa and exponent if the sum causes the mantissa to go out of bounds, and signals an error if the resulting inex is out of bounds.
+
+(define (inex+ inex1 inex2)
+ (cond
+ [(and (inex? inex1)
+ (inex? inex2)
+ (= (inex-sign inex1) (inex-sign inex2))
+ (= (inex-exponent inex1) (inex-exponent inex2)))
+ (create-adjusted-inex (+ (inex-mantissa inex1) (inex-mantissa inex2))
+ (inex-sign inex1)
+ (inex-exponent inex1))]
+ [else (error 'inex+ "addition failed")]))
+
+|#
+
+;inex+ : inex inex -> inex
+;Adds inex1 to inex2 if the two exponents are equal or differ only by one. Automatically changes the mantissa and exponent if the sum causes the mantissa to go out of bounds, and signals an error if the resulting inex is out of bounds.
+
+(define (inex+ inex1 inex2)
+ (cond
+ [(and (inex? inex1)
+ (inex? inex2))
+ (local ((define expdiff (- (* (inex-sign inex1) (inex-exponent inex1))
+ (* (inex-sign inex2) (inex-exponent inex2)))))
+ (cond
+ [(= expdiff 0)
+ (create-adjusted-inex (+ (inex-mantissa inex1) (inex-mantissa inex2))
+ (inex-sign inex1)
+ (inex-exponent inex1))]
+ [(= expdiff 1)
+ (create-adjusted-inex (+ (* (inex-mantissa inex1) 10) (inex-mantissa inex2))
+ (inex-sign inex2)
+ (inex-exponent inex2))]
+ [(= expdiff -1)
+ (create-adjusted-inex (+ (inex-mantissa inex1) (* (inex-mantissa inex2) 10))
+ (inex-sign inex1)
+ (inex-exponent inex1))]
+ [else (error 'inex+ "addition failed")]))]
+ [else (error 'inex+ "addition failed")]))
+
+;create-adjusted-inex : N N N -> inex
+;Given mantissa, sign, and exponent, create an inex such that both the mantissa and exponent are in the interval [0,99]
+#|
+(define (create-adjusted-inex mantissa sign exponent)
+ (cond
+ [(and (<= 0 mantissa 99)
+ (= (abs sign) 1)
+ (<= 1 exponent 99))
+ (make-inex (round mantissa)
+ (round sign)
+ (round exponent))]
+ [(and (<= 0 mantissa 99)
+ (= (abs sign) 1)
+ (= 0 exponent))
+ (make-inex (round mantissa)
+ +1
+ (round exponent))]
+ [(and (<= 100 mantissa)
+ (= sign 1)
+ (<= 0 exponent 99))
+ (create-adjusted-inex (/ mantissa 10) sign (+ exponent 1))]
+ [(and (<= 100 mantissa)
+ (= sign -1)
+ (<= 2 exponent 99))
+ (create-adjusted-inex (/ mantissa 10) sign (- exponent 1))]
+ [(and (<= 100 mantissa)
+ (= sign -1)
+ (= 1 exponent))
+ (create-adjusted-inex (/ mantissa 10) +1 (- exponent 1))]
+ [(and (<= 100 mantissa)
+ (= sign -1)
+ (= 0 exponent))
+ (create-adjusted-inex (/ mantissa 10) +1 (+ exponent 1))]
+ [else (error 'create-adjusted-inex "out-of-bounds")]))
+|#
+(define (create-adjusted-inex mantissa sign exponent)
+ (cond
+ [(and (<= 0 mantissa 99)
+ (= (abs sign) 1)
+ (<= 0 exponent 99))
+ (make-inex (round mantissa)
+ (signof (* sign exponent))
+ (round (abs exponent)))]
+ [(and (<= 100 mantissa)
+ (>= (* sign exponent) 0))
+ (create-adjusted-inex (/ mantissa 10) (signof (* sign exponent)) (+ exponent 1))]
+ [(and (<= 100 mantissa)
+ (< (* sign exponent) 0))
+ (create-adjusted-inex (/ mantissa 10) (signof (* sign (- exponent 1))) (- exponent 1))]
+ [else (error 'create-adjusted-inex "out-of-bounds")]))
+
+(define (signof n)
+ (cond
+ [(>= n 0) +1]
+ [else -1]))
+
+
+;signals an error
+;(inex+ (make-inex 1923 1 99) (make-inex 2422 1 99))
+
+;inex* : inex inex -> inex
+;Multiplies inex1 by inex2.
+
+(define (inex* inex1 inex2)
+ (local ((define newexp (+ (* (inex-sign inex1) (inex-exponent inex1))
+ (* (inex-sign inex2) (inex-exponent inex2)))))
+ (create-adjusted-inex (* (inex-mantissa inex1) (inex-mantissa inex2))
+ (signof newexp)
+ (abs newexp))))
+
+(and (equal? (inex+ (make-inex 55 -1 1) (make-inex 55 -1 1)) (make-inex 11 1 0))
+ (equal? (inex+ (make-inex 20 -1 1) (make-inex 80 -1 1)) (make-inex 10 1 0))
+ (equal? (inex+ (make-inex 16 -1 0) (make-inex 84 -1 0)) (make-inex 10 1 1))
+ (equal? (inex+ (make-inex 55 1 0) (make-inex 55 1 0)) (make-inex 11 1 1))
+ (equal? (inex+ (make-inex 55 -1 1) (make-inex 55 -1 1)) (make-inex 11 1 0))
+ (equal? (inex+ (make-inex 955 -1 0) (make-inex 405 -1 0)) (make-inex 14 1 2))
+ (equal? (inex+ (make-inex 9655 1 1) (make-inex 5565 1 1)) (make-inex 15 1 4))
+ (equal? (inex+ (make-inex 9855 -1 1) (make-inex 9955 -1 1)) (make-inex 20 1 2))
+ (equal? (inex+ (make-inex 23 -1 50) (make-inex 22 -1 50)) (make-inex 45 -1 50))
+ (equal? (inex+ (make-inex 5423 -1 50) (make-inex 9622 -1 50)) (make-inex 15 -1 47))
+ (equal? (inex+ (make-inex 1923 -1 99) (make-inex 2422 -1 99)) (make-inex 43 -1 97))
+ (equal? (inex+ (make-inex 1 -1 99) (make-inex 1 -1 99)) (make-inex 2 -1 99))
+ (equal? (inex+ (make-inex 5 -1 3) (make-inex 5 -1 4)) (make-inex 55 -1 4))
+ (equal? (inex+ (make-inex 5 -1 3) (make-inex 5 -1 2)) (make-inex 55 -1 3))
+ (equal? (inex+ (make-inex 5 1 99) (make-inex 45 1 98)) (make-inex 95 1 98))
+ (equal? (inex* (make-inex 55 -1 1) (make-inex 55 -1 1)) (make-inex 30 1 0)))
\ No newline at end of file
blob - /dev/null
blob + 06cc6294441e200cb1fe7ec5db620f4ec62eb23d (mode 644)
--- /dev/null
+++ 33.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (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")))))
+(define-struct inex (mantissa sign exponent))
+
+;An inexact number (inex) is a structure
+;(make-inex m s e)
+;where m, e are N in the interval [0,99] and s is either +1 or -1.
+;
+;create-inex : N N N -> inex
+;Creates an inex from mantissa, sign, and exponent.
+
+(define (create-inex mantissa sign exponent)
+ (cond
+ [(and (<= 0 mantissa 99)
+ (<= 0 exponent 99)
+ (= (abs sign) 1)) (make-inex mantissa sign exponent)]
+ [else (error 'create-inex "(<= 0 m 99), +1 or -1, (<= 0 e 99) expected")]))
+
+;inex->number : inex -> number
+;Given an-inex, convert it to an exact number.
+
+(define (inex->number an-inex)
+ (* (inex-mantissa an-inex)
+ (expt 10 (* (inex-sign an-inex) (inex-exponent an-inex)))))
+
+;;Test
+;(equal? (inex->number (create-inex 55 -1 3)) 0.055)
+
+inex+
\ No newline at end of file
blob - /dev/null
blob + 39c8c483b05431795874cec318e55115262f69ee (mode 644)
--- /dev/null
+++ 33.1.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (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")))))
+;add : N -> inexact
+;Adds up #i1/185 n times.
+
+(define (add n)
+ (cond
+ [(= n 1) #i1/185]
+ [else (+ #i1/185 (add (sub1 n)))]))
+
+;sub : inexact or number N -> N
+;Determines the number of times that 1/185 can be subtracted from n0. The accumulator represents the number of times that 1/185 has been subtracted from n0 to give n1.
+
+(define (sub n0)
+ (local ((define (sub-accu n1 accumulator)
+ (cond
+ [(<= n1 0) accumulator]
+ [else (sub-accu (- n1 1/185) (add1 accumulator))])))
+ (sub-accu n0 0)))
\ No newline at end of file
blob - /dev/null
blob + 71ae2af196f1552118df049debe0b3e4f3c638f2 (mode 644)
--- /dev/null
+++ 33.1.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (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")))))
+;add : N -> inexact
+;Adds up #i1/185 n times.
+
+(define (add n)
+ (cond
+ [(= n 1) #i1/185]
+ [else (+ #i1/185 (add (sub1 n)))]))
+
+sub : inexact or number N -> N
+Determines the number of times that 1/185 can be subtracted from n0. The accumulator represents the number of times that 1/185 has been subtracted from n0 to give n1.
+
+(define (sub n0)
+ (local ((define (sub-accu n1 accumulator)
+ (cond
+ [(zero? n) ...]
+ [else ...])))
+ (sub n0 ...)))
\ No newline at end of file
blob - /dev/null
blob + 06740d5d3e4ba99aca11f0d305e73f22a7c49876 (mode 644)
--- /dev/null
+++ 33.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.2|) (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")))))
+;overflow-n? : N -> N
+;Searches for a value from [n,+inf.0) such that the number returned is the largest natural number where (expt #i10. n) is still an inexact number rather than infinity.
+
+(define (overflow-n? n)
+ (cond
+ [(< (expt #i10. (+ n 1)) +inf.0) (overflow-n? (add1 n))]
+ [else n]))
+
+(overflow-n? 1)
+
+underflow-n? : integer -> integer
+;Searches for a value from (-inf.0,n] such that the number returned is the smallest integer possible where (expt #i10. n) is still an inexact number rather than #i0
+
+(define (underflow-n? n)
+ (cond
+ [(> (expt #i10. n) #i0) (underflow-n? (sub1 n))]
+ [else n]))
\ No newline at end of file
blob - /dev/null
blob + 65fa73d4979604a1c43a4f9f6d476d2030b76d84 (mode 644)
--- /dev/null
+++ 33.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.2|) (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")))))
+;infinite-n? : N -> N
+;Searches for a value from [n,inf) such that n is the largest natural number where (expt #i10. n) is still an inexact number rather than infinity.
+
+(define (infinite-n? n)
+ (cond
+ [(< (expt #i10 (+ n 1)) +inf.0) (infinite-n? (add1 n))]
+ [else n]))
\ No newline at end of file
blob - /dev/null
blob + b6d1bd97810838b1c3ac1e158935643dada118fc (mode 644)
--- /dev/null
+++ 33.4.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.4|) (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")))))
+(define (my-expt n1 n2)
+ (expt n1 n2))
+
+(define inex (+ 1 #i1e-12))
+(define exac (+ 1 1e-12))
+
+(my-expt inex 30)
+(my-expt exac 30)
\ No newline at end of file
blob - /dev/null
blob + 813b16eba996b8b79f954cd51068579787353491 (mode 644)
--- /dev/null
+++ 35.4.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |35.4|) (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")))))
+;An address-book (ab) is either
+;1. empty or
+;2. (cons (cons s (cons n empty)) ab) [(list (list s n)
+; ab)]
+;where s is a symbol, n is a number, and ab is an address-book.
+
+(define my-book empty)
+
+;add-to-address-book : symbol number -> void
+
+(define (add-to-address-book name phone)
+ (set! my-book (cons (list name phone) my-book)))
+
+;lookup : symbol ab -> number or false
+;Lookup the phone number for aname in abook. Returns false if aname is not in abook.
+(define (lookup aname abook)
+ (cond
+ [(empty? abook) false]
+ [(symbol=? (first (first abook)) aname) (second (first abook))]
+ [else (lookup aname (rest abook))]))
+
+;remove : symbol -> void
+;Removes the entry associated with aname from my-book.
+
+(define (remove aname)
+ (local ((define (remove-aux aname abook)
+ (cond
+ [(empty? abook) empty]
+ [(symbol=? (first (first abook)) aname) (remove-aux aname (rest abook))]
+ [else (cons (first abook)
+ (remove-aux aname (rest abook)))])))
+ (set! my-book (remove-aux aname my-book))))
+
+
+(begin (add-to-address-book 'Aaron 6265939257)
+ (add-to-address-book 'Hsinya 9174633)
+ (add-to-address-book 'Jessica 102853)
+ (add-to-address-book 'Tuna 1234567)
+ (remove 'Aaron))
+
blob - /dev/null
blob + 8e44b2011c22f0719143a84665d7586e0fcf7585 (mode 644)
--- /dev/null
+++ 35.4.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |35.4|) (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")))))
+;An address-book (ab) is either
+;1. empty or
+;2. (cons s (cons n ab)) [(list (list s n)
+; ab)]
+;where s is a symbol, n is a number, and ab is an address-book.
+
+(define my-book empty)
+
+add-to-address-book : symbol number -> void
+
+(define (add-to-address-book name phone)
+ (set! my-book (cons (list name phone) my-book)))
blob - /dev/null
blob + a1717e5ff72e99c872a5b12be008bfabddb5b5dd (mode 644)
--- /dev/null
+++ 36.4.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |36.4|) (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")))))
blob - /dev/null
blob + 127e820c6ee289a09ed780a9f81b5235cb69abcd (mode 644)
--- /dev/null
+++ 36.4.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |36.4|) (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")))))
+;A traffic-light color (TL-color) is either
+;1. 'red,
+;2. 'yellow, or
+;3. 'green.
+
+;;State Variable:
+;;current-color : TL-color
+(define current-color 'red)
+
+;next : -> void
+;Effect: Changes current-color from 'red to 'green, 'green to 'yellow, or 'yellow to 'red depending on what the current-color is. Produces no output.
+
+(define (next)
+ (set! (next-color current-color)))
+
+;next-color : TL-color -> TL-color
+;Given acolor, returns the next logical color.
+
+(define (next-color acolor)
+ (cond
+ [(symbol=? acolor 'red) 'green]
+ [(symbol=? acolor 'yellow) 'red]
+ [(symbol=? acolor 'green) 'yellow]))
\ No newline at end of file
blob - /dev/null
blob + e5b8aa61a14c6f35620e71356b1910566e4cec1a (mode 644)
--- /dev/null
+++ 36.4.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |36.4|) (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")))))
+;;Model
+
+;;State Variable
+;;address-book : (listof (list symbol number))
+;;Stores a list of list of two items (pairs) of names and numbers representing entries in an address book.
+(define address-book empty)
+
+;add-to-address-book : symbol number -> void
+;Effect: Adds name and phone to the address-book. Produces no output.
+
+(define (add-to-address-book name phone)
+ (set! address-book (cons (list name phone) address-book)))
+
+;remove : symbol -> void
+;Effect: Removes name from address-book. No output returned.
+(define (remove name)
+ (local ((define (remove-aux aname abook)
+ (cond
+ [(empty? abook) empty]
+ [(symbol=? (first (first abook)) aname) (remove-aux aname (rest abook))]
+ [else (cons (first abook)
+ (remove-aux aname (rest abook)))])))
+ (set! address-book (remove-aux name address-book))))
+
+
+
+;lookup-name : symbol (listof (list symbol number)) -> number or false
+;Output: Lookup the phone number for aname in abook. No effect (memory neither changed nor accessed).
+
+(define (lookup-name aname abook)
+ (lookup-abstract aname abook first second))
+
+;lookup-number : number (listof (list symbol number)) -> symbol or false
+;Output: Lookup the name for the entry with anumber in abook. No effect (memory neither changed nor accessed).
+
+(define (lookup-number anumber abook)
+ (lookup-abstract anumber abook second first))
+
+;lookup-abstract : X (listof (list symbol number)) ((listof Z) -> Z) ((listof Z) -> Z) -> Y
+;Output: Given anx, abook, op1, and op2, returns a number given a symbol or a symbol given a number. X and Y are different data types.
+;No effect.
+
+(define (lookup-abstract anx abook op1 op2)
+ (cond
+ [(empty? abook) false]
+ [(equal? (op1 (first abook)) anx) (op2 (first abook))]
+ [else (lookup-abstract anx (rest abook) op1 op2)]))
+
+;;View
+
+(define name-text (make-text "Name"))
+(define number-text (make-text "Number"))
+(define results-message (make-message "Delta Notch Phone Beta"))
+
+
+;;Controller
+
+;add-entry-callback : event -> true
+;Effect: Adds the contents of name-text and number-text into the beginning of address-book.
+(define (add-entry-callback event)
+ (void? (add-to-address-book (string->symbol (text-contents name-text)) (string->number (text-contents number-text)))))
+
+;remove-name-callback : event -> true
+;Effect: Removes an entry from address-book associated with the text contents of name-text.
+(define (remove-name-callback event)
+ (void? (remove (string->symbol (text-contents name-text)))))
+
+;search-callback : event -> true
+(define (search-callback event)
+ (local
+ ((define found-name
+ (lookup-number (string->number (text-contents number-text)) address-book))
+ (define found-number
+ (lookup-name (string->symbol (text-contents name-text)) address-book)))
+ (cond
+ [(and (equal? (text-contents name-text) "")
+ (symbol? found-name))
+ (draw-message results-message (symbol->string found-name))]
+ [(number? found-number)
+ (draw-message results-message (number->string found-number))]
+ [else (draw-message results-message "Entry not found")])))
+
+
+
+(create-window (list (list name-text (make-button "Add entry" add-entry-callback))
+ (list number-text (make-button "Search!" search-callback))
+ (list results-message (make-button "Remove name" remove-name-callback))))
+
+;Tests
+(define (init-address-book)
+ (begin (add-to-address-book 'Aaron 525)
+ (add-to-address-book 'Geffen 3225)
+ (add-to-address-book 'Jobs 5251)
+ (add-to-address-book 'Gates 5265)
+ (add-to-address-book 'Dell 5259)
+ (remove 'Aaron)
+ address-book))
+(init-address-book)
\ No newline at end of file
blob - /dev/null
blob + a1717e5ff72e99c872a5b12be008bfabddb5b5dd (mode 644)
--- /dev/null
+++ 36.4.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |36.4|) (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")))))
blob - /dev/null
blob + f7d968a40d67dea55b7c79135ef609c2c1de725d (mode 644)
--- /dev/null
+++ 37.1.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.1|) (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")))))
+;;Model
+
+;;Constants
+
+;;The allowed variety of colors for mastermind as a (listof symbols).
+(define COLORS '(black white red blue green gold pink orange purple navy))
+
+;;The number of colors. The number of colors must be even.
+(define COL# (length COLORS))
+
+;;Data Definition
+;;A color is a symbol found in COLORS.
+
+;;State Variables
+;;target1, target2 : colors
+;;Both target1 and target2 represent the chosen colors for mastermind. They are originally defined to be the first entry in COLORS but their definitions will change after master initializes the state variables.
+(define target1 (first COLORS))
+(define target2 (first COLORS))
+
+;;guesses : number
+;;guesses represent the number of guesses taken to reach the answer for mastermind.
+(define guesses 0)
+
+;;guess1, guess2 : color
+;;Represents the first or second color guessed.
+
+(define guess1 (first COLORS))
+(define guess2 (first COLORS))
+
+;;click-number : N
+;;Determines whether this is the first click in a pair or the second. If the click-number is 2, we will clear the messages that keep track of which guesses have been made for a pair, and write the new guess in guess1-message. If the click-number is 1, we will not clear anything and fill in guess2-message.
+
+(define click-number 2)
+
+;;master : -> void
+;;Initializes each of target1 and target2 to a random color in COLORS. Also initializes the number of guesses to 0.
+
+(define (master)
+ (begin (set! target1 (random-pick COLORS))
+ (set! target2 (random-pick COLORS))
+ (set! guesses 0)
+ (set! guess1 (first COLORS))
+ (set! guess2 (first COLORS))
+ (set! click-number 2)))
+
+;random-pick : (listof X) -> XExercise 37.1.4. Modify the color guessing program so that it
+;Given alist, randomly choose one item from that list.
+
+(define (random-pick alist)
+ (list-ref alist (random (length alist))))
+
+;; check-guess : color color color color -> symbol
+;; Given guess1 and guess2, which are symbols representing the color of squares 1
+;; and 2, respectively, the function lets you check if the guesses are the same
+;; as target1 and target2.
+
+(define (check-guess guess1 guess2 target1 target2)
+ (cond
+ [(and (symbol=? guess1 target1)
+ (symbol=? guess2 target2)) 'Perfect]
+ [(or (symbol=? guess1 target1)
+ (symbol=? guess2 target2)) 'OneColorAtCorrectPosition]
+ [(or (symbol=? guess1 target2)
+ (symbol=? guess2 target1)) 'OneColorOccurs]
+ [else 'NothingCorrect]))
+
+;master-check : color color -> (list symbol number)
+;Returns a list containing a message and a number. The message either indicates that the game is solved given guess1 and guess2, or it reveals a hint. The number indicates the number of guesses taken.
+;Effect : Increases the number of guesses by 1 each time.
+(define (master-check guess1 guess2)
+ (local ((define return-list
+ (begin (set! guesses (add1 guesses))
+ (list (check-guess guess1 guess2 target1 target2) guesses))))
+ (cond
+ [(and (symbol=? guess1 target1)
+ (symbol=? guess2 target2)) (begin (master)
+ return-list)]
+ [else return-list])))
+
+;;View
+
+(define guess1-message (make-message "Guess 1"))
+(define guess2-message (make-message "Guess 2"))
+(define status-message (make-message "Let's play mastermind!"))
+(define num-guesses-message (make-message "Guesses: 0"))
+
+;;Controller
+
+;color-callback : color color -> true
+;Draws the message associated with the two color guesses (status-message) and also the number of guesses in the appropriate text-box given color1 and color2.
+
+;;button-callback : event -> true
+;;Effect: writes guess1 into guess1-message and guess2 into guess2-message. Once the second guess has been made, button-callback will write the hint and number of guesses into status-message and num-guesses-message through color-callback.
+
+(define (color-callback color1 color2)
+ (local ((define result-list (master-check color1 color2)))
+ (and (draw-message status-message (symbol->string (first result-list)))
+ (draw-message num-guesses-message (number->string (second result-list))))))
+
+;make-color-button : N N -> GUI-Item (button)
+;Given col and row (0,0 inclusive), make the button for the given color at row, col.
+;Effect: Accesses click-number, guess1, guess2
+(define (make-color-button col row)
+ (local
+ ((define index (+ col (* (/ COL# 2) row)))
+ (define current-color (list-ref COLORS index))
+ (define (button-callback event)
+ (cond
+ [(= click-number 2)
+ (begin (set! guess1 current-color)
+ (set! click-number 1)
+ (draw-message guess1-message (symbol->string current-color))
+ (draw-message guess2-message ""))]
+ [(= click-number 1)
+ (begin (set! guess2 current-color)
+ (set! click-number 2)
+ (draw-message guess2-message (symbol->string current-color))
+ (color-callback guess1 guess2))])))
+ (make-button (symbol->string current-color) button-callback)))
+
+(define buttons-list
+ (build-list 2 (lambda (y)
+ (build-list (/ COL# 2)
+ (lambda (x) (make-color-button x y))))))
+
+;init-mastermind : -> true
+;Initiates the game mastermind.
+
+(define (init-mastermind)
+ (begin (master)
+ (create-window (append buttons-list
+ (list (list guess1-message guess2-message)
+ (list status-message num-guesses-message))))))
+
+(init-mastermind)
blob - /dev/null
blob + 33670de289aef97e6879d0f18aecd9ce286a2b06 (mode 644)
--- /dev/null
+++ 37.1.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname Scheme) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp")))))
+;; check-guess : symbol symbol symbol symbol -> symbol
+;; Given guess1 and guess2, which are symbols representing the color of squares 1
+;; and 2, respectively, the function lets you check if the guesses are the same
+;; as target1 and target2.
+
+(define (check-guess guess1 guess2 target1 target2)
+ (cond
+ [(and
+ (symbol=? guess1 target1)
+ (symbol=? guess2 target2))
+ 'Perfect]
+ [(or
+ (symbol=? guess1 target1)
+ (symbol=? guess2 target2))
+ 'OneColorAtCorrectPosition]
+ [(or
+ (symbol=? guess1 target2)
+ (symbol=? guess2 target1))
+ 'OneColorOccurs]
+ [else 'NothingCorrect]))
\ No newline at end of file
blob - /dev/null
blob + fda73a1417041954916a11f5b201e674e6543d26 (mode 644)
--- /dev/null
+++ 37.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.2|) (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")))))
+;;Model
+
+;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s h)
+ (s e a l i o n)
+ (t u n a)
+ (d o l p h i n)
+ (w h a l e)
+ (k e l p)
+ (m a n a t e e)))
+
+;;The alphabet
+(define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+
+;;The number of words
+(define WORDS# (length WORDS))
+
+;;A body-part is one of the following symbols:
+(define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+;;State Variables
+
+;;chosen-word : word
+;;This word is the target word that the player needs to guess
+
+(define chosen-word (first WORDS))
+
+;;status-word : word
+;;This word represents the current status of the player's guesses
+
+(define status-word (first WORDS))
+
+;;body-parts-left : (listof body-parts)
+;;Indicates how many body-parts are left before the hangman is dead.
+
+(define body-parts-left PARTS)
+
+;;previous-guesses : word
+;;Keeps track of all previous guesses.
+
+(define previous-guesses empty)
+
+;make-status-word : word -> word
+;Given aword, creates an equally long word consisting only of the letter '_.
+
+(define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+;;hangman : -> void
+;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+
+(define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)))
+
+;;Initializes the state variables
+(hangman)
+
+;A response is either
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+;hangman-guess : letter -> response
+;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+(define (hangman-guess aletter)
+ (local ((define updated-status (reveal-word chosen-word status-word aletter)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [(equal? status-word updated-status)
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]
+ [else (begin (set! status-word updated-status)
+ (cond
+ [(equal? status-word chosen-word) "You won"]
+ [else (list "Good guess!" status-word)]))]))])))
+
+;reveal-word: word word letter -> word
+;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+(define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(equal? chosen-letter aletter) chosen-letter]
+ [else status-letter])))
+ (map reveal-letter chosen-word status-word)))
+
+;contains : (listof X) X -> boolean
+;Determine if alox contains anx
+(define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+;Exercise 37.2.4. Formulate the four examples for hangman-guess as boolean-valued expressions that produce true if hangman-guess is correct. Develop an additional example for each case; turn these new examples into additional tests. Solution
+
+#|
+;Tests
+;test-hangman : letter word X -> boolean
+;Tests hangman-guess and returns true if the test is successful. Consumes guess (a letter), status (a word), partsleft (listof body-parts), and response (one of the four responses).
+(define (test-hangman guess status partsleft response)
+ (begin (set! chosen-word '(b a l l))
+ (set! status-word status)
+ (set! body-parts-left partsleft)
+ (equal? (hangman-guess guess) response)))
+
+
+
+(and (test-hangman 'l '(b _ _ _) '(arm leg) '("Good guess!" (b _ l l)))
+ (equal? status-word '(b _ l l)))
+(test-hangman 'a '(b _ l l) '(arm leg) "You won")
+(and (test-hangman 'l '(b _ l l) '(right-leg left-leg) '("Sorry" right-leg (b _ l l)))
+ (equal? body-parts-left '(left-leg)))
+(and (test-hangman 'l '(b _ l l) '(left-leg) '("The End" (b a l l)))
+ (equal? body-parts-left empty))
+|#
+
+;;View
+
+;word->string : word -> string
+;Given a word, convert it to a string.
+
+(define (word->string aword)
+ (foldr string-append "" (map (lambda (aletter) (symbol->string aletter)) aword)))
+
+;;GUI-items
+(define guess-message (make-message "Guess: "))
+(define guess-choice (make-choice (map (lambda (aletter) (symbol->string aletter)) LETTERS)))
+(define status-message (make-message "Status: "))
+(define status-word-message (make-message (word->string status-word)))
+(define result-message (make-message "Let's play hangman!"))
+(define body-part-message (make-message ""))
+
+;;Controller
+
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+
+(define (check-call-back event)
+ (local ((define response (hangman-guess (list-ref LETTERS (choice-index guess-choice)))))
+ (cond
+ [(string? response) (and (draw-message result-message response)
+ (draw-message status-word-message (word->string status-word)))]
+ [(= (length response) 2)
+ (and (draw-message result-message (first response))
+ (draw-message status-word-message (word->string (second response))))]
+ [(and (draw-message result-message (first response))
+ (draw-message body-part-message (symbol->string (second response)))
+ (draw-message status-word-message (word->string (third response)))
+ (draw-next-part (second response)))
+ (cond
+ [(empty? body-parts-left)
+ (begin (hangman)
+ (draw-message status-message "Chosen Word:"))]
+ [else true])])))
+
+(define check-button (make-button "Check" check-call-back))
+
+(create-window
+ (list (list guess-message guess-choice check-button)
+ (list status-message status-word-message)
+ (list result-message body-part-message)))
+
+(define CWIDTH 300)
+(define CHEIGHT 300)
+(start CWIDTH CHEIGHT)
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (local ((define XCENTER (/ CWIDTH 2))
+ (define COLORHEAD 'brown)
+ (define COLORBODY 'purple)
+ (define COLORARMS 'brown)
+ (define COLORLEGS 'red)
+ (define (draw-noose)
+ (and (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5)))))
+ (define (draw-head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD))
+ (define (draw-body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY))
+ (define (draw-right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS))
+ (define (draw-left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)))
+ (cond
+ [(symbol=? part 'noose) (draw-noose)]
+ [(symbol=? part 'head) (draw-head)]
+ [(symbol=? part 'body) (draw-body)]
+ [(symbol=? part 'right-arm) (draw-right-arm)]
+ [(symbol=? part 'left-arm) (draw-left-arm)]
+ [(symbol=? part 'right-leg) (draw-right-leg)]
+ [(symbol=? part 'left-leg) (draw-left-leg)])))
+
+
+;;Wish-list
+;;Once game is over, create a new button, reset the board
+;;Once game is over, you need to erase the body-part message or at least put the correct body part image (left-leg is never given)
+;;Once game is over, replace status-word with chosen-word
\ No newline at end of file
blob - /dev/null
blob + 72ddde8a65cea1e54506b600d4079d82e521cf74 (mode 644)
--- /dev/null
+++ 37.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.2|) (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")))))
+Data Definition
+
+A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s )
+ (s e a l i o n)))
+
+
+
+;;State Variables
+
+
+;;chosen-word : word
+
+(define chosen-word
blob - /dev/null
blob + 2251eef2ccbb35ad2111d57500aee69b2f7aa91c (mode 644)
--- /dev/null
+++ 37.2.7
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.2|) (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")))))
+;;Model
+
+;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s h)
+ (s e a l i o n)
+ (t u n a)
+ (d o l p h i n)
+ (w h a l e)
+ (k e l p)
+ (m a n a t e e)))
+
+;;The alphabet
+(define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+
+;;The number of words
+(define WORDS# (length WORDS))
+
+;;A body-part is one of the following symbols:
+(define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+;;State Variables
+
+;;chosen-word : word
+;;This word is the target word that the player needs to guess
+
+(define chosen-word (first WORDS))
+
+;;status-word : word
+;;This word represents the current status of the player's guesses
+
+(define status-word (first WORDS))
+
+;;body-parts-left : (listof body-parts)
+;;Indicates how many body-parts are left before the hangman is dead.
+
+(define body-parts-left PARTS)
+
+;;previous-guesses : word
+;;Keeps track of all previous guesses.
+
+(define previous-guesses empty)
+
+;make-status-word : word -> word
+;Given aword, creates an equally long word consisting only of the letter '_.
+
+(define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+;;hangman : -> void
+;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+
+(define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)))
+
+;;Initializes the state variables
+(hangman)
+
+;A response is either
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+;hangman-guess : letter -> response
+;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+(define (hangman-guess aletter)
+ (local ((define old-status status-word)
+ (define updated-status (begin (reveal-list! aletter)
+ status-word)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [(equal? old-status updated-status)
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]
+ [(equal? status-word chosen-word) "You won"]
+ [else (list "Good guess!" status-word)]))])))
+
+;reveal-word: word word letter -> word
+;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+(define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(equal? chosen-letter aletter) chosen-letter]
+ [else status-letter])))
+ (map reveal-letter chosen-word status-word)))
+
+;;reveal-list! : letter -> void
+;;effect: modifies status-word based on a comparison with chosen-word, status-word, and guess
+
+(define (reveal-list! guess)
+ (local ((define (reveal-one chosen-letter status-letter)
+ (cond
+ [(symbol=? chosen-letter guess) guess]
+ [else status-letter])))
+ (set! status-word (map reveal-one chosen-word status-word))))
+
+;contains : (listof X) X -> boolean
+;Determine if alox contains anx
+(define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+;Exercise 37.2.4. Formulate the four examples for hangman-guess as boolean-valued expressions that produce true if hangman-guess is correct. Develop an additional example for each case; turn these new examples into additional tests. Solution
+
+#|
+;Tests
+;test-hangman : letter word X -> boolean
+;Tests hangman-guess and returns true if the test is successful. Consumes guess (a letter), status (a word), partsleft (listof body-parts), and response (one of the four responses).
+(define (test-hangman guess status partsleft response)
+ (begin (set! chosen-word '(b a l l))
+ (set! status-word status)
+ (set! body-parts-left partsleft)
+ (equal? (hangman-guess guess) response)))
+
+
+
+(and (test-hangman 'l '(b _ _ _) '(arm leg) '("Good guess!" (b _ l l)))
+ (equal? status-word '(b _ l l)))
+(test-hangman 'a '(b _ l l) '(arm leg) "You won")
+(and (test-hangman 'l '(b _ l l) '(right-leg left-leg) '("Sorry" right-leg (b _ l l)))
+ (equal? body-parts-left '(left-leg)))
+(and (test-hangman 'l '(b _ l l) '(left-leg) '("The End" (b a l l)))
+ (equal? body-parts-left empty))
+|#
+
+;;View
+
+;word->string : word -> string
+;Given a word, convert it to a string.
+
+(define (word->string aword)
+ (foldr string-append "" (map (lambda (aletter) (symbol->string aletter)) aword)))
+
+;;GUI-items
+(define guess-message (make-message "Guess: "))
+(define guess-choice (make-choice (map (lambda (aletter) (symbol->string aletter)) LETTERS)))
+(define status-message (make-message "Status: "))
+(define status-word-message (make-message (word->string status-word)))
+(define result-message (make-message "Let's play hangman!"))
+(define body-part-message (make-message ""))
+
+;;Controller
+
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+
+(define (check-call-back event)
+ (local ((define response (hangman-guess (list-ref LETTERS (choice-index guess-choice)))))
+ (cond
+ [(string? response) (and (draw-message result-message response)
+ (draw-message status-word-message (word->string status-word)))]
+ [(= (length response) 2)
+ (and (draw-message result-message (first response))
+ (draw-message status-word-message (word->string (second response))))]
+ [(and (draw-message result-message (first response))
+ (draw-message body-part-message (symbol->string (second response)))
+ (draw-message status-word-message (word->string (third response)))
+ (draw-next-part (second response)))
+ (cond
+ [(empty? body-parts-left)
+ (begin (hangman)
+ (draw-message status-message "Chosen Word:"))]
+ [else true])])))
+
+(define check-button (make-button "Check" check-call-back))
+
+(create-window
+ (list (list guess-message guess-choice check-button)
+ (list status-message status-word-message)
+ (list result-message body-part-message)))
+
+(define CWIDTH 300)
+(define CHEIGHT 300)
+(start CWIDTH CHEIGHT)
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (local ((define XCENTER (/ CWIDTH 2))
+ (define COLORHEAD 'brown)
+ (define COLORBODY 'purple)
+ (define COLORARMS 'brown)
+ (define COLORLEGS 'red)
+ (define (draw-noose)
+ (and (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5)))))
+ (define (draw-head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD))
+ (define (draw-body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY))
+ (define (draw-right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS))
+ (define (draw-left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)))
+ (cond
+ [(symbol=? part 'noose) (draw-noose)]
+ [(symbol=? part 'head) (draw-head)]
+ [(symbol=? part 'body) (draw-body)]
+ [(symbol=? part 'right-arm) (draw-right-arm)]
+ [(symbol=? part 'left-arm) (draw-left-arm)]
+ [(symbol=? part 'right-leg) (draw-right-leg)]
+ [(symbol=? part 'left-leg) (draw-left-leg)])))
+
+
+;;Wish-list
+;;Once game is over, create a new button, reset the board
+;;Once game is over, you need to erase the body-part message or at least put the correct body part image (left-leg is never given)
+;;Once game is over, replace status-word with chosen-word
\ No newline at end of file
blob - /dev/null
blob + fda73a1417041954916a11f5b201e674e6543d26 (mode 644)
--- /dev/null
+++ 37.2.7~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.2|) (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")))))
+;;Model
+
+;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s h)
+ (s e a l i o n)
+ (t u n a)
+ (d o l p h i n)
+ (w h a l e)
+ (k e l p)
+ (m a n a t e e)))
+
+;;The alphabet
+(define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+
+;;The number of words
+(define WORDS# (length WORDS))
+
+;;A body-part is one of the following symbols:
+(define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+;;State Variables
+
+;;chosen-word : word
+;;This word is the target word that the player needs to guess
+
+(define chosen-word (first WORDS))
+
+;;status-word : word
+;;This word represents the current status of the player's guesses
+
+(define status-word (first WORDS))
+
+;;body-parts-left : (listof body-parts)
+;;Indicates how many body-parts are left before the hangman is dead.
+
+(define body-parts-left PARTS)
+
+;;previous-guesses : word
+;;Keeps track of all previous guesses.
+
+(define previous-guesses empty)
+
+;make-status-word : word -> word
+;Given aword, creates an equally long word consisting only of the letter '_.
+
+(define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+;;hangman : -> void
+;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+
+(define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)))
+
+;;Initializes the state variables
+(hangman)
+
+;A response is either
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+;hangman-guess : letter -> response
+;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+(define (hangman-guess aletter)
+ (local ((define updated-status (reveal-word chosen-word status-word aletter)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [(equal? status-word updated-status)
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]
+ [else (begin (set! status-word updated-status)
+ (cond
+ [(equal? status-word chosen-word) "You won"]
+ [else (list "Good guess!" status-word)]))]))])))
+
+;reveal-word: word word letter -> word
+;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+(define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(equal? chosen-letter aletter) chosen-letter]
+ [else status-letter])))
+ (map reveal-letter chosen-word status-word)))
+
+;contains : (listof X) X -> boolean
+;Determine if alox contains anx
+(define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+;Exercise 37.2.4. Formulate the four examples for hangman-guess as boolean-valued expressions that produce true if hangman-guess is correct. Develop an additional example for each case; turn these new examples into additional tests. Solution
+
+#|
+;Tests
+;test-hangman : letter word X -> boolean
+;Tests hangman-guess and returns true if the test is successful. Consumes guess (a letter), status (a word), partsleft (listof body-parts), and response (one of the four responses).
+(define (test-hangman guess status partsleft response)
+ (begin (set! chosen-word '(b a l l))
+ (set! status-word status)
+ (set! body-parts-left partsleft)
+ (equal? (hangman-guess guess) response)))
+
+
+
+(and (test-hangman 'l '(b _ _ _) '(arm leg) '("Good guess!" (b _ l l)))
+ (equal? status-word '(b _ l l)))
+(test-hangman 'a '(b _ l l) '(arm leg) "You won")
+(and (test-hangman 'l '(b _ l l) '(right-leg left-leg) '("Sorry" right-leg (b _ l l)))
+ (equal? body-parts-left '(left-leg)))
+(and (test-hangman 'l '(b _ l l) '(left-leg) '("The End" (b a l l)))
+ (equal? body-parts-left empty))
+|#
+
+;;View
+
+;word->string : word -> string
+;Given a word, convert it to a string.
+
+(define (word->string aword)
+ (foldr string-append "" (map (lambda (aletter) (symbol->string aletter)) aword)))
+
+;;GUI-items
+(define guess-message (make-message "Guess: "))
+(define guess-choice (make-choice (map (lambda (aletter) (symbol->string aletter)) LETTERS)))
+(define status-message (make-message "Status: "))
+(define status-word-message (make-message (word->string status-word)))
+(define result-message (make-message "Let's play hangman!"))
+(define body-part-message (make-message ""))
+
+;;Controller
+
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+
+(define (check-call-back event)
+ (local ((define response (hangman-guess (list-ref LETTERS (choice-index guess-choice)))))
+ (cond
+ [(string? response) (and (draw-message result-message response)
+ (draw-message status-word-message (word->string status-word)))]
+ [(= (length response) 2)
+ (and (draw-message result-message (first response))
+ (draw-message status-word-message (word->string (second response))))]
+ [(and (draw-message result-message (first response))
+ (draw-message body-part-message (symbol->string (second response)))
+ (draw-message status-word-message (word->string (third response)))
+ (draw-next-part (second response)))
+ (cond
+ [(empty? body-parts-left)
+ (begin (hangman)
+ (draw-message status-message "Chosen Word:"))]
+ [else true])])))
+
+(define check-button (make-button "Check" check-call-back))
+
+(create-window
+ (list (list guess-message guess-choice check-button)
+ (list status-message status-word-message)
+ (list result-message body-part-message)))
+
+(define CWIDTH 300)
+(define CHEIGHT 300)
+(start CWIDTH CHEIGHT)
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (local ((define XCENTER (/ CWIDTH 2))
+ (define COLORHEAD 'brown)
+ (define COLORBODY 'purple)
+ (define COLORARMS 'brown)
+ (define COLORLEGS 'red)
+ (define (draw-noose)
+ (and (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5)))))
+ (define (draw-head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD))
+ (define (draw-body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY))
+ (define (draw-right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS))
+ (define (draw-left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)))
+ (cond
+ [(symbol=? part 'noose) (draw-noose)]
+ [(symbol=? part 'head) (draw-head)]
+ [(symbol=? part 'body) (draw-body)]
+ [(symbol=? part 'right-arm) (draw-right-arm)]
+ [(symbol=? part 'left-arm) (draw-left-arm)]
+ [(symbol=? part 'right-leg) (draw-right-leg)]
+ [(symbol=? part 'left-leg) (draw-left-leg)])))
+
+
+;;Wish-list
+;;Once game is over, create a new button, reset the board
+;;Once game is over, you need to erase the body-part message or at least put the correct body part image (left-leg is never given)
+;;Once game is over, replace status-word with chosen-word
\ No newline at end of file
blob - /dev/null
blob + a4668374d43ef53f4dfa41dc8915aa3f8bd5caec (mode 644)
--- /dev/null
+++ 37.3.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.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")))))
+;;Model
+
+;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s h)
+ (s e a l i o n)
+ (t u n a)
+ (d o l p h i n)
+ (w h a l e)
+ (k e l p)
+ (m a n a t e e)))
+
+;;The alphabet
+(define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+
+;;The number of words
+(define WORDS# (length WORDS))
+
+;;A body-part is one of the following symbols:
+(define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+;;State Variables
+
+;;chosen-word : word
+;;This word is the target word that the player needs to guess
+
+(define chosen-word (first WORDS))
+
+;;status-word : word
+;;This word represents the current status of the player's guesses
+
+(define status-word (first WORDS))
+
+;;body-parts-left : (listof body-parts)
+;;Indicates how many body-parts are left before the hangman is dead.
+
+(define body-parts-left PARTS)
+
+;;previous-guesses : word
+;;Keeps track of all previous guesses.
+
+(define previous-guesses empty)
+
+;;new-knowledge : boolean
+;;Keeps track of whether or not the guessed letter adds new-knowledge.
+
+(define new-knowledge false)
+
+;;letters-remaining : number
+;;Keeps track of the letters that still need to be uncovered.
+
+(define letters-remaining (length chosen-word))
+
+;make-status-word : word -> word
+;Given aword, creates an equally long word consisting only of the letter '_.
+
+(define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+;;hangman : -> void
+;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+
+(define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)
+ (set! previous-guesses empty)
+ (set! new-knowledge false)
+ (set! letters-remaining (length chosen-word))))
+
+;;Initializes the state variables
+(hangman)
+
+;A response is either
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+;hangman-guess : letter -> response
+;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+(define (hangman-guess aletter)
+ (local ((define updated-status (reveal-word chosen-word status-word aletter)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [new-knowledge (begin (set! status-word updated-status)
+ (set! letters-remaining (sub1 letters-remaining))
+ (cond
+ [(zero? letters-remaining) "You won"]
+ [else (list "Good guess!" status-word)]))]
+ [else
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]))])))
+
+;reveal-word: word word letter -> word
+;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+(define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(and (symbol=? chosen-letter aletter)
+ (symbol=? status-letter '_))
+ (begin (set! new-knowledge true)
+ aletter)]
+ [else status-letter])))
+ (begin (set! new-knowledge false)
+ (map reveal-letter chosen-word status-word))))
+
+;contains : (listof X) X -> boolean
+;Determine if alox contains anx
+(define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+;Exercise 37.2.4. Formulate the four examples for hangman-guess as boolean-valued expressions that produce true if hangman-guess is correct. Develop an additional example for each case; turn these new examples into additional tests. Solution
+
+#|
+;Tests
+;test-hangman : letter word X -> boolean
+;Tests hangman-guess and returns true if the test is successful. Consumes guess (a letter), status (a word), partsleft (listof body-parts), and response (one of the four responses).
+(define (test-hangman guess status partsleft response)
+ (begin (set! chosen-word '(b a l l))
+ (set! status-word status)
+ (set! body-parts-left partsleft)
+ (equal? (hangman-guess guess) response)))
+
+
+
+(and (test-hangman 'l '(b _ _ _) '(arm leg) '("Good guess!" (b _ l l)))
+ (equal? status-word '(b _ l l)))
+(test-hangman 'a '(b _ l l) '(arm leg) "You won")
+(and (test-hangman 'l '(b _ l l) '(right-leg left-leg) '("Sorry" right-leg (b _ l l)))
+ (equal? body-parts-left '(left-leg)))
+(and (test-hangman 'l '(b _ l l) '(left-leg) '("The End" (b a l l)))
+ (equal? body-parts-left empty))
+|#
+
+;;View
+
+;word->string : word -> string
+;Given a word, convert it to a string.
+
+(define (word->string aword)
+ (foldr string-append "" (map (lambda (aletter) (symbol->string aletter)) aword)))
+
+;;GUI-items
+(define guess-message (make-message "Guess: "))
+(define guess-choice (make-choice (map (lambda (aletter) (symbol->string aletter)) LETTERS)))
+(define status-message (make-message "Status: "))
+(define status-word-message (make-message (word->string status-word)))
+(define result-message (make-message "Let's play hangman!"))
+(define body-part-message (make-message ""))
+
+;;Controller
+
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+
+(define (check-call-back event)
+ (local ((define response (hangman-guess (list-ref LETTERS (choice-index guess-choice)))))
+ (cond
+ [(string? response) (and (draw-message result-message response)
+ (draw-message status-word-message (word->string status-word)))]
+ [(= (length response) 2)
+ (and (draw-message result-message (first response))
+ (draw-message status-word-message (word->string (second response))))]
+ [(and (draw-message result-message (first response))
+ (draw-message body-part-message (symbol->string (second response)))
+ (draw-message status-word-message (word->string (third response)))
+ (draw-next-part (second response)))
+ (cond
+ [(empty? body-parts-left)
+ (begin (hangman)
+ (draw-message status-message "Chosen Word:"))]
+ [else true])])))
+
+(define check-button (make-button "Check" check-call-back))
+
+(create-window
+ (list (list guess-message guess-choice check-button)
+ (list status-message status-word-message)
+ (list result-message body-part-message)))
+
+(define CWIDTH 300)
+(define CHEIGHT 300)
+(start CWIDTH CHEIGHT)
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (local ((define XCENTER (/ CWIDTH 2))
+ (define COLORHEAD 'brown)
+ (define COLORBODY 'purple)
+ (define COLORARMS 'brown)
+ (define COLORLEGS 'red)
+ (define (draw-noose)
+ (and (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5)))))
+ (define (draw-head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD))
+ (define (draw-body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY))
+ (define (draw-right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS))
+ (define (draw-left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)))
+ (cond
+ [(symbol=? part 'noose) (draw-noose)]
+ [(symbol=? part 'head) (draw-head)]
+ [(symbol=? part 'body) (draw-body)]
+ [(symbol=? part 'right-arm) (draw-right-arm)]
+ [(symbol=? part 'left-arm) (draw-left-arm)]
+ [(symbol=? part 'right-leg) (draw-right-leg)]
+ [(symbol=? part 'left-leg) (draw-left-leg)])))
+
+#|
+;Tests reveal-word given cw, sw, aletter, expected, and new?.
+
+(define (test-reveal-word cw sw aletter expected new?)
+ (begin (set! chosen-word cw)
+ (set! status-word sw)
+ (and (equal? (reveal-word cw sw aletter) expected)
+ (equal? new? new-knowledge))))
+
+;If status-word is (list 'b '_ 'l 'l) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'a)
+;produces (list 'b 'a 'l 'l) and new-knowledge is true.
+
+(test-reveal-word '(b a l l) '(b _ l l) 'a '(b a l l) true)
+
+;If status-word is (list 'b '_ '_ '_) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'x)
+;produces (list 'b '_ '_ '_) and new-knowledge is false.
+
+(test-reveal-word '(b a l l) '(b _ _ _) 'x '(b _ _ _) false)
+
+;If status-word is (list 'b '_ '_ '_) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'l)
+;produces (list 'b '_ 'l 'l) and new-knowledge is true.
+
+(test-reveal-word '(b a l l) '(b _ _ _) 'l '(b _ l l) true)
+
+;Finally, if status-word is (list 'b '_ 'l 'l) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'l)
+;produces (list 'b '_ 'l 'l) and new-knowledge is false.
+
+(test-reveal-word '(b a l l) '(b _ l l) 'l '(b _ l l) false)
+
+|#
\ No newline at end of file
blob - /dev/null
blob + 50d89f767de79c015e0abbb7a86543434e7b0908 (mode 644)
--- /dev/null
+++ 37.3.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.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")))))
+;;Model
+
+;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s h)
+ (s e a l i o n)
+ (t u n a)
+ (d o l p h i n)
+ (w h a l e)
+ (k e l p)
+ (m a n a t e e)))
+
+;;The alphabet
+(define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+
+;;The number of words
+(define WORDS# (length WORDS))
+
+;;A body-part is one of the following symbols:
+(define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+;;State Variables
+
+;;chosen-word : word
+;;This word is the target word that the player needs to guess
+
+(define chosen-word (first WORDS))
+
+;;status-word : word
+;;This word represents the current status of the player's guesses
+
+(define status-word (first WORDS))
+
+;;body-parts-left : (listof body-parts)
+;;Indicates how many body-parts are left before the hangman is dead.
+
+(define body-parts-left PARTS)
+
+;;previous-guesses : word
+;;Keeps track of all previous guesses.
+
+(define previous-guesses empty)
+
+;make-status-word : word -> word
+;Given aword, creates an equally long word consisting only of the letter '_.
+
+(define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+;;hangman : -> void
+;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+
+(define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)))
+
+;;Initializes the state variables
+(hangman)
+
+;A response is either
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+;hangman-guess : letter -> response
+;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+(define (hangman-guess aletter)
+ (local ((define updated-status (reveal-word chosen-word status-word aletter)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [(equal? status-word updated-status)
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]
+ [else (begin (set! status-word updated-status)
+ (cond
+ [(equal? status-word chosen-word) "You won"]
+ [else (list "Good guess!" status-word)]))]))])))
+
+;reveal-word: word word letter -> word
+;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+(define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(equal? chosen-letter aletter) chosen-letter]
+ [else status-letter])))
+ (map reveal-letter chosen-word status-word)))
+
+;contains : (listof X) X -> boolean
+;Determine if alox contains anx
+(define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+;Exercise 37.2.4. Formulate the four examples for hangman-guess as boolean-valued expressions that produce true if hangman-guess is correct. Develop an additional example for each case; turn these new examples into additional tests. Solution
+
+#|
+;Tests
+;test-hangman : letter word X -> boolean
+;Tests hangman-guess and returns true if the test is successful. Consumes guess (a letter), status (a word), partsleft (listof body-parts), and response (one of the four responses).
+(define (test-hangman guess status partsleft response)
+ (begin (set! chosen-word '(b a l l))
+ (set! status-word status)
+ (set! body-parts-left partsleft)
+ (equal? (hangman-guess guess) response)))
+
+
+
+(and (test-hangman 'l '(b _ _ _) '(arm leg) '("Good guess!" (b _ l l)))
+ (equal? status-word '(b _ l l)))
+(test-hangman 'a '(b _ l l) '(arm leg) "You won")
+(and (test-hangman 'l '(b _ l l) '(right-leg left-leg) '("Sorry" right-leg (b _ l l)))
+ (equal? body-parts-left '(left-leg)))
+(and (test-hangman 'l '(b _ l l) '(left-leg) '("The End" (b a l l)))
+ (equal? body-parts-left empty))
+|#
+
+;;View
+
+;word->string : word -> string
+;Given a word, convert it to a string.
+
+(define (word->string aword)
+ (foldr string-append "" (map (lambda (aletter) (symbol->string aletter)) aword)))
+
+;;GUI-items
+(define guess-message (make-message "Guess: "))
+(define guess-choice (make-choice (map (lambda (aletter) (symbol->string aletter)) LETTERS)))
+(define status-message (make-message "Status: "))
+(define status-word-message (make-message (word->string status-word)))
+(define result-message (make-message "Let's play hangman!"))
+(define body-part-message (make-message ""))
+
+;;Controller
+
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+
+(define (check-call-back event)
+ (local ((define response (hangman-guess (list-ref LETTERS (choice-index guess-choice)))))
+ (cond
+ [(string? response) (and (draw-message result-message response)
+ (draw-message status-word-message (word->string status-word)))]
+ [(= (length response) 2)
+ (and (draw-message result-message (first response))
+ (draw-message status-word-message (word->string (second response))))]
+ [(and (draw-message result-message (first response))
+ (draw-message body-part-message (symbol->string (second response)))
+ (draw-message status-word-message (word->string (third response)))
+ (draw-next-part (second response)))
+ (cond
+ [(empty? body-parts-left)
+ (begin (hangman)
+ (draw-message status-message "Chosen Word:"))]
+ [else true])])))
+
+(define check-button (make-button "Check" check-call-back))
+
+(create-window
+ (list (list guess-message guess-choice check-button)
+ (list status-message status-word-message)
+ (list result-message body-part-message)))
+
+(define CWIDTH 300)
+(define CHEIGHT 300)
+(start CWIDTH CHEIGHT)
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (local ((define XCENTER (/ CWIDTH 2))
+ (define COLORHEAD 'brown)
+ (define COLORBODY 'purple)
+ (define COLORARMS 'brown)
+ (define COLORLEGS 'red)
+ (define (draw-noose)
+ (and (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5)))))
+ (define (draw-head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD))
+ (define (draw-body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY))
+ (define (draw-right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS))
+ (define (draw-left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)))
+ (cond
+ [(symbol=? part 'noose) (draw-noose)]
+ [(symbol=? part 'head) (draw-head)]
+ [(symbol=? part 'body) (draw-body)]
+ [(symbol=? part 'right-arm) (draw-right-arm)]
+ [(symbol=? part 'left-arm) (draw-left-arm)]
+ [(symbol=? part 'right-leg) (draw-right-leg)]
+ [(symbol=? part 'left-leg) (draw-left-leg)])))
+
+
+;;Wish-list
+;;Once game is over, create a new button, reset the board
+;;Once game is over, you need to erase the body-part message or at least put the correct body part image (left-leg is never given)
+;;Once game is over, replace status-word with chosen-word
\ No newline at end of file
blob - /dev/null
blob + f76d2756dd6b7367d93e94b3f1265143a5aa8455 (mode 644)
--- /dev/null
+++ 37.3.5
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.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")))))
+;A node is a symbol.
+;
+;A pair is a list
+;(cons n1 (cons n2)), ie, (list n1 n2)
+;where n1 and n2 are symbols representing nodes.
+;
+;A simple-graph is a (listof pairs).
+
+;;State Variables
+
+;;seen-before : (listof nodes)
+;;Keeps track of all nodes that have been accessed in the past.
+
+(define seen-before empty)
+
+;route-exists? : node node simple-graph -> boolean
+;Determines if there exists a route from orig to dest given the simple-graph sg.
+
+;route-exists?-aux : node (listof nodes) -> boolean
+;Determine if there exists a route from orig to dest given the simple-graph sg. accu-seen represents nodes that have been visited before. If a node is visited twice and a route is not determined, return false.
+
+(define (route-exists? orig dest sg)
+ (local ((define (route-exists?-aux orig dest sg)
+ (cond
+ [(symbol=? orig dest) true]
+ [(contains orig seen-before) false]
+ [else (begin (set! seen-before (cons orig seen-before))
+ (route-exists?-aux (neighbor orig sg) dest sg))])))
+ (begin (set! seen-before empty)
+ (route-exists?-aux orig dest sg))))
+
+;neighbor : node simple-graph -> node
+;Given anode, find its neighbor in simple-graph.
+
+(define (neighbor anode sg)
+ (cond
+ [(empty? sg) (error 'neighbor "node does not exist")]
+ [(symbol=? (first (first sg)) anode) (second (first sg))]
+ [else (neighbor anode (rest sg))]))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+
+(define (contains x alox)
+ (ormap (lambda (item) (equal? x item)) alox))
+#|
+ Old Body
+ (cond
+ [(empty? alox) false]
+ [(equal? x (first alox)) true]
+ [else (contains x (rest alox))]))
+|#
+(define SimpleG
+ '((A B)
+ (B C)
+ (C E)
+ (D E)
+ (E B)
+ (F F)))
+
+(not (route-exists? 'A 'D SimpleG))
+(route-exists? 'D 'B SimpleG)
+(not (route-exists? 'F 'D SimpleG))
+(route-exists? 'D 'C SimpleG)
\ No newline at end of file
blob - /dev/null
blob + 9949b984f280007594a273bfed4bb8de621b9309 (mode 644)
--- /dev/null
+++ 37.3.5~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.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")))))
+;A node is a symbol.
+;
+;A pair is a list
+;(cons n1 (cons n2)), ie, (list n1 n2)
+;where n1 and n2 are symbols representing nodes.
+;
+;A simple-graph is a (listof pairs).
+
+;route-exists? : node node simple-graph -> boolean
+;Determines if there exists a route from orig to dest given the simple-graph sg.
+
+;route-exists?-aux : node (listof nodes) -> boolean
+;Determine if there exists a route from orig to dest given the simple-graph sg. accu-seen represents nodes that have been visited before. If a node is visited twice and a route is not determined, return false.
+
+(define (route-exists? orig dest sg)
+ (local ((define (route-exists?-aux orig accu-seen)
+ (cond
+ [(symbol=? orig dest) true]
+ [(contains orig accu-seen) false]
+ [else (route-exists?-aux (neighbor orig sg) (cons orig accu-seen))])))
+ (route-exists?-aux orig empty)))
+
+;neighbor : node simple-graph -> node
+;Given anode, find its neighbor in simple-graph.
+
+(define (neighbor anode sg)
+ (cond
+ [(empty? sg) (error 'neighbor "node does not exist")]
+ [(symbol=? (first (first sg)) anode) (second (first sg))]
+ [else (neighbor anode (rest sg))]))
+
+;contains : X (listof X) -> boolean
+;Determines if alox contains x.
+
+(define (contains x alox)
+ (ormap (lambda (item) (equal? x item)) alox))
+#|
+ Old Body
+ (cond
+ [(empty? alox) false]
+ [(equal? x (first alox)) true]
+ [else (contains x (rest alox))]))
+|#
+(define SimpleG
+ '((A B)
+ (B C)
+ (C E)
+ (D E)
+ (E B)
+ (F F)))
+
+(not (route-exists? 'A 'D SimpleG))
+(route-exists? 'D 'B SimpleG)
+(not (route-exists? 'F 'D SimpleG))
+(route-exists? 'D 'C SimpleG)
\ No newline at end of file
blob - /dev/null
blob + 3f470111bbabb11f33ec4d3b51dd76b41f1ea004 (mode 644)
--- /dev/null
+++ 37.3.6
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.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")))))
+;A directory (dir) is a structure
+;(make-dir name content size systems) where name, systems are symbols,
+;size is a number, and content is a list-of-files-and-directories (LOFD).
+;
+;A list-of-files-and-directories (LOFD) is either
+;1. empty,
+;2. (cons file lofd)
+;3. (cons dir lofd),
+;where file is a symbol, dir is a directory,
+;and lofd is a LOFD (list-of-files-and-directories).
+
+(define-struct dir (name content size systems))
+
+;;State variables
+
+;;how-many-directories : N
+;;The number of subdirectories encountered
+(define how-many-directories 0)
+
+;Template
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lofd (dir-content a-dir)) ...))
+;
+;
+;fun-for-lofd : lofd -> ???
+;(define (fun-for-lofd a-lofd)
+; (cond
+; [(empty? a-lofd) ...]
+; [(symbol? (first a-lofd)) ... (first a-lofd) ...
+; ... (fun-for-lofd (rest a-lofd)) ...]
+; [(dir? (first a-lofd)) ... (fun-for-dir (first a-lofd)) ...
+; ... (fun-for-lofd (rest a-lofd)) ...]))
+
+;Examples:
+(define Code (make-dir 'Code '(hang draw) 5 'ReadOnly))
+(define Docs (make-dir 'Docs '(read!) 5 'ReadWrite))
+(define Libs (make-dir 'Libs (list Code Docs) 5 'Executable))
+(define Text (make-dir 'Text '(part1 part2 part3) 5 'ReadOnly))
+(define TS (make-dir 'TS (list Text Libs 'read!) 5 'None))
+
+;;dir-listing : dir -> lofd
+;;Consumes a directory and produces a list of all file names in the directory and all of its subdirectories
+;;Effect: Count the number of subdirectories accessed and store it in how-many-directories.
+
+;;list-all-filenames : lofd -> (listof symbol)
+;;Lists the names of all the files in the directory.
+;;Effect: everytime a directory is accessed, add one more to how-many-directories.
+
+(define (dir-listing adir)
+ (local ((define (list-all-filenames alofd)
+ (cond
+ [(empty? alofd) empty]
+ [(symbol? (first alofd)) (cons (first alofd) (list-all-filenames (rest alofd)))]
+ [else (begin (set! how-many-directories (add1 how-many-directories))
+ (append (list-all-filenames (dir-content (first alofd)))
+ (list-all-filenames (rest alofd))))])))
+ (begin (set! how-many-directories 0)
+ (list-all-filenames (dir-content adir)))))
+
+
+
+(dir-listing TS)
blob - /dev/null
blob + bcc7e11ec1aa23079c8a7907458c3e250481196a (mode 644)
--- /dev/null
+++ 37.3.6~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-intermediate-reader.ss" "lang")((modname |37.3|) (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")))))
+;A directory (dir) is a structure
+;(make-dir name content size systems) where name, systems are symbols,
+;size is a number, and content is a list-of-files-and-directories (LOFD).
+;
+;A list-of-files-and-directories (LOFD) is either
+;1. empty,
+;2. (cons file lofd)
+;3. (cons dir lofd),
+;where file is a symbol, dir is a directory,
+;and lofd is a LOFD (list-of-files-and-directories).
+
+(define-struct dir (name content size systems))
+
+;Template
+;fun-for-dir : dir -> ???
+;(define (fun-for-dir a-dir)
+; (... (dir-name a-dir) ...
+; ... (fun-for-lofd (dir-content a-dir)) ...))
+;
+;
+;fun-for-lofd : lofd -> ???
+;(define (fun-for-lofd a-lofd)
+; (cond
+; [(empty? a-lofd) ...]
+; [(symbol? (first a-lofd)) ... (first a-lofd) ...
+; ... (fun-for-lofd (rest a-lofd)) ...]
+; [(dir? (first a-lofd)) ... (fun-for-dir (first a-lofd)) ...
+; ... (fun-for-lofd (rest a-lofd)) ...]))
+
+;Examples:
+(define Code (make-dir 'Code '(hang draw) 5 'ReadOnly))
+(define Docs (make-dir 'Docs '(read!) 5 'ReadWrite))
+(define Libs (make-dir 'Libs (list Code Docs) 5 'Executable))
+(define Text (make-dir 'Text '(part1 part2 part3) 5 'ReadOnly))
+(define TS (make-dir 'TS (list Text Libs 'read!) 5 'None))
+
+;how-many : dir -> number
+;Given a-dir, determine the number of
+;files in the dir tree.
+
+(define (how-many a-dir)
+ (how-many-lofd (dir-content a-dir)))
+
+
+;how-many-lofd : lofd -> number
+;Given a-lofd, determine the number of files
+;in the lofd (search within subdirectories as well).
+
+(define (how-many-lofd a-lofd)
+ (cond
+ [(empty? a-lofd) 0]
+ [(symbol? (first a-lofd)) (+ 1
+ (how-many-lofd (rest a-lofd)))]
+ [(dir? (first a-lofd)) (+ (how-many (first a-lofd))
+ (how-many-lofd (rest a-lofd)))]))
blob - /dev/null
blob + 9b58ccfb27ce4597df7c391bd887f59db004f4b3 (mode 644)
--- /dev/null
+++ 37.4.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.4|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp")))))
+;Data Definition
+;A list-of-digits is either
+;1. an empty list or
+;2. (cons n lod) where n is a number and lod is a list-of-digits.
+;
+;Contract, Purpose, Header
+;convert : list-of-digits -> number
+;Converts a-list to a number where the first digit in a-list is
+;the least significant digit in the number output, the second
+;digit the second least, and so forth.
+;
+;Template
+;(define (convert a-list)
+; (cond
+; [(empty?) ...]
+; [(cons?)
+; (cond
+; [(and
+; (number? (first a-list))
+; ())
+; ... (first a-list) (convert (rest a-list)) ...]
+; [(number? (first a-list)) ...]
+; [else (error '... "...")]
+; [else ...])]))
+
+;;State Variables
+;;guess# : N
+;;Indicates the number of guesses taken.
+
+(define guess# 0)
+
+(define (convert a-list)
+ (cond
+ [(empty? a-list) 0]
+ [(cons? a-list)
+ (cond
+ [(and
+ (number? (first a-list))
+ (>= (first a-list) 0)
+ (<= (first a-list) 9))
+ (+ (first a-list) (* 10 (convert (rest a-list))))]
+ [else (error 'convert "expected arg: list (of digits)")])]
+ [else (error 'convert "expected arg: list (of digits)")]))
+
+;Contract, Purpose, Header
+;check-guess-for-list : list-of-digits number -> symbol
+;Consumes a-list, which is a list-of-digits and converts it
+;to a number according to the function convert. It compares this
+;to chosen, which is a number and returns the corresponding symbol
+;'TooSmall, 'Perfect, or 'TooLarge
+;
+;Template
+
+(define (check-guess-for-list a-list chosen)
+ (local ((define (check-guess-for-list-aux a-list chosen)
+ (cond
+ [(= (convert a-list) chosen) 'Perfect]
+ [(> (convert a-list) chosen) 'TooLarge]
+ [(< (convert a-list) chosen) 'TooSmall])))
+ (begin (set! guess# (add1 guess#))
+ (check-guess-for-list-aux a-list chosen))))
+
+(guess-with-gui-list 1 check-guess-for-list)
\ No newline at end of file
blob - /dev/null
blob + 38073f4a0c7d0eb2e090f73bb44c45c065c3ec1b (mode 644)
--- /dev/null
+++ 37.4.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |37.4|) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
+;Data Definition
+;A list-of-digits is either
+;1. an empty list or
+;2. (cons n lod) where n is a number and lod is a list-of-digits.
+;
+;Contract, Purpose, Header
+;convert : list-of-digits -> number
+;Converts a-list to a number where the first digit in a-list is
+;the least significant digit in the number output, the second
+;digit the second least, and so forth.
+;
+;Template
+;(define (convert a-list)
+; (cond
+; [(empty?) ...]
+; [(cons?)
+; (cond
+; [(and
+; (number? (first a-list))
+; ())
+; ... (first a-list) (convert (rest a-list)) ...]
+; [(number? (first a-list)) ...]
+; [else (error '... "...")]
+; [else ...])]))
+
+(define (convert a-list)
+ (cond
+ [(empty? a-list) 0]
+ [(cons? a-list)
+ (cond
+ [(and
+ (number? (first a-list))
+ (>= (first a-list) 0)
+ (<= (first a-list) 9))
+ (+ (first a-list) (* 10 (convert (rest a-list))))]
+ [else (error 'convert "expected arg: list (of digits)")])]
+ [else (error 'convert "expected arg: list (of digits)")]))
+
+;Contract, Purpose, Header
+;check-guess-for-list : list-of-digits number -> symbol
+;Consumes a-list, which is a list-of-digits and converts it
+;to a number according to the function convert. It compares this
+;to chosen, which is a number and returns the corresponding symbol
+;'TooSmall, 'Perfect, or 'TooLarge
+;
+;Template
+
+(define (check-guess-for-list a-list chosen)
+ (cond
+ [(= (convert a-list) chosen) 'Perfect]
+ [(> (convert a-list) chosen) 'TooLarge]
+ [(< (convert a-list) chosen) 'TooSmall]))
blob - /dev/null
blob + 4cd5bfdfb1e0dee596363efa0fccf9c2b47bec83 (mode 644)
--- /dev/null
+++ 37.4.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.4|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+;;Model
+
+;;State Variables
+
+;;queue : (listof strings)
+;;Lists all the tasks which need to be done.
+
+(define queue empty)
+
+;;queue-index : N
+;;The current index of the queue.
+
+(define queue-index 0)
+
+;enter : string -> void
+;Adds atask to the end of queue.
+
+(define (enter atask)
+ (set! queue (append queue
+ (list atask))))
+
+;next : -> string
+;Returns the next task in the queue based on queue-index. If the end of the queue is reached, return the current task in the queue specified by queue-index. If the queue is empty, return 'NoneLeft.
+
+(define (next)
+ (cond
+ [(empty? queue) 'NoneLeft]
+ [(= (length queue) (add1 queue-index)) (list-ref queue queue-index)]
+ [else (begin (set! queue-index (add1 queue-index))
+ (list-ref queue queue-index))]))
+
+;remove : -> void
+;Removes the first task in the queue. If there are no tasks left to be removed, do nothing.
+
+(define (remove)
+ (cond
+ [(empty? queue) (void)]
+ [else (set! queue (rest queue))]))
+
+;count : -> N
+;Counts the number of items in the queue.
+
+(define (count)
+ (length queue))
+
+;;View
+
+;;GUI-items, text and messages
+(define task-message (make-message "Welcome to the Task Manager"))
+(define task-number-message (make-message "2000"))
+(define input-text (make-text "Task: "))
+
+;;Controller
+
+(define (enter-callback event)
+ (cond
+ [(equal? (text-contents input-text) "") true]
+ [else (begin (enter (text-contents input-text))
+ (draw-queue-number)
+ (cond
+ [(= (length queue) 1) (draw-first-task)]
+ [else true]))]))
+
+;;draw-queue-number : -> true
+;;Draws the queue number and returns true.
+(define (draw-queue-number)
+ (draw-message task-number-message (number->string (length queue))))
+
+;draw-first-task : -> true
+;Draws the first task in the queue and returns true.
+(define (draw-first-task)
+ (draw-message task-message (first queue)))
+
+(define (next-callback event)
+ (cond
+ [(>= (length queue) 2)
+ (begin (remove)
+ (draw-queue-number)
+ (draw-first-task))]
+ [(= (length queue) 1)
+ (begin
+ (remove)
+ (draw-queue-number)
+ (draw-message task-message "No more tasks left!"))]
+ [(= (length queue) 0) true]))
+
+(define (quit-callback event)
+ (hide-window task-manager-win))
+
+(define enter-button (make-button "Enter" enter-callback))
+(define next-button (make-button "Next" next-callback))
+(define quit-button (make-button "Quit" quit-callback))
+
+(define task-manager-win
+ (create-window (list (list task-message task-number-message)
+ (list input-text enter-button)
+ (list next-button quit-button))))
+
+;;Tests
+#|
+(begin (enter "hi")
+ (enter "joe")
+ (enter "it's")
+ (enter "me")
+ (and (equal? (list "hi" "joe" "it's" "me") queue)
+ (begin (next)
+ (equal? (next) "it's")
+ (remove)
+ (and (= 3 (count))
+ (equal? queue (list "joe" "it's" "me"))))))
+|#
+
+;;Wish-list
+
+;;Initialize queue, queue-index
\ No newline at end of file
blob - /dev/null
blob + 3b7955728def73ad0bbe18bab5171f726b7a74dc (mode 644)
--- /dev/null
+++ 37.4.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.4|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp")))))
blob - /dev/null
blob + c68ccde1f21220bc5dab3a3c280e69bc443855e5 (mode 644)
--- /dev/null
+++ 37.4.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |37.4|) (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")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+;Template
+;fun-for-losh : list-of-shapes -> ???
+;Consumes a list-of-shapes.
+;
+;(define (fun-for-losh alosh)
+; (cond
+; [(empty? alosh) ...]
+; [(circle? (first alosh)) ... (first alosh) (fun-for-losh (rest alosh))]
+; [(rectangle? (first alosh)) ...(first alosh) (fun-for-losh (rest alosh))]
+; [else ...]))
+
+;draw-losh : list-of-shapes -> boolean
+;Consumes alosh and draws the shapes on the canvas,
+;returning true. If drawing fails, it returns false.
+
+(define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+;draw-a-circle : circle -> boolean?
+;Draws a circle given a-circle (struct circle).
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+; draw-a-rectangle : rectangle -> boolean
+; Returns true after drawing, consumes a-rect.
+
+(define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;translate-losh : list-of-shapes number -> list-of-shapes
+;Given alosh, returns a list-of-shapes that have translated
+;delta pixels in the x direction. This function
+;does not affect the canvas.
+
+(define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+;clear-losh : list-of-shapes -> boolean
+;Clears shapes corresponding to entries in alosh
+;and returns true. Does so by calling clear-a-rectangle
+;and clear-a-circle.
+
+(define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+; clear-a-circle : circle -> boolean
+; Clears a circle given a-circle, returns true if
+; evaluation completes successfully, false otherwise.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+; clear-a-rectangle : rectangle -> boolean
+; Clears rectangle specified by a-rect and returns true
+; if evaluation suceeds, false otherwise.
+
+(define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+;Data Definition
+;
+;A picture is a list-of-shapes?, I think.
+;
+;draw-and-clear-picture : picture -> boolean
+;Draws alosh, sleeps for a while, then clears alosh.
+;!!!CHANGE!!! Now it clears, sleeps for a while,
+;then draws alosh.
+
+(define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+; (sleep-for-a-while 2)
+ (clear-losh alosh)))
+;
+;move-picture : number picture -> picture
+;Draws a picture delta pixels to the right, sleeps for a while,
+;clears the picture, and then returns the translated picture.
+
+(define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false]))
+
+(start 500 100)
+
+(control-left-right FACE 100 move-picture draw-losh)
\ No newline at end of file
blob - /dev/null
blob + c68ccde1f21220bc5dab3a3c280e69bc443855e5 (mode 644)
--- /dev/null
+++ 37.4.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname |37.4|) (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")))))
+;Data Definitions
+;
+;A circle is a structure
+;(make-circle p n s) where p is a posn,
+;n is a number, and s is a symbol.
+
+(define-struct circle (center radius color))
+;
+;A rectangle is a structure
+;(make-rectangle p m n s) where p is a posn,
+;m and n are numbers, and s is a symbol.
+
+(define-struct rectangle (upper-left width height color))
+
+;A shape is either
+;1. a circle or
+;2. a rectangle.
+;
+;A list-of-shapes is either
+;1. an empty list or
+;2. (cons s los) where s is a shape and
+;los is a list-of-shapes.
+
+(define FACE (cons
+ (make-circle (make-posn 50 50)
+ 40
+ 'red)
+ (cons
+ (make-rectangle (make-posn 30 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 65 20)
+ 5
+ 5
+ 'blue)
+ (cons
+ (make-rectangle (make-posn 40 75)
+ 20
+ 10
+ 'red)
+ (cons
+ (make-rectangle (make-posn 45 35)
+ 10
+ 30
+ 'blue) empty))))))
+
+;Template
+;fun-for-losh : list-of-shapes -> ???
+;Consumes a list-of-shapes.
+;
+;(define (fun-for-losh alosh)
+; (cond
+; [(empty? alosh) ...]
+; [(circle? (first alosh)) ... (first alosh) (fun-for-losh (rest alosh))]
+; [(rectangle? (first alosh)) ...(first alosh) (fun-for-losh (rest alosh))]
+; [else ...]))
+
+;draw-losh : list-of-shapes -> boolean
+;Consumes alosh and draws the shapes on the canvas,
+;returning true. If drawing fails, it returns false.
+
+(define (draw-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (draw-a-circle (first alosh))
+ (draw-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (draw-a-rectangle (first alosh))
+ (draw-losh (rest alosh)))]
+ [else false]))
+
+;draw-a-circle : circle -> boolean?
+;Draws a circle given a-circle (struct circle).
+
+(define (draw-a-circle a-circle)
+ (draw-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)
+ (circle-color a-circle)))
+
+; draw-a-rectangle : rectangle -> boolean
+; Returns true after drawing, consumes a-rect.
+
+(define (draw-a-rectangle a-rect)
+ (draw-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)
+ (rectangle-color a-rect)))
+
+;translate-losh : list-of-shapes number -> list-of-shapes
+;Given alosh, returns a list-of-shapes that have translated
+;delta pixels in the x direction. This function
+;does not affect the canvas.
+
+(define (translate-losh alosh delta)
+ (cond
+ [(empty? alosh) empty]
+ [(circle? (first alosh))
+ (cons
+ (make-circle
+ (make-posn (+ (posn-x (circle-center (first alosh)))
+ delta)
+ (posn-y (circle-center (first alosh))))
+ (circle-radius (first alosh))
+ (circle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [(rectangle? (first alosh))
+ (cons
+ (make-rectangle
+ (make-posn (+ (posn-x (rectangle-upper-left (first alosh)))
+ delta)
+ (posn-y (rectangle-upper-left (first alosh))))
+ (rectangle-width (first alosh))
+ (rectangle-height (first alosh))
+ (rectangle-color (first alosh)))
+ (translate-losh (rest alosh) delta))]
+ [else (error 'translate-losh "unexpected error")]))
+
+;clear-losh : list-of-shapes -> boolean
+;Clears shapes corresponding to entries in alosh
+;and returns true. Does so by calling clear-a-rectangle
+;and clear-a-circle.
+
+(define (clear-losh alosh)
+ (cond
+ [(empty? alosh) true]
+ [(circle? (first alosh)) (and
+ (clear-a-circle (first alosh))
+ (clear-losh (rest alosh)))]
+ [(rectangle? (first alosh)) (and
+ (clear-a-rectangle (first alosh))
+ (clear-losh (rest alosh)))]
+ [else false]))
+
+; clear-a-circle : circle -> boolean
+; Clears a circle given a-circle, returns true if
+; evaluation completes successfully, false otherwise.
+
+(define (clear-a-circle a-circle)
+ (clear-solid-disk (circle-center a-circle)
+ (circle-radius a-circle)))
+
+; clear-a-rectangle : rectangle -> boolean
+; Clears rectangle specified by a-rect and returns true
+; if evaluation suceeds, false otherwise.
+
+(define (clear-a-rectangle a-rect)
+ (clear-solid-rect (rectangle-upper-left a-rect)
+ (rectangle-width a-rect)
+ (rectangle-height a-rect)))
+
+;Data Definition
+;
+;A picture is a list-of-shapes?, I think.
+;
+;draw-and-clear-picture : picture -> boolean
+;Draws alosh, sleeps for a while, then clears alosh.
+;!!!CHANGE!!! Now it clears, sleeps for a while,
+;then draws alosh.
+
+(define (draw-and-clear-picture alosh)
+ (and
+
+ (draw-losh alosh)
+; (sleep-for-a-while 2)
+ (clear-losh alosh)))
+;
+;move-picture : number picture -> picture
+;Draws a picture delta pixels to the right, sleeps for a while,
+;clears the picture, and then returns the translated picture.
+
+(define (move-picture delta alosh)
+ (cond
+ [(draw-and-clear-picture (translate-losh alosh delta))
+ (translate-losh alosh delta)]
+ [else false]))
+
+(start 500 100)
+
+(control-left-right FACE 100 move-picture draw-losh)
\ No newline at end of file
blob - /dev/null
blob + 74258c794a05799f444de038db250ad8f9652024 (mode 644)
--- /dev/null
+++ 37.4.4
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.4|) (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")))))
+(define WIDTH 500)
+(define HEIGHT 500)
+(define RADIUS 40)
+(define INTERDIST 20)
+(define X-BULB (/ WIDTH 6))
+(define Y-RED (+ (* 6 INTERDIST) RADIUS))
+(define Y-YELLOW (+ Y-RED (* 2 RADIUS) INTERDIST))
+(define Y-GREEN (+ Y-YELLOW (* 2 RADIUS) INTERDIST))
+(define Y-BULB (/ HEIGHT 6))
+(define X-RED (+ (* 6 INTERDIST) RADIUS))
+(define X-YELLOW (+ X-RED (* 2 RADIUS) INTERDIST))
+(define X-GREEN (+ X-YELLOW (* 2 RADIUS) INTERDIST))
+
+;A traffic-light color (TL-color) is either
+;1. 'red,
+;2. 'yellow, or
+;3. 'green.
+
+;;State Variables:
+
+;;current-color1 : TL-color
+;;The current color of the first traffic-light.
+(define current-color1 'red)
+
+;;current-color2: TL-color
+;;The current color of the second traffic-light.
+(define current-color2 'red)
+
+;;change-color : -> void
+;;Changes the color of the first and second traffic lights, ie, its effect is to change current-color1 and current-color2 in a way that obeys traffic laws.
+
+(define (change-color)
+ (cond
+ [(symbol=? current-color1 'green)
+ (begin (set! current-color1 'yellow)
+ (set! current-color2 'red))]
+ [(symbol=? current-color1 'yellow)
+ (begin (set! current-color1 'red)
+ (set! current-color2 'green))]
+ [(symbol=? current-color2 'green)
+ (begin (set! current-color1 'red)
+ (set! current-color2 'yellow))]
+ [(symbol=? current-color2 'yellow)
+ (begin (set! current-color1 'green)
+ (set! current-color2 'red))]
+ [else (begin (set! current-color1 'green)
+ (set! current-color2 'red))]))
+
+;next : -> true
+;Effect: Changes the traffic light colors, redraws the traffic lights, then returns true.
+
+(define (next)
+ (local ((define previous-color1 current-color1)
+ (define previous-color2 current-color2))
+ (begin (change-color)
+ (switch current-color1 previous-color1 1)
+ (switch current-color2 previous-color2 2))))
+
+;;init-current-color : -> true
+;Opens the canvas and draws the outline of the 3 traffic light bulbs as well as lighting up the red lightbulb.
+
+(define (init-current-color)
+ (begin (start WIDTH HEIGHT)
+ (draw-circle (make-posn X-BULB Y-RED) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-BULB Y-YELLOW) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-BULB Y-GREEN) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-RED Y-BULB) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-YELLOW Y-BULB) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-GREEN Y-BULB) (+ RADIUS 1) 'black)
+ (set! current-color1 'red)
+ (set! current-color2 'red)
+ (fill-bulb current-color1 1)
+ (fill-bulb current-color2 2)))
+
+;;op-bulb : symbol N -> boolean
+;; Performs op on a given bulb based on color and bulb#; returns true if the function evaluates properly, false otherwise.
+
+(define (op-bulb color op bulb#)
+ (local ((define x-bulb (cond
+ [(= bulb# 1) X-BULB]
+ [(symbol=? color 'red) X-RED]
+ [(symbol=? color 'yellow) X-YELLOW]
+ [(symbol=? color 'green) X-GREEN]))
+ (define y-bulb (cond
+ [(= bulb# 2) Y-BULB]
+ [(symbol=? color 'red) Y-RED]
+ [(symbol=? color 'yellow) Y-YELLOW]
+ [(symbol=? color 'green) Y-GREEN])))
+ (cond
+ [(symbol=? color 'red)
+ (op (make-posn x-bulb y-bulb) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (op (make-posn x-bulb y-bulb) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (op (make-posn x-bulb y-bulb) RADIUS 'green)])))
+
+;; fill-bulb : symbol N -> boolean
+;; Fills in a given bulb based on color and bulb#; returns true if the function evaluates properly, false otherwise.
+
+(define (fill-bulb color bulb#)
+ (op-bulb color draw-solid-disk bulb#))
+
+;; clear-bulb : symbol N N -> boolean
+;; Clears a given bulb based on color, x-bulb, and y-bulb; returns true if the function evaluates properly, false otherwise.
+
+(define (clear-bulb color bulb#)
+ (op-bulb color clear-solid-disk bulb#))
+
+;; switch : symbol symbol -> boolean
+;; Fills in bulb based on fill and clears another based on clear to switch colors. Returns true if evaluation completes, false otherwise.
+
+(define (switch fill clear bulb#)
+ (and
+ (clear-bulb clear bulb#)
+ (fill-bulb fill bulb#)))
+
+(init-current-color)
+
+;;Code that needs to be modified
+
+;;Controller
+
+(define (next-callback event)
+ (next))
+
+(create-window (list (list (make-button "Next" next-callback))))
\ No newline at end of file
blob - /dev/null
blob + d54b036b5e635ff42568558d769bf53d2f640ddb (mode 644)
--- /dev/null
+++ 37.4.4~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.4|) (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")))))
+(define WIDTH 100)
+(define HEIGHT 340)
+(define RADIUS 40)
+(define INTERDIST 20)
+(define X-BULB (/ WIDTH 2))
+(define Y-RED (+ INTERDIST RADIUS))
+(define Y-YELLOW (+ Y-RED (* 2 RADIUS) INTERDIST))
+(define Y-GREEN (+ Y-YELLOW (* 2 RADIUS) INTERDIST))
+
+;A traffic-light color (TL-color) is either
+;1. 'red,
+;2. 'yellow, or
+;3. 'green.
+
+;;State Variable:
+;;current-color : TL-color
+(define current-color 'red)
+
+;next : -> true
+;Effect: Changes current-color from 'red to 'green, 'green to 'yellow, or 'yellow to 'red depending on what the current-color is. Returns true once evaluation completes.
+
+(define (next)
+ (local ((define previous-color current-color))
+ (begin (set! current-color (next-color current-color))
+ (switch current-color previous-color))))
+
+;next-color : TL-color -> TL-color
+;Given acolor, returns the next logical color.
+
+(define (next-color acolor)
+ (cond
+ [(symbol=? acolor 'red) 'green]
+ [(symbol=? acolor 'yellow) 'red]
+ [(symbol=? acolor 'green) 'yellow]))
+
+;;init-current-color : -> true
+;Opens the canvas and draws the outline of the 3 traffic light bulbs as well as lighting up the red lightbulb.
+
+(define (init-current-color)
+ (begin (start WIDTH HEIGHT)
+ (draw-circle (make-posn X-BULB Y-RED) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-BULB Y-YELLOW) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-BULB Y-GREEN) (+ RADIUS 1) 'black)
+ (set! current-color 'red)
+ (fill-bulb current-color)))
+
+;; fill-bulb : symbol -> boolean
+;; Fills in a given bulb based on color; returns true if the function evaluates properly, false otherwise.
+
+(define (fill-bulb color)
+ (cond
+ [(symbol=? color 'red)
+ (draw-solid-disk (make-posn X-BULB Y-RED) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (draw-solid-disk (make-posn X-BULB Y-YELLOW) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (draw-solid-disk (make-posn X-BULB Y-GREEN) RADIUS 'green)]))
+
+;; clear-bulb : symbol -> boolean
+;; Clears a bulb given color; returns true if evaluation completes, false otherwise.
+
+(define (clear-bulb color)
+ (cond
+ [(symbol=? color 'red)
+ (clear-solid-disk (make-posn X-BULB Y-RED) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (clear-solid-disk (make-posn X-BULB Y-YELLOW) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (clear-solid-disk (make-posn X-BULB Y-GREEN) RADIUS 'green)]))
+
+;; switch : symbol symbol -> boolean
+;; Fills in bulb based on fill and clears another based on clear to switch colors. Returns true if evaluation completes, false otherwise.
+
+(define (switch fill clear)
+ (and
+ (fill-bulb fill)
+ (clear-bulb clear)))
+
+(init-current-color)
\ No newline at end of file
blob - /dev/null
blob + 0e42dd038e95e0c337f759a5167314cb0d46ff16 (mode 644)
--- /dev/null
+++ 37.5.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.5|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+(define-struct building (name picture connections))
+
+A building is a structure
+(make-building n p c)
+where n is a symbol, p is an image, and c is a (listof buildings).
+
+current-location
\ No newline at end of file
blob - /dev/null
blob + cb8ab4ad21c65e43dd96a4d54dec7b2ac200632b (mode 644)
--- /dev/null
+++ 39.1.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |39.1|) (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")))))
+;;Data Definition
+;;A traffic-light color (TL-color) is either
+;;1. 'red,
+;;2. 'yellow, or
+;;3. 'green.
+
+;;View
+
+(define WIDTH 1000)
+(define HEIGHT 340)
+(define RADIUS 40)
+(define INTERDIST 20)
+(define Y-RED (+ INTERDIST RADIUS))
+(define Y-YELLOW (+ Y-RED (* 2 RADIUS) INTERDIST))
+(define Y-GREEN (+ Y-YELLOW (* 2 RADIUS) INTERDIST))
+
+;;op-bulb : (posn N symbol -> true) symbol number -> boolean
+;;Perform op on a bulb given op, color, and x-posn.
+
+(define (op-bulb op color x-posn)
+ (cond
+ [(symbol=? color 'red)
+ (op (make-posn x-posn Y-RED) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (op (make-posn x-posn Y-YELLOW) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (op (make-posn x-posn Y-GREEN) RADIUS 'green)]))
+
+;; fill-bulb : symbol number -> boolean
+;; Fills in a given bulb based on color and x-posn; returns true if the function evaluates properly, false otherwise.
+
+(define (fill-bulb color x-posn)
+ (op-bulb draw-solid-disk color x-posn))
+
+;; clear-bulb : symbol number -> boolean
+;; Clears a bulb given color and x-posn; returns true if evaluation completes, false otherwise.
+
+(define (clear-bulb color x-posn)
+ (op-bulb clear-solid-disk color x-posn))
+
+;draw-border : number -> true
+;Draws the borders for the 3 traffic lights given x-posn.
+
+(define (draw-border x-posn)
+ (and (draw-circle (make-posn x-posn Y-RED) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn x-posn Y-YELLOW) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn x-posn Y-GREEN) (+ RADIUS 1) 'black)))
+
+;switch : symbol symbol number -> true
+;Switches clear to fill for the lightbulb given x-posn.
+
+(define (switch clear fill x-posn)
+ (and
+ (fill-bulb fill x-posn)
+ (clear-bulb clear x-posn)))
+
+;;Model
+
+;;make-traffic-light : symbol number -> (symbol -> true)
+;;Consumes location and x-posn, which indicates the position of the traffic light.
+;;Output: Creates a function that acts as a service manager, which has two functions. If the argument 'next is passed, a given traffic light will switch (effect: current-color will switch for the given light and the canvas will change accordingly). If the argument 'reset is passed, the traffic light will be reset to 'red (effect: current-color and canvas will change accordingly).
+
+(define (make-traffic-light location x-posn)
+ (local
+ (;;State Variable:
+ ;;current-color : TL-color
+ (define current-color 'red)
+
+ ;;next : -> true
+ ;;Effect: Changes current-color from 'red to 'green, 'green to 'yellow,
+ ;;or 'yellow to 'red depending on what the current-color is. Returns true.
+ (define (next)
+ (local ((define previous-color current-color))
+ (begin (set! current-color (next-color current-color))
+ (switch previous-color current-color x-posn))))
+
+ ;next-color : TL-color -> TL-color
+ ;Given acolor, returns the next logical color.
+ (define (next-color acolor)
+ (cond
+ [(symbol=? acolor 'red) 'green]
+ [(symbol=? acolor 'yellow) 'red]
+ [(symbol=? acolor 'green) 'yellow]))
+
+ ;;init-current-color : -> true
+ ;;Opens the canvas and draws the outline of the 3 traffic light
+ ;;bulbs as well as lighting up the red lightbulb.
+ (define (init-traffic-light)
+ (begin (draw-border x-posn)
+ (clear-bulb current-color x-posn)
+ (set! current-color 'red)
+ (fill-bulb current-color x-posn)))
+ (define (service-manager msg)
+ (cond
+ [(symbol=? msg 'next) (next)]
+ [(symbol=? msg 'reset) (init-traffic-light)]
+ [else (error 'service-manager "message not understood")])))
+ (begin (init-traffic-light)
+ service-manager)))
+
+(start WIDTH HEIGHT)
+(define lights
+ (list (make-traffic-light 'AdobeCircle 50)
+ (make-traffic-light 'Pereira 200)
+ (make-traffic-light 'CampusDr 350)
+ (make-traffic-light 'HarvardSt 500)
+ (make-traffic-light 'BrenRd 650)
+ (make-traffic-light 'UniversityBlvd 800)))
+
+
+;;Controller
+
+(define (next-callback event)
+ (andmap (lambda (a-light) (a-light 'next)) lights))
+
+(define (reset-callback event)
+ (andmap (lambda (a-light) (a-light 'reset)) lights))
+
+(define next-buttons
+(build-list (length lights)
+ (lambda (n)
+ (local ((define (next-indiv-callback event)
+ ((list-ref lights n) 'next)))
+ (make-button (number->string (add1 n)) next-indiv-callback)))))
+
+(create-window (list (list (make-button "Next" next-callback)
+ (make-button "Reset" reset-callback))
+ next-buttons))
+
blob - /dev/null
blob + 41e6da3cc309999ef5a137bd9be6613fa515770a (mode 644)
--- /dev/null
+++ 39.1.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |39.1|) (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")))))
+(define WIDTH 500)
+(define HEIGHT 500)
+(define RADIUS 40)
+(define INTERDIST 20)
+(define X-BULB (/ WIDTH 6))
+(define Y-RED (+ (* 6 INTERDIST) RADIUS))
+(define Y-YELLOW (+ Y-RED (* 2 RADIUS) INTERDIST))
+(define Y-GREEN (+ Y-YELLOW (* 2 RADIUS) INTERDIST))
+(define Y-BULB (/ HEIGHT 6))
+(define X-RED (+ (* 6 INTERDIST) RADIUS))
+(define X-YELLOW (+ X-RED (* 2 RADIUS) INTERDIST))
+(define X-GREEN (+ X-YELLOW (* 2 RADIUS) INTERDIST))
+
+;A traffic-light color (TL-color) is either
+;1. 'red,
+;2. 'yellow, or
+;3. 'green.
+
+;;State Variables:
+
+;;current-color1 : TL-color
+;;The current color of the first traffic-light.
+(define current-color1 'red)
+
+;;current-color2: TL-color
+;;The current color of the second traffic-light.
+(define current-color2 'red)
+
+;;change-color : -> void
+;;Changes the color of the first and second traffic lights, ie, its effect is to change current-color1 and current-color2 in a way that obeys traffic laws.
+
+(define (change-color)
+ (cond
+ [(symbol=? current-color1 'green)
+ (begin (set! current-color1 'yellow)
+ (set! current-color2 'red))]
+ [(symbol=? current-color1 'yellow)
+ (begin (set! current-color1 'red)
+ (set! current-color2 'green))]
+ [(symbol=? current-color2 'green)
+ (begin (set! current-color1 'red)
+ (set! current-color2 'yellow))]
+ [(symbol=? current-color2 'yellow)
+ (begin (set! current-color1 'green)
+ (set! current-color2 'red))]
+ [else (begin (set! current-color1 'green)
+ (set! current-color2 'red))]))
+
+;next : -> true
+;Effect: Changes the traffic light colors, redraws the traffic lights, then returns true.
+
+(define (next)
+ (local ((define previous-color1 current-color1)
+ (define previous-color2 current-color2))
+ (begin (change-color)
+ (switch current-color1 previous-color1 1)
+ (switch current-color2 previous-color2 2))))
+
+;;init-current-color : -> true
+;Opens the canvas and draws the outline of the 3 traffic light bulbs as well as lighting up the red lightbulb.
+
+(define (init-current-color)
+ (begin (start WIDTH HEIGHT)
+ (draw-circle (make-posn X-BULB Y-RED) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-BULB Y-YELLOW) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-BULB Y-GREEN) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-RED Y-BULB) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-YELLOW Y-BULB) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn X-GREEN Y-BULB) (+ RADIUS 1) 'black)
+ (set! current-color1 'red)
+ (set! current-color2 'red)
+ (fill-bulb current-color1 1)
+ (fill-bulb current-color2 2)))
+
+;;op-bulb : symbol N -> boolean
+;; Performs op on a given bulb based on color and bulb#; returns true if the function evaluates properly, false otherwise.
+
+(define (op-bulb color op bulb#)
+ (local ((define x-bulb (cond
+ [(= bulb# 1) X-BULB]
+ [(symbol=? color 'red) X-RED]
+ [(symbol=? color 'yellow) X-YELLOW]
+ [(symbol=? color 'green) X-GREEN]))
+ (define y-bulb (cond
+ [(= bulb# 2) Y-BULB]
+ [(symbol=? color 'red) Y-RED]
+ [(symbol=? color 'yellow) Y-YELLOW]
+ [(symbol=? color 'green) Y-GREEN])))
+ (cond
+ [(symbol=? color 'red)
+ (op (make-posn x-bulb y-bulb) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (op (make-posn x-bulb y-bulb) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (op (make-posn x-bulb y-bulb) RADIUS 'green)])))
+
+;; fill-bulb : symbol N -> boolean
+;; Fills in a given bulb based on color and bulb#; returns true if the function evaluates properly, false otherwise.
+
+(define (fill-bulb color bulb#)
+ (op-bulb color draw-solid-disk bulb#))
+
+;; clear-bulb : symbol N N -> boolean
+;; Clears a given bulb based on color, x-bulb, and y-bulb; returns true if the function evaluates properly, false otherwise.
+
+(define (clear-bulb color bulb#)
+ (op-bulb color clear-solid-disk bulb#))
+
+;; switch : symbol symbol -> boolean
+;; Fills in bulb based on fill and clears another based on clear to switch colors. Returns true if evaluation completes, false otherwise.
+
+(define (switch fill clear bulb#)
+ (and
+ (clear-bulb clear bulb#)
+ (fill-bulb fill bulb#)))
+
+(init-current-color)
+
+;;Code that needs to be modified
+
+;;Controller
+
+(define (next-callback event)
+ (next))
+
+(create-window (list (list (make-button "Next" next-callback))))
\ No newline at end of file
blob - /dev/null
blob + dc7ed9255d7a24bce87532bb4b566faf80c52e22 (mode 644)
--- /dev/null
+++ 39.1.6.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname 39.1.6) (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")))))
+;;make-address-book : string -> address-book
+;;
+;;An address-book is an interface
+;;1. 'add :: symbol number -> void
+;;2. 'remove :: symbol -> void
+;;3. 'lookup-name :: symbol -> number or false
+;;4. 'lookup-number :: number -> symbol or false
+
+(define-struct entry (name number))
+
+;;An entry is a structure
+;;(make-entry na nu)
+;;where na is a symbol, nu is a number.
+
+(define (make-address-book title)
+ (local (;;Model
+
+ ;;State Variable
+ ;;address-book : (listof entry)
+ ;;Represents the entries in a physical address book
+ (define address-book empty)
+
+ ;;add-to-address-book : symbol number -> void
+ ;;Effect: Adds name and phone to the address-book. Produces no output.
+ (define (add-to-address-book name phone)
+ (set! address-book (cons (make-entry name phone) address-book)))
+
+ ;;remove : symbol -> void
+ ;;Effect: Removes name from address-book. No output returned.
+ (define (remove name)
+ (set! address-book
+ (filter (lambda (anentry) (not (equal? name (entry-name anentry))))
+ address-book)))
+
+ ;;lookup-name : symbol (listof (list symbol number)) -> number or false
+ ;;Output: Lookup the phone number for aname in abook.
+ ;;No effect (memory neither changed nor accessed).
+ (define (lookup-name aname abook)
+ (lookup-abstract aname abook entry-name entry-number))
+
+ ;;lookup-number : number (listof (list symbol number)) -> symbol or false
+ ;;Output: Lookup the name for the entry with anumber in abook.
+ ;;No effect (memory neither changed nor accessed).
+ (define (lookup-number anumber abook)
+ (lookup-abstract anumber abook entry-number entry-name))
+
+ ;;lookup-abstract :
+ ;;X (listof (list symbol number)) ((listof Z) -> Z) ((listof Z) -> Z) -> Y
+ ;;Output: Given anx, abook, op1, and op2, returns a number
+ ;;given a symbol or a symbol given a number. X and Y are different data types.
+ ;;No effect.
+
+ (define (lookup-abstract anx abook op1 op2)
+ (cond
+ [(empty? abook) false]
+ [(equal? (op1 (first abook)) anx) (op2 (first abook))]
+ [else (lookup-abstract anx (rest abook) op1 op2)]))
+
+ (define (service-manager msg)
+ (cond
+ [(symbol=? msg 'add) add-to-address-book]
+ [(symbol=? msg 'remove) remove]
+ [(symbol=? msg 'lookup-name)
+ (lambda (aname) (lookup-name aname address-book))]
+ [(symbol=? msg 'lookup-number)
+ (lambda (anumber) (lookup-number anumber address-book))])))
+ service-manager))
+
+
+;;gui-for-address-book : (listof strings) -> true
+;;Consumes alos. Outputs true.
+;;Effects:
+;;1. Creates a new address book (define a new interface for each string?) for each one.
+;;2. Creates a GUI for the address books.
+
+(define (gui-for-address-book alos)
+ (local (;;View
+ (define book-list
+ (build-list (length alos)
+ (lambda (i) (make-address-book (list-ref alos i)))))
+ (define greeting-msg (make-message "Delta Notch - People Finder Pro Deluxe (TM)"))
+ (define book-msg (make-message "Select address book: "))
+ (define book-choice (make-choice alos))
+ (define input-name (make-text "Name: "))
+ (define input-number (make-text "Number: "))
+ (define results-msg (make-message ""))
+
+ ;;Controller
+ (define (add-callback event)
+ (local ((define address-book-interface
+ (list-ref book-list (choice-index book-choice)))
+ (define aname-sym (string->symbol (text-contents input-name)))
+ (define anumber-num (string->number (text-contents input-number))))
+ (begin ((address-book-interface 'add) aname-sym anumber-num)
+ (draw-message results-msg
+ (string-append "Added: "
+ (symbol->string aname-sym)
+ " "
+ (number->string anumber-num))))))
+ (define (remove-callback event)
+ (local ((define address-book-interface
+ (list-ref book-list (choice-index book-choice)))
+ (define aname-sym (string->symbol (text-contents input-name)))
+ (define anumber-num (string->number (text-contents input-number))))
+ (begin ((address-book-interface 'remove) aname-sym)
+ (draw-message results-msg
+ (string-append "Removed: "
+ (symbol->string aname-sym)
+ " "
+ (number->string anumber-num))))))
+ (define (lookup-callback event)
+ (local ((define address-book-interface
+ (list-ref book-list (choice-index book-choice)))
+ (define aname (text-contents input-name))
+ (define anumber (text-contents input-number))
+ (define aname-sym (string->symbol aname))
+ (define anumber-num (string->number anumber))
+ (define return-name
+ ((address-book-interface 'lookup-number) anumber-num))
+ (define return-number
+ ((address-book-interface 'lookup-name) aname-sym)))
+ (cond
+ [(and (not (equal? aname ""))
+ (number? return-number))
+ (draw-message results-msg (number->string return-number))]
+ [(and (not (equal? anumber ""))
+ (symbol? return-name))
+ (draw-message results-msg (symbol->string return-name))]
+ [(and (not (equal? aname ""))
+ (boolean? return-name))
+ (draw-message results-msg "Name not found")]
+ [(and (not (equal? anumber ""))
+ (boolean? return-number))
+ (draw-message results-msg "Number not found")]
+ [else (draw-message results-msg "Please enter a name or number")])))
+ (define add-button (make-button "Add Entry" add-callback))
+ (define remove-button (make-button "Remove Entry" remove-callback))
+ (define lookup-button (make-button "Lookup" lookup-callback)))
+ (create-window (list (list greeting-msg)
+ (list book-msg book-choice)
+ (list input-name add-button)
+ (list input-number remove-button)
+ (list results-msg lookup-button)))))
+
+
+
+(gui-for-address-book '("Hsinya's Book" "Aaron's Book" "Anonymous Book"))
blob - /dev/null
blob + 435ad1664a65eaef2d40c466e161d4f2207f341d (mode 644)
--- /dev/null
+++ 39.1.6.0~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname 39.1.6) (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")))))
+;;Model
+
+;;State Variable
+;;address-book : (listof (list symbol number))
+;;Stores a list of list of two items (pairs) of names and numbers representing entries in an address book.
+(define address-book empty)
+
+;add-to-address-book : symbol number -> void
+;Effect: Adds name and phone to the address-book. Produces no output.
+
+(define (add-to-address-book name phone)
+ (set! address-book (cons (list name phone) address-book)))
+
+;remove : symbol -> void
+;Effect: Removes name from address-book. No output returned.
+(define (remove name)
+ (local ((define (remove-aux aname abook)
+ (cond
+ [(empty? abook) empty]
+ [(symbol=? (first (first abook)) aname) (remove-aux aname (rest abook))]
+ [else (cons (first abook)
+ (remove-aux aname (rest abook)))])))
+ (set! address-book (remove-aux name address-book))))
+
+
+
+;lookup-name : symbol (listof (list symbol number)) -> number or false
+;Output: Lookup the phone number for aname in abook. No effect (memory neither changed nor accessed).
+
+(define (lookup-name aname abook)
+ (lookup-abstract aname abook first second))
+
+;lookup-number : number (listof (list symbol number)) -> symbol or false
+;Output: Lookup the name for the entry with anumber in abook. No effect (memory neither changed nor accessed).
+
+(define (lookup-number anumber abook)
+ (lookup-abstract anumber abook second first))
+
+;lookup-abstract : X (listof (list symbol number)) ((listof Z) -> Z) ((listof Z) -> Z) -> Y
+;Output: Given anx, abook, op1, and op2, returns a number given a symbol or a symbol given a number. X and Y are different data types.
+;No effect.
+
+(define (lookup-abstract anx abook op1 op2)
+ (cond
+ [(empty? abook) false]
+ [(equal? (op1 (first abook)) anx) (op2 (first abook))]
+ [else (lookup-abstract anx (rest abook) op1 op2)]))
+
+;;View
+
+(define name-text (make-text "Name"))
+(define number-text (make-text "Number"))
+(define results-message (make-message "Delta Notch Phone Beta"))
+
+
+;;Controller
+
+;add-entry-callback : event -> true
+;Effect: Adds the contents of name-text and number-text into the beginning of address-book.
+(define (add-entry-callback event)
+ (void? (add-to-address-book (string->symbol (text-contents name-text)) (string->number (text-contents number-text)))))
+
+;remove-name-callback : event -> true
+;Effect: Removes an entry from address-book associated with the text contents of name-text.
+(define (remove-name-callback event)
+ (void? (remove (string->symbol (text-contents name-text)))))
+
+;search-callback : event -> true
+(define (search-callback event)
+ (local
+ ((define found-name
+ (lookup-number (string->number (text-contents number-text)) address-book))
+ (define found-number
+ (lookup-name (string->symbol (text-contents name-text)) address-book)))
+ (cond
+ [(and (equal? (text-contents name-text) "")
+ (symbol? found-name))
+ (draw-message results-message (symbol->string found-name))]
+ [(number? found-number)
+ (draw-message results-message (number->string found-number))]
+ [else (draw-message results-message "Entry not found")])))
+
+
+
+(create-window (list (list name-text (make-button "Add entry" add-entry-callback))
+ (list number-text (make-button "Search!" search-callback))
+ (list results-message (make-button "Remove name" remove-name-callback))))
+
+;Tests
+(define (init-address-book)
+ (begin (add-to-address-book 'Aaron 525)
+ (add-to-address-book 'Geffen 3225)
+ (add-to-address-book 'Jobs 5251)
+ (add-to-address-book 'Gates 5265)
+ (add-to-address-book 'Dell 5259)
+ (remove 'Aaron)
+ address-book))
+(init-address-book)
\ No newline at end of file
blob - /dev/null
blob + 3a29193a78f7824bf70b5037aaf30f28b4edbb16 (mode 644)
--- /dev/null
+++ 39.2.1
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |39.2|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp")))))
+;TODO:
+;
+;Fill in examples for make-city
+;Abstract x-posn using absolute definitions
+
+#|
+Exercise 39.2.1. Develop the program make-city. It manages a collection of traffic lights. The program should provide four services:
+
+ 1. adding a traffic light with a label (string);
+ 2. removing a traffic light by label;
+ 3. switching the state of a traffic light with some given label; and
+ 4. resetting a traffic light to red with some given label.
+
+Hint: The first two services are provided directly; the last two are implemented by the simulated traffic lights.
+
+After the development of the program is completed, develop a graphical user interface. Solution
+|#
+
+;;Data Definition
+;;A traffic-light color (TL-color) is either
+;;1. 'red,
+;;2. 'yellow, or
+;;3. 'green.
+
+;;A traffic-light is an interface
+;;1. 'next : -> true
+;;2. 'reset : -> true
+
+;;A city is an interface
+;;1.'add-light :: symbol -> void
+;;2.'remove-light :: symbol -> void
+;;3.'access-light :: symbol -> traffic-light
+
+;make-city : symbol -> city
+;;Consumes location. Produces a city interface, which can ultimately be used to perform 4 possible services:
+
+;; 1. adding a traffic light with a label (string);
+;; 2. removing a traffic light by label;
+;; 3. switching the state of a traffic light with some given label; and
+;; 4. resetting a traffic light to red with some given label.
+
+;;Examples
+
+;;((make-city) 'add-light 'Germany) should set city-lights to (list (list 'Germany (make-traffic-light 'Germany))). It should also draw the traffic-light on the canvas. Output should be true.
+;;(define my-city (make-city "Los Angeles"))
+;;((my-city 'add-light) 'Boulevard)
+;;((my-city 'add-light) 'Street)
+;;((my-city 'add-light) 'Drive)
+;;((my-city 'add-light) 'Road)
+;;Should give a city with 4 traffic-lights and should draw 4 traffic lights on a canvas.
+
+(define (make-city location)
+ (local
+ (;;State Variables:
+ ;;city-lights : (listof (list symbol traffic-light))
+ ;;Records the traffic-lights in the city, the first symbol represents the location
+ (define city-lights empty)
+
+ ;;add-light : symbol -> void
+ ;;Effect: Adds (list symbol traffic-light) to the front of city-lights
+ (define (add-light alocation)
+ (local ((define x-posn (+ 200 (* 100 (sub1 (length city-lights))))))
+ (set! city-lights
+ (cons (list alocation (make-traffic-light alocation x-posn))
+ city-lights))))
+
+ ;;remove-light : symbol -> void
+ ;;Effect: Removes a light from city-lights
+ (define (remove-light alocation)
+ (local ((define (remove-aux alox x)
+ (filter (lambda (an-x) (not (equal? (first an-x) x))) alox))
+ (define x-posn (+ 200 (* 100 (sub1 (sub1 (length city-lights)))))))
+ (begin
+ (clear-bulb 'red x-posn)
+ (clear-bulb 'yellow x-posn)
+ (clear-bulb 'green x-posn)
+ (clear-border x-posn)
+ (set! city-lights (remove-aux city-lights alocation)))))
+
+
+ (define (access-light alocation)
+ (local ((define (access-aux alox x)
+ (cond
+ [(empty? alox) false]
+ [(equal? (first (first alox)) x) (second (first alox))]
+ [else (access-aux (rest alox) x)])))
+ (access-aux city-lights alocation)))
+ (define (service-manager msg)
+ (cond
+ [(equal? msg 'add-light) add-light]
+ [(equal? msg 'remove-light) remove-light]
+ [(equal? msg 'access-light) access-light]
+ [else (error 'make-city "message not understood")])))
+ service-manager))
+
+;;Model
+
+;;make-traffic-light : symbol number -> (symbol -> true)
+;;Consumes location and x-posn, which indicates the position of the traffic light.
+;;Output: Creates a function that acts as a service manager, which has two functions. If the argument 'next is passed, a given traffic light will switch (effect: current-color will switch for the given light and the canvas will change accordingly). If the argument 'reset is passed, the traffic light will be reset to 'red (effect: current-color and canvas will change accordingly).
+
+(define (make-traffic-light location x-posn)
+ (local
+ (;;State Variable:
+ ;;current-color : TL-color
+ (define current-color 'red)
+
+ ;;next : -> true
+ ;;Effect: Changes current-color from 'red to 'green, 'green to 'yellow,
+ ;;or 'yellow to 'red depending on what the current-color is. Returns true.
+ (define (next)
+ (local ((define previous-color current-color))
+ (begin (set! current-color (next-color current-color))
+ (switch previous-color current-color x-posn))))
+
+ ;next-color : TL-color -> TL-color
+ ;Given acolor, returns the next logical color.
+ (define (next-color acolor)
+ (cond
+ [(symbol=? acolor 'red) 'green]
+ [(symbol=? acolor 'yellow) 'red]
+ [(symbol=? acolor 'green) 'yellow]))
+
+ ;;init-current-color : -> true
+ ;;Opens the canvas and draws the outline of the 3 traffic light
+ ;;bulbs as well as lighting up the red lightbulb.
+ (define (init-traffic-light)
+ (begin (draw-border x-posn)
+ (clear-bulb current-color x-posn)
+ (set! current-color 'red)
+ (fill-bulb current-color x-posn)))
+ (define (service-manager msg)
+ (cond
+ [(symbol=? msg 'next) (next)]
+ [(symbol=? msg 'reset) (init-traffic-light)]
+ [else (error 'service-manager "message not understood")])))
+ (begin (init-traffic-light)
+ service-manager)))
+
+
+;;View
+
+(define WIDTH 1000)
+(define HEIGHT 340)
+(define RADIUS 40)
+(define INTERDIST 20)
+(define Y-RED (+ INTERDIST RADIUS))
+(define Y-YELLOW (+ Y-RED (* 2 RADIUS) INTERDIST))
+(define Y-GREEN (+ Y-YELLOW (* 2 RADIUS) INTERDIST))
+
+;;op-bulb : (posn N symbol -> true) symbol number -> boolean
+;;Perform op on a bulb given op, color, and x-posn.
+
+(define (op-bulb op color x-posn)
+ (cond
+ [(symbol=? color 'red)
+ (op (make-posn x-posn Y-RED) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (op (make-posn x-posn Y-YELLOW) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (op (make-posn x-posn Y-GREEN) RADIUS 'green)]))
+
+;; fill-bulb : symbol number -> boolean
+;; Fills in a given bulb based on color and x-posn; returns true if the function evaluates properly, false otherwise.
+
+(define (fill-bulb color x-posn)
+ (op-bulb draw-solid-disk color x-posn))
+
+;; clear-bulb : symbol number -> boolean
+;; Clears a bulb given color and x-posn; returns true if evaluation completes, false otherwise.
+
+(define (clear-bulb color x-posn)
+ (op-bulb clear-solid-disk color x-posn))
+
+;;op-border : (posn number symbol -> true) number -> true
+;;Performs an operation on the borders of circles of a traffic light.
+
+(define (op-border op x-posn)
+ (and (op (make-posn x-posn Y-RED) (+ RADIUS 1) 'black)
+ (op (make-posn x-posn Y-YELLOW) (+ RADIUS 1) 'black)
+ (op (make-posn x-posn Y-GREEN) (+ RADIUS 1) 'black)))
+
+;;draw-border : number -> true
+;;Draws the borders for the 3 traffic lights given x-posn.
+
+(define (draw-border x-posn)
+ (op-border draw-circle x-posn))
+
+;;clear-border : number -> true
+;;Clears the borders for the 3 traffic lights given x-posn.
+
+(define (clear-border x-posn)
+ (op-border clear-circle x-posn))
+
+;switch : symbol symbol number -> true
+;Switches clear to fill for the lightbulb given x-posn.
+
+(define (switch clear fill x-posn)
+ (and
+ (fill-bulb fill x-posn)
+ (clear-bulb clear x-posn)))
+
+
+
+
+#|
+(define lights
+ (list (make-traffic-light 'AdobeCircle 50)
+ (make-traffic-light 'Pereira 200)
+ (make-traffic-light 'CampusDr 350)
+ (make-traffic-light 'HarvardSt 500)
+ (make-traffic-light 'BrenRd 650)
+ (make-traffic-light 'UniversityBlvd 800)))
+
+(start WIDTH HEIGHT)
+
+;;Controller
+
+(define (next-callback event)
+ (andmap (lambda (a-light) (a-light 'next)) lights))
+
+(define (reset-callback event)
+ (andmap (lambda (a-light) (a-light 'reset)) lights))
+
+(define next-buttons
+(build-list (length lights)
+ (lambda (n)
+ (local ((define (next-indiv-callback event)
+ ((list-ref lights n) 'next)))
+ (make-button (number->string (add1 n)) next-indiv-callback)))))
+
+(create-window (list (list (make-button "Next" next-callback)
+ (make-button "Reset" reset-callback))
+ next-buttons))
+
+|#
+
+(start WIDTH HEIGHT)
+
+(define my-city (make-city "Los Angeles"))
+((my-city 'add-light) 'Germany)
+((my-city 'add-light) 'Naples)
+((my-city 'add-light) 'Paris)
+((my-city 'add-light) 'Italy)
\ No newline at end of file
blob - /dev/null
blob + 2a81b7dcd48330b4184ed1585078ad39dc7490d4 (mode 644)
--- /dev/null
+++ 39.2.1~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |39.2|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
+#|
+Exercise 39.2.1. Develop the program make-city. It manages a collection of traffic lights. The program should provide four services:
+
+ 1. adding a traffic light with a label (string);
+ 2. removing a traffic light by label;
+ 3. switching the state of a traffic light with some given label; and
+ 4. resetting a traffic light to red with some given label.
+
+Hint: The first two services are provided directly; the last two are implemented by the simulated traffic lights.
+
+After the development of the program is completed, develop a graphical user interface. Solution
+|#
+
+make-city : -> traffic-light.
+
+A traffic-light is an interface
+1. 'add-light : string -> (symbol number -> (symbol -> true))
+2. 'remove-light : string -> true
+
+(define (make-city)
+ make-traffic-light)
+
+
+;;Data Definition
+;;A traffic-light color (TL-color) is either
+;;1. 'red,
+;;2. 'yellow, or
+;;3. 'green.
+
+;;View
+
+(define WIDTH 1000)
+(define HEIGHT 340)
+(define RADIUS 40)
+(define INTERDIST 20)
+(define Y-RED (+ INTERDIST RADIUS))
+(define Y-YELLOW (+ Y-RED (* 2 RADIUS) INTERDIST))
+(define Y-GREEN (+ Y-YELLOW (* 2 RADIUS) INTERDIST))
+
+;;op-bulb : (posn N symbol -> true) symbol number -> boolean
+;;Perform op on a bulb given op, color, and x-posn.
+
+(define (op-bulb op color x-posn)
+ (cond
+ [(symbol=? color 'red)
+ (op (make-posn x-posn Y-RED) RADIUS 'red)]
+ [(symbol=? color 'yellow)
+ (op (make-posn x-posn Y-YELLOW) RADIUS 'yellow)]
+ [(symbol=? color 'green)
+ (op (make-posn x-posn Y-GREEN) RADIUS 'green)]))
+
+;; fill-bulb : symbol number -> boolean
+;; Fills in a given bulb based on color and x-posn; returns true if the function evaluates properly, false otherwise.
+
+(define (fill-bulb color x-posn)
+ (op-bulb draw-solid-disk color x-posn))
+
+;; clear-bulb : symbol number -> boolean
+;; Clears a bulb given color and x-posn; returns true if evaluation completes, false otherwise.
+
+(define (clear-bulb color x-posn)
+ (op-bulb clear-solid-disk color x-posn))
+
+;draw-border : number -> true
+;Draws the borders for the 3 traffic lights given x-posn.
+
+(define (draw-border x-posn)
+ (and (draw-circle (make-posn x-posn Y-RED) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn x-posn Y-YELLOW) (+ RADIUS 1) 'black)
+ (draw-circle (make-posn x-posn Y-GREEN) (+ RADIUS 1) 'black)))
+
+;switch : symbol symbol number -> true
+;Switches clear to fill for the lightbulb given x-posn.
+
+(define (switch clear fill x-posn)
+ (and
+ (fill-bulb fill x-posn)
+ (clear-bulb clear x-posn)))
+
+;;Model
+
+;;make-traffic-light : symbol number -> (symbol -> true)
+;;Consumes location and x-posn, which indicates the position of the traffic light.
+;;Output: Creates a function that acts as a service manager, which has two functions. If the argument 'next is passed, a given traffic light will switch (effect: current-color will switch for the given light and the canvas will change accordingly). If the argument 'reset is passed, the traffic light will be reset to 'red (effect: current-color and canvas will change accordingly).
+
+(define (make-traffic-light location x-posn)
+ (local
+ (;;State Variable:
+ ;;current-color : TL-color
+ (define current-color 'red)
+
+ ;;next : -> true
+ ;;Effect: Changes current-color from 'red to 'green, 'green to 'yellow,
+ ;;or 'yellow to 'red depending on what the current-color is. Returns true.
+ (define (next)
+ (local ((define previous-color current-color))
+ (begin (set! current-color (next-color current-color))
+ (switch previous-color current-color x-posn))))
+
+ ;next-color : TL-color -> TL-color
+ ;Given acolor, returns the next logical color.
+ (define (next-color acolor)
+ (cond
+ [(symbol=? acolor 'red) 'green]
+ [(symbol=? acolor 'yellow) 'red]
+ [(symbol=? acolor 'green) 'yellow]))
+
+ ;;init-current-color : -> true
+ ;;Opens the canvas and draws the outline of the 3 traffic light
+ ;;bulbs as well as lighting up the red lightbulb.
+ (define (init-traffic-light)
+ (begin (draw-border x-posn)
+ (clear-bulb current-color x-posn)
+ (set! current-color 'red)
+ (fill-bulb current-color x-posn)))
+ (define (service-manager msg)
+ (cond
+ [(symbol=? msg 'next) (next)]
+ [(symbol=? msg 'reset) (init-traffic-light)]
+ [else (error 'service-manager "message not understood")])))
+ (begin (init-traffic-light)
+ service-manager))))
+
+#|
+
+(start WIDTH HEIGHT)
+(define lights
+ (list (make-traffic-light 'AdobeCircle 50)
+ (make-traffic-light 'Pereira 200)
+ (make-traffic-light 'CampusDr 350)
+ (make-traffic-light 'HarvardSt 500)
+ (make-traffic-light 'BrenRd 650)
+ (make-traffic-light 'UniversityBlvd 800)))
+
+
+;;Controller
+
+(define (next-callback event)
+ (andmap (lambda (a-light) (a-light 'next)) lights))
+
+(define (reset-callback event)
+ (andmap (lambda (a-light) (a-light 'reset)) lights))
+
+(define next-buttons
+(build-list (length lights)
+ (lambda (n)
+ (local ((define (next-indiv-callback event)
+ ((list-ref lights n) 'next)))
+ (make-button (number->string (add1 n)) next-indiv-callback)))))
+
+(create-window (list (list (make-button "Next" next-callback)
+ (make-button "Reset" reset-callback))
+ next-buttons))
+
+|#
\ No newline at end of file
blob - /dev/null
blob + cbc40497bc97dcae1eaf406b6ff06c5730d9f589 (mode 644)
--- /dev/null
+++ 39.2.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |39.2|) (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")))))
+#|
+Exercise 39.2.3. Develop make-hangman. The program consumes a list of words, creates a hangman game using the list, and produces the hangman-guess function as a result. A player would use the dialogue as follows:
+
+> (define hangman-easy (make-hangman (list 'a 'an 'and 'able 'adler)))
+> (define hangman-difficult (make-hangman (list 'ardvark ...)))
+> (hangman-easy 'a)
+"You won"
+> (hangman-difficult 'a)
+(list 'head (list '_ '_ '_ '_ '_ '_))
+> ...
+
+Compare this with the first dialogue in section 37.2.
+|#
+
+;Data Definitions
+;
+;;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+;
+;A hangman-interface is an interface
+;1. 'guess -> (letter -> response)
+;2. 'reveal -> ( -> word)
+;
+;
+;;A response is either
+;; 1. "You won"
+;; 2. (list "The End" body-part word)
+;; 3. (list "Good guess!" word)
+;; 4. (list "Sorry" body-part word)
+
+
+;make-hangman : (listof word) -> hangman-interface
+;;Effect: Given alow, uses the (listof word) to create the hidden, chosen words (WORDS).
+;;Output: Returns a hangman-interface, which can be used to access hangman-guess and hangman-reveal.
+
+(define (make-hangman alow)
+ (local (;;The list of potential chosen words
+ (define WORDS alow)
+ ;;The alphabet
+ (define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+ ;;The number of words
+ (define WORDS# (length WORDS))
+ ;;A body-part is one of the following symbols:
+ (define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+ ;;State Variables
+ ;;chosen-word : word
+ ;;This word is the target word that the player needs to guess
+ (define chosen-word (first WORDS))
+ ;;status-word : word
+ ;;This word represents the current status of the player's guesses
+ (define status-word (first WORDS))
+ ;;body-parts-left : (listof body-parts)
+ ;;Indicates how many body-parts are left before the hangman is dead.
+ (define body-parts-left PARTS)
+ ;;previous-guesses : word
+ ;;Keeps track of all previous guesses.
+ (define previous-guesses empty)
+ ;;new-knowledge : boolean
+ ;;Keeps track of whether or not the guessed letter adds new-knowledge.
+ (define new-knowledge false)
+ ;;letters-remaining : number
+ ;;Keeps track of the letters that still need to be uncovered.
+ (define letters-remaining (length chosen-word))
+
+ ;make-status-word : word -> word
+ ;Given aword, creates an equally long word consisting only of the letter '_.
+ (define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+ ;;hangman : -> void
+ ;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+ (define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)
+ (set! previous-guesses empty)
+ (set! new-knowledge false)
+ (set! letters-remaining (length chosen-word))))
+
+ ;hangman-guess : letter -> response
+ ;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+ (define (hangman-guess aletter)
+ (local ((define updated-status (reveal-word chosen-word status-word aletter)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [new-knowledge (begin (set! status-word updated-status)
+ (set! letters-remaining (sub1 letters-remaining))
+ (cond
+ [(zero? letters-remaining) "You won"]
+ [else (list "Good guess!" status-word)]))]
+ [else
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]))])))
+
+ ;reveal-word: word word letter -> word
+ ;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+ (define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(and (symbol=? chosen-letter aletter)
+ (symbol=? status-letter '_))
+ (begin (set! new-knowledge true)
+ aletter)]
+ [else status-letter])))
+ (begin (set! new-knowledge false)
+ (map reveal-letter chosen-word status-word))))
+
+ ;contains : (listof X) X -> boolean
+ ;Determine if alox contains anx
+ (define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+ (define (service-manager msg)
+ (cond
+ [(equal? msg 'guess) hangman-guess]
+ [(equal? msg 'reveal) chosen-word]
+ [else (error 'make-hangman "msg not understood")])))
+ (begin (hangman)
+ service-manager)))
+
+(define my-hangman (make-hangman '((f a r m e r)
+ (p l a n t e r)
+ (t r a c t o r)
+ (s e e d s)
+ (l i v e s t o c k))))
\ No newline at end of file
blob - /dev/null
blob + cb5bc27ecdb5a0db448f1c0ac0682ef1de9f025c (mode 644)
--- /dev/null
+++ 39.2.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |39.2|) (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")))))
+;;Model
+
+;A word is a (listof letters) where letters is a symbol from 'a ... 'z and '_.
+
+;;Constants
+
+(define WORDS '((o c t o p u s)
+ (s q u i d)
+ (s a l m o n)
+ (t i l a p i a)
+ (b a s s)
+ (s h r i m p)
+ (c l a m s)
+ (m u s s e l)
+ (o y s t e r)
+ (c r a b)
+ (s t a r f i s h)
+ (j e l l y f i s h)
+ (s e a l i o n)
+ (t u n a)
+ (d o l p h i n)
+ (w h a l e)
+ (k e l p)
+ (m a n a t e e)))
+
+;;The alphabet
+(define LETTERS '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
+
+;;The number of words
+(define WORDS# (length WORDS))
+
+;;A body-part is one of the following symbols:
+(define PARTS '(noose head body right-arm left-arm right-leg left-leg))
+
+;;State Variables
+
+;;chosen-word : word
+;;This word is the target word that the player needs to guess
+
+(define chosen-word (first WORDS))
+
+;;status-word : word
+;;This word represents the current status of the player's guesses
+
+(define status-word (first WORDS))
+
+;;body-parts-left : (listof body-parts)
+;;Indicates how many body-parts are left before the hangman is dead.
+
+(define body-parts-left PARTS)
+
+;;previous-guesses : word
+;;Keeps track of all previous guesses.
+
+(define previous-guesses empty)
+
+;;new-knowledge : boolean
+;;Keeps track of whether or not the guessed letter adds new-knowledge.
+
+(define new-knowledge false)
+
+;;letters-remaining : number
+;;Keeps track of the letters that still need to be uncovered.
+
+(define letters-remaining (length chosen-word))
+
+;make-status-word : word -> word
+;Given aword, creates an equally long word consisting only of the letter '_.
+
+(define (make-status-word aword)
+ (build-list (length aword) (lambda (x) '_)))
+
+;;hangman : -> void
+;;Initiates the hangman program by selecting the chosen word and resetting the status word and the number of body-parts left.
+
+(define (hangman)
+ (begin (set! chosen-word (list-ref WORDS (random WORDS#)))
+ (set! status-word (make-status-word chosen-word))
+ (set! body-parts-left PARTS)
+ (set! previous-guesses empty)
+ (set! new-knowledge false)
+ (set! letters-remaining (length chosen-word))))
+
+;;Initializes the state variables
+(hangman)
+
+;A response is either
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+;hangman-guess : letter -> response
+;If aletter is present in chosen-word but not in status-word, (effect) update status-word. Otherwise, shorten body-part-list. In all cases, output one of the four possible responses. Also effect the update of previous-guesses.
+
+(define (hangman-guess aletter)
+ (local ((define updated-status (reveal-word chosen-word status-word aletter)))
+ (cond
+ [(contains previous-guesses aletter) "You have used this guess before."]
+ [else
+ (begin
+ (set! previous-guesses (cons aletter previous-guesses))
+ (cond
+ [new-knowledge (begin (set! status-word updated-status)
+ (set! letters-remaining (sub1 letters-remaining))
+ (cond
+ [(zero? letters-remaining) "You won"]
+ [else (list "Good guess!" status-word)]))]
+ [else
+ (local ((define lost-part (first body-parts-left)))
+ (begin (set! body-parts-left (rest body-parts-left))
+ (cond
+ [(empty? body-parts-left) (list "The End" lost-part chosen-word)]
+ [else (list "Sorry" lost-part status-word)])))]))])))
+
+;reveal-word: word word letter -> word
+;Given chosen-word, status-word, and aletter, return an updated status-word where '_ is replaced by aletter for all letters in chosen-word that are aletter.
+
+(define (reveal-word chosen-word status-word aletter)
+ (local ((define (reveal-letter chosen-letter status-letter)
+ (cond
+ [(and (symbol=? chosen-letter aletter)
+ (symbol=? status-letter '_))
+ (begin (set! new-knowledge true)
+ aletter)]
+ [else status-letter])))
+ (begin (set! new-knowledge false)
+ (map reveal-letter chosen-word status-word))))
+
+;contains : (listof X) X -> boolean
+;Determine if alox contains anx
+(define (contains alox anx)
+ (ormap (lambda (x) (equal? x anx)) alox))
+;Exercise 37.2.4. Formulate the four examples for hangman-guess as boolean-valued expressions that produce true if hangman-guess is correct. Develop an additional example for each case; turn these new examples into additional tests. Solution
+
+#|
+;Tests
+;test-hangman : letter word X -> boolean
+;Tests hangman-guess and returns true if the test is successful. Consumes guess (a letter), status (a word), partsleft (listof body-parts), and response (one of the four responses).
+(define (test-hangman guess status partsleft response)
+ (begin (set! chosen-word '(b a l l))
+ (set! status-word status)
+ (set! body-parts-left partsleft)
+ (equal? (hangman-guess guess) response)))
+
+
+
+(and (test-hangman 'l '(b _ _ _) '(arm leg) '("Good guess!" (b _ l l)))
+ (equal? status-word '(b _ l l)))
+(test-hangman 'a '(b _ l l) '(arm leg) "You won")
+(and (test-hangman 'l '(b _ l l) '(right-leg left-leg) '("Sorry" right-leg (b _ l l)))
+ (equal? body-parts-left '(left-leg)))
+(and (test-hangman 'l '(b _ l l) '(left-leg) '("The End" (b a l l)))
+ (equal? body-parts-left empty))
+|#
+
+;;View
+
+;word->string : word -> string
+;Given a word, convert it to a string.
+
+(define (word->string aword)
+ (foldr string-append "" (map (lambda (aletter) (symbol->string aletter)) aword)))
+
+;;GUI-items
+(define guess-message (make-message "Guess: "))
+(define guess-choice (make-choice (map (lambda (aletter) (symbol->string aletter)) LETTERS)))
+(define status-message (make-message "Status: "))
+(define status-word-message (make-message (word->string status-word)))
+(define result-message (make-message "Let's play hangman!"))
+(define body-part-message (make-message ""))
+
+;;Controller
+
+; 1. "You won"
+; 2. (list "The End" body-part word)
+; 3. (list "Good guess!" word)
+; 4. (list "Sorry" body-part word)
+
+
+(define (check-call-back event)
+ (local ((define response (hangman-guess (list-ref LETTERS (choice-index guess-choice)))))
+ (cond
+ [(string? response) (and (draw-message result-message response)
+ (draw-message status-word-message (word->string status-word)))]
+ [(= (length response) 2)
+ (and (draw-message result-message (first response))
+ (draw-message status-word-message (word->string (second response))))]
+ [(and (draw-message result-message (first response))
+ (draw-message body-part-message (symbol->string (second response)))
+ (draw-message status-word-message (word->string (third response)))
+ (draw-next-part (second response)))
+ (cond
+ [(empty? body-parts-left)
+ (begin (hangman)
+ (draw-message status-message "Chosen Word:"))]
+ [else true])])))
+
+(define check-button (make-button "Check" check-call-back))
+
+(create-window
+ (list (list guess-message guess-choice check-button)
+ (list status-message status-word-message)
+ (list result-message body-part-message)))
+
+(define CWIDTH 300)
+(define CHEIGHT 300)
+(start CWIDTH CHEIGHT)
+
+; draw-next-part : symbol -> boolean
+; Draws the next part given the name of the part. Returns true if
+; drawing is successful.
+
+(define (draw-next-part part)
+ (local ((define XCENTER (/ CWIDTH 2))
+ (define COLORHEAD 'brown)
+ (define COLORBODY 'purple)
+ (define COLORARMS 'brown)
+ (define COLORLEGS 'red)
+ (define (draw-noose)
+ (and (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 10)))
+ (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
+ (make-posn XCENTER (/ CHEIGHT 5)))))
+ (define (draw-head)
+ (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD))
+ (define (draw-body)
+ (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
+ (make-posn XCENTER (* CHEIGHT 3/4))
+ COLORBODY))
+ (define (draw-right-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-left-arm)
+ (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
+ (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
+ COLORARMS))
+ (define (draw-right-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
+ COLORLEGS))
+ (define (draw-left-leg)
+ (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
+ (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
+ COLORLEGS)))
+ (cond
+ [(symbol=? part 'noose) (draw-noose)]
+ [(symbol=? part 'head) (draw-head)]
+ [(symbol=? part 'body) (draw-body)]
+ [(symbol=? part 'right-arm) (draw-right-arm)]
+ [(symbol=? part 'left-arm) (draw-left-arm)]
+ [(symbol=? part 'right-leg) (draw-right-leg)]
+ [(symbol=? part 'left-leg) (draw-left-leg)])))
+
+#|
+;Tests reveal-word given cw, sw, aletter, expected, and new?.
+
+(define (test-reveal-word cw sw aletter expected new?)
+ (begin (set! chosen-word cw)
+ (set! status-word sw)
+ (and (equal? (reveal-word cw sw aletter) expected)
+ (equal? new? new-knowledge))))
+
+;If status-word is (list 'b '_ 'l 'l) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'a)
+;produces (list 'b 'a 'l 'l) and new-knowledge is true.
+
+(test-reveal-word '(b a l l) '(b _ l l) 'a '(b a l l) true)
+
+;If status-word is (list 'b '_ '_ '_) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'x)
+;produces (list 'b '_ '_ '_) and new-knowledge is false.
+
+(test-reveal-word '(b a l l) '(b _ _ _) 'x '(b _ _ _) false)
+
+;If status-word is (list 'b '_ '_ '_) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'l)
+;produces (list 'b '_ 'l 'l) and new-knowledge is true.
+
+(test-reveal-word '(b a l l) '(b _ _ _) 'l '(b _ l l) true)
+
+;Finally, if status-word is (list 'b '_ 'l 'l) and chosen-word is (list 'b 'a 'l 'l), then evaluating
+;(reveal-one chosen-word status-word 'l)
+;produces (list 'b '_ 'l 'l) and new-knowledge is false.
+
+(test-reveal-word '(b a l l) '(b _ l l) 'l '(b _ l l) false)
+
+|#
\ No newline at end of file
blob - /dev/null
blob + eefa665b2ae6280665e1d56e366b5c2135735053 (mode 644)
--- /dev/null
+++ 4.2.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.2.3) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; equation1 : number -> boolean
+;; See if n is a solution to 4*n + 2 = 62
+
+(define (equation1 n)
+ (= (+ (* 4 n) 2) 62))
\ No newline at end of file
blob - /dev/null
blob + 155271781add43beb0fff8d83869113d60bce327 (mode 644)
--- /dev/null
+++ 4.2.3.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.2.3) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; equation1 : number -> boolean
+;; See if n is a solution to 4*n + 2 = 62
+
+(define (equation1 n)
+ (= (+ (* 4 n) 2) 62))
+
+;; equation2 : number -> boolean
+;; See if n is a solution to 2*n^2 = 102
+
+(define (equation2 n)
+ (= (* 2 (sqr n)) 102))
+
+;; equation3 : number -> boolean
+;; Test if n is a solution to 4*n^2 + 6*n + 2 = 462
+
+(define (equation3 n)
+ (= (+
+ (* 4 (sqr n))
+ (* 6 n)
+ 2)
+ 462))
\ No newline at end of file
blob - /dev/null
blob + d90cbb7a2331ee5ef8d0bbc0d1d3dcb35fd19684 (mode 644)
--- /dev/null
+++ 4.4.1.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.1) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define BRACKET2 1000)
+(define BRACKET3 5000)
+(define BRACKETINT1 4)
+(define BRACKETINT2 4.5)
+(define BRACKETINT3 5)
+
+;; interest-rate : number -> number
+;; Given amount, it computes the interest rate
+;; Divides the amount into brackets by using BRACKET2 and BRACKET3
+;; Gives the interest rate based on where the value falls between the two brackets
+;; BRACKETINT1, BRACKETINT2, BRACKETINT3 (bracket interest - the interest rate for
+;; a given bracket)
+
+(define (interest-rate amount)
+ (cond
+ [(<= amount BRACKET2) BRACKETINT1]
+ [(<= amount BRACKET3) BRACKETINT2]
+ [(> amount BRACKET3) BRACKETINT3]))
blob - /dev/null
blob + f5537f6e1fcc930ce4aff5cd93a3441a6494da70 (mode 644)
--- /dev/null
+++ 4.4.1.scm
+(define BRACKET2 1000)
+(define BRACKET3 5000)
+(define BRACKETINT1 0.04)
+(define BRACKETINT2 0.045)
+(define BRACKETINT3 0.05)
+
+;; interest-rate : number -> number
+;; Given amount, it computes the interest rate
+;; Divides the amount into brackets by using BRACKET2 and BRACKET3
+;; Gives the interest rate based on where the value falls between the two brackets
+;; BRACKETINT1, BRACKETINT2, BRACKETINT3 (bracket interest - the interest rate for
+;; a given bracket)
+
+(define (interest-rate amount)
+ (cond
+ [(<= amount BRACKET2) BRACKETINT1]
+ [(<= amount BRACKET3) BRACKETINT2]
+ [(> amount BRACKET3) BRACKETINT3]))
+
+;; interest : number -> number
+;; Given the amount, calculates the total interest by multiplying the amount
+;; by the interest-rate
+
+(define (interest amount)
+ (* amount (interest-rate amount)))
\ No newline at end of file
blob - /dev/null
blob + 8572ad1d1087daa0c6d54a59d7bb2852e6e106b3 (mode 644)
--- /dev/null
+++ 4.4.2.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.2) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define BRACKET2 1000)
+(define BRACKET3 5000)
+(define BRACKETINT1 0.04)
+(define BRACKETINT2 0.045)
+(define BRACKETINT3 0.05)
+
+;; interest-rate : number -> number
+;; Given amount, it computes the interest rate
+;; Divides the amount into brackets by using BRACKET2 and BRACKET3
+;; Gives the interest rate based on where the value falls between the two brackets
+;; BRACKETINT1, BRACKETINT2, BRACKETINT3 (bracket interest - the interest rate for
+;; a given bracket)
+
+(define (interest-rate amount)
+ (cond
+ [(<= amount BRACKET2) BRACKETINT1]
+ [(<= amount BRACKET3) BRACKETINT2]
+ [(> amount BRACKET3) BRACKETINT3]))
+
+;; interest : number -> number
+;; Given the amount, calculates the total interest by multiplying the amount
+;; by the interest-rate
+
+(define (interest amount)
+ (* amount (interest-rate amount)))
\ No newline at end of file
blob - /dev/null
blob + 87770daa721a124079e3d77504eac90e148c60de (mode 644)
--- /dev/null
+++ 4.4.2.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.2) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define BRACKET2 240)
+(define BRACKET3 480)
+(define BRACKETRATE1 0.00)
+(define BRACKETRATE2 0.15)
+(define BRACKETRATE3 0.28)
+
+;; tax-rate : number -> number
+;; Given amount, it computes the tax rate
+;; Divides the amount into brackets by using BRACKET2 and BRACKET3
+;; Gives the tax rate based on where the value falls between the two brackets
+;; BRACKETRATE1, BRACKETRATE2, BRACKETRATE3 (bracket rate - the tax rate for
+;; a given bracket)
+
+(define (tax-rate amount)
+ (cond
+ [(<= amount BRACKET2) BRACKETRATE1]
+ [(<= amount BRACKET3) BRACKETRATE2]
+ [(> amount BRACKET3) BRACKETRATE3]))
+
+;; tax : number -> number
+;; Given the amount, calculates the total tax by multiplying the amount
+;; by the tax-rate
+
+(define (tax amount)
+ (* amount (tax-rate amount)))
\ No newline at end of file
blob - /dev/null
blob + 6ebb185cd84236ba0310d5fa05da7da63cda4680 (mode 644)
--- /dev/null
+++ 4.4.3.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.3) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define BRACKET2 240)
+(define BRACKET3 480)
+(define BRACKETRATE1 0.00)
+(define BRACKETRATE2 0.15)
+(define BRACKETRATE3 0.28)
+
+;; tax-rate : number -> number
+;; Given amount, it computes the tax rate
+;; Divides the amount into brackets by using BRACKET2 and BRACKET3
+;; Gives the tax rate based on where the value falls between the two brackets
+;; BRACKETRATE1, BRACKETRATE2, BRACKETRATE3 (bracket rate - the tax rate for
+;; a given bracket)
+
+(define (tax-rate amount)
+ (cond
+ [(<= amount BRACKET2) BRACKETRATE1]
+ [(<= amount BRACKET3) BRACKETRATE2]
+ [(> amount BRACKET3) BRACKETRATE3]))
+
+;; tax : number -> number
+;; Given the amount, calculates the total tax by multiplying the amount
+;; by the tax-rate
+
+(define (tax amount)
+ (* amount (tax-rate amount)))
\ No newline at end of file
blob - /dev/null
blob + 1f419bbf547a64b47be82dbb3549e082331ef9d1 (mode 644)
--- /dev/null
+++ 4.4.3.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.3) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+(define BRACKET2 500)
+(define BRACKET3 1500)
+(define BRACKET4 2500)
+(define BRACKETRATE1 0.0025)
+(define BRACKETRATE2 0.0050)
+(define BRACKETRATE3 0.0075)
+(define BRACKETRATE4 0.0100)
+
+;; pay-back : number -> number
+;; Calculates the pay back rate based on the charge on the credit card
+
+(define (pay-back charges)
+ (cond
+ [(<= charges BRACKET2) (* BRACKETRATE1 charges)]
+ [(<= charges BRACKET3) (+
+ (* BRACKETRATE2 (- charges BRACKET2))
+ (* BRACKETRATE1 BRACKET2))]
+ [(<= charges BRACKET4) (+
+ (* BRACKETRATE3 (- charges BRACKET3))
+ (* BRACKETRATE2 (- BRACKET3 BRACKET2))
+ (* BRACKETRATE1 BRACKET2))]
+ [(> charges BRACKET4) (+
+ (* BRACKETRATE4 (- charges BRACKET4))
+ (* BRACKETRATE3 (- BRACKET4 BRACKET3))
+ (* BRACKETRATE2 (- BRACKET3 BRACKET2))
+ (* BRACKETRATE1 BRACKET2))]))
blob - /dev/null
blob + 6a20c26f07db9dc4ac7b9798f2b52a5ac361fc14 (mode 644)
--- /dev/null
+++ 4.4.4.bak
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.4) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;;
\ No newline at end of file
blob - /dev/null
blob + 06a8efabae76d4666e9df6908e0ba4db1cc2da6d (mode 644)
--- /dev/null
+++ 4.4.4.scm
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-beginner-reader.ss" "lang")((modname 4.4.4) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
+;; how-many : number number number -> number
+;; Determines how many solutions a given quadratic equation has given
+;; coefficients a, b, and c.
+
+(define (how-many a b c)
+ (cond
+ [(= a 0) 'degenerate]
+ [(> (sqr b) (* 4 a c)) 2]
+ [(= (sqr b) (* 4 a c)) 1]
+ [(< (sqr b) (* 4 a c)) 0]))
\ No newline at end of file
blob - /dev/null
blob + 9ce29d7affb2dd48652cb62e792b0a3cb6a33910 (mode 644)
--- /dev/null
+++ 40.1.3
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |40.1|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp")))))
+#|
+Exercise 40.1.3. Show how to implement the following structure definitions as functions:
+
+ 1. (define-struct movie (title producer))
+ 2. (define-struct boyfriend (name hair eyes phone))
+ 3. (define-struct cheerleader (name number))
+ 4. (define-struct CD (artist title price))
+ 5. (define-struct sweater (material size producer))
+
+Pick one and demonstrate that the expected laws hold. Solution
+|#
+
+(define (make-movie title producer)
+ (local ((define title0 title)
+ (define producer0 producer)
+ (define (service-manager msg)
+ (cond
+ [(equal? msg 'title) title0]
+ [(equal? msg 'producer) producer0])))
+ service-manager))
+
+(define (movie-title amovie)
+ (amovie 'title))
+
+(define (movie-producer amovie)
+ (amovie 'producer))
+
+(define SciFi (make-movie 'StarWars 'GeorgeLucas))
+(movie-title SciFi)
+(movie-producer SciFi)
+
+(define (make-boyfriend name hair eyes phone)
+ (lambda (selector)
+ (selector name hair eyes phone)))
+(define (boyfriend-name aboyfriend)
+ (aboyfriend (lambda (name hair eyes phone) name)))
+(define (boyfriend-hair aboyfriend)
+ (aboyfriend (lambda (name hair eyes phone) hair)))
+(define (boyfriend-eyes aboyfriend)
+ (aboyfriend (lambda (name hair eyes phone) eyes)))
+(define (boyfriend-phone aboyfriend)
+ (aboyfriend (lambda (name hair eyes phone) phone)))
+
+(define Aaron (make-boyfriend 'Aaron 'black 'black 715))
+(boyfriend-name Aaron)
+(boyfriend-hair Aaron)
+(boyfriend-eyes Aaron)
+(boyfriend-phone Aaron)
+
+(define (make-cheerleader name number)
+ (lambda (selector)
+ (selector name number)))
+(define (cheerleader-name acheerleader)
+ (acheerleader (lambda (name number) name)))
+
+(define (cheerleader-number acheerleader)
+ (acheerleader (lambda (name number) number)))
+
+(define Abbo (make-cheerleader 'Abbo 53535))
+(cheerleader-name Abbo)
+(cheerleader-number Abbo)
+
+(define (make-CD artist title price)
+ (local ((define artist0 artist)
+ (define title0 title)
+ (define price0 price)
+ (define (service-manager msg)
+ (cond
+ [(equal? msg 'artist) artist0]
+ [(equal? msg 'title) title0]
+ [(equal? msg 'price) price0])))
+ service-manager))
+
+(define (CD-artist aCD)
+ (aCD 'artist))
+
+(define (CD-title aCD)
+ (aCD 'title))
+
+(define (CD-price aCD)
+ (aCD 'price))
+
+(define BeeGees (make-CD 'BeeGees 'SaturdayNightFever 9.99))
+(CD-artist BeeGees)
+(CD-title BeeGees)
+(CD-price BeeGees)
+
+(define (make-sweater material size producer)
+ (lambda (selector)
+ (selector material size producer)))
+(define (sweater-material asweater)
+ (asweater (lambda (material size producer) material)))
+(define (sweater-size asweater)
+ (asweater (lambda (material size producer) size)))
+(define (sweater-producer asweater)
+ (asweater (lambda (material size producer) producer)))
+
+(define YellowJacket (make-sweater 'Cotton 'Large 'Unknown))
+(sweater-material YellowJacket)
+(sweater-size YellowJacket)
+(sweater-producer YellowJacket)
blob - /dev/null
blob + 5f0c8947536ca5d049fcfa7bc230ffc25a1ed27a (mode 644)
--- /dev/null
+++ 40.1.3~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |40.1|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp")))))
+Exercise 40.1.3. Show how to implement the following structure definitions as functions:
+
+ 1.
+
+ (define-struct movie (title producer))
+ 2.
+
+ (define-struct boyfriend (name hair eyes phone))
+ 3.
+
+ (define-struct cheerleader (name number))
+ 4.
+
+ (define-struct CD (artist title price))
+ 5.
+
+ (define-struct sweater (material size producer))
+
+Pick one and demonstrate that the expected laws hold. Solution
\ No newline at end of file
blob - /dev/null
blob + a0354a870b0f6de0855c7a807ddcfa24d9679cab (mode 644)
--- /dev/null
+++ 40.2.0
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |40.2|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp")))))
+(define (make-coord x y)
+ (local ((define x0 x)
+ (define y0 y)
+ (define (service-manager msg)
+ (cond
+ [(equal? msg 'x) x0]
+ [(equal? msg 'y) y0]
+ [(equal? msg 'set-x) (lambda (new-x) (set! x0 new-x))]
+ [(equal? msg 'set-y) (lambda (new-y) (set! y0 new-y))])))
+ service-manager))
+
+(define (coord-x acoord)
+ (acoord 'x))
+(define (coord-y acoord)
+ (acoord 'y))
+(define (coord-x! acoord new-x)
+ ((acoord 'set-x) new-x))
+(define (coord-y! acoord new-y)
+ ((acoord 'set-y) new-y))
+(define acoord (make-coord 4 5))
+(coord-x acoord)
+(coord-y acoord)
+(coord-x! acoord 3)
+(coord-x acoord)
+(coord-y! acoord 1)
+(coord-y acoord)
+
+(define (make-boyfriend name hair eyes phone)
+ (local ((define name0 name)
+ (define hair0 hair)
+ (define eyes0 eyes)
+ (define phone0 phone)
+ (define (service-manager msg)
+ (cond
+ [(symbol=? msg 'name) name0]
+ [(symbol=? msg 'hair) hair0]
+ [(symbol=? msg 'eyes) eyes0]
+ [(symbol=? msg 'phone) phone0]
+ [(symbol=? msg 'set-name) (lambda (new-name) (set! name0 new-name))]
+ [(symbol=? msg 'set-hair) (lambda (new-hair) (set! hair0 new-hair))]
+ [(symbol=? msg 'set-eyes) (lambda (new-eyes) (set! eyes0 new-eyes))]
+ [(symbol=? msg 'set-phone) (lambda (new-phone) (set! phone0 new-phone))])))
+ service-manager))
+(define (boyfriend-name aboyfriend)
+ (aboyfriend 'name))
+(define (boyfriend-hair aboyfriend)
+ (aboyfriend 'hair))
+(define (boyfriend-eyes aboyfriend)
+ (aboyfriend 'eyes))
+(define (boyfriend-phone aboyfriend)
+ (aboyfriend 'phone))
+(define (boyfriend-name! aboyfriend new-name)
+ ((aboyfriend 'set-name) new-name))
+(define (boyfriend-hair! aboyfriend new-hair)
+ ((aboyfriend 'set-hair) new-hair))
+(define (boyfriend-eyes! aboyfriend new-eyes)
+ ((aboyfriend 'set-eyes) new-eyes))
+(define (boyfriend-phone! aboyfriend new-phone)
+ ((aboyfriend 'set-phone) new-phone))
+
+(define Aaron (make-boyfriend 'Aaron 'dark-brown 'black 646))
+(boyfriend-name! Aaron 'Arone)
+(boyfriend-hair! Aaron 'black)
+(boyfriend-eyes! Aaron 'gray)
+(boyfriend-phone! Aaron 545)
+(boyfriend-name Aaron)
+(boyfriend-hair Aaron)
+(boyfriend-eyes Aaron)
+(boyfriend-phone Aaron)
\ No newline at end of file
blob - /dev/null
blob + dc4b33383f29920ed3a3d9b24032aedc8743e9ef (mode 644)
--- /dev/null
+++ 40.2.0~
+(define (make-posn x y)
+ (local ((define x0 x)
+ (define y0 y)
+ (define (service-manager msg)
+ (cond
+ [(equal? msg 'x) x0]
+ [(equal? msg 'y) y0]
+ [(equal? msg 'set-x) (lambda (new-x) (set! x0 new-x))]
+ [(equal? msg 'set-y) (lambda (new-y) (set! y0 new-y))])))
+ service-manager))
\ No newline at end of file
blob - /dev/null
blob + a85235c5709e059c4e9acefc91bc0172c5e446e0 (mode 644)
--- /dev/null
+++ 40.2.2
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |40.2|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp")))))
+(define (make-coord x y)
+ (local ((define x0 x)
+ (define y0 y)
+ (define (set-x new-x) (set! x0 new-x))
+ (define (set-y new-y) (set! y0 new-y)))
+ (lambda (op)
+ (op x0 y0 set-x set-y))))
+
+(define (coord-x acoord)
+ (acoord (lambda (x1 y1 set-x1 set-y1) x1)))
+(define (coord-y acoord)
+ (acoord (lambda (x1 y1 set-x1 set-y1) y1)))
+(define (coord-x! acoord new-x1)
+ (acoord (lambda (x1 y1 set-x1 set-y1) (set-x1 new-x1))))
+(define (coord-y! acoord new-y1)
+ (acoord (lambda (x1 y1 set-x1 set-y1) (set-y1 new-y1))))
+
+(define acoord (make-coord 5 6))
+(coord-x! acoord 3)
+(coord-y! acoord 2)
+(coord-x acoord)
+(coord-y acoord)
\ No newline at end of file
blob - /dev/null
blob + ba263ecdfbc8a2458e3b4bd1793938325c04e7d9 (mode 644)
--- /dev/null
+++ 40.2.2~
+;; The first three lines of this file were inserted by DrScheme. They record metadata
+;; about the language level of this file in a form that our tools can easily process.
+#reader(lib "htdp-advanced-reader.ss" "lang")((modname |40.2|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp")))))
+(define (make-coord x y)
+ (local ((define x0 x)
+ (define y0 y)
+ (define (set-x new-x) (set! x0 new-x))
+ (define (set-y new-y) (set! y0 new-y)))
+ (lambda (op)
+ (op x y set-x set-y))))
+
+(define (coord-x acoord)
+ (acoord (lambda (x y set-x set-y) x)))
+(define (coord-y acoord)
+ (acoord (lambda (x y set-x set-y) y)))
+(define (coord-x! acoord new-x)
+ (acoord (lambda (x y set-x set-y) (set-x new-x))))
+(define (coord-y! acoord new-y)
+ (acoord (lambda (x y set-x set-y) (set-y new-y))))
+
+(define acoord (make-coord 5 6))
+(coord-x! acoord 3)
+(coord-y! acoord 2)
+(coord-x acoord)
+(coord-y acoord)
+
+#|
+Demonstrate how to modify a structure like (ffm-make-posn 3 4) so that its y field contains 5. Solution
+|#
\ No newline at end of file