Advertisement
Guest User

I tried, sorry

a guest
Oct 23rd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. (require spd/tags)
  2. ;; DO NOT PUT ANY PERSONALLY IDENTIFYING INFORMATION IN THIS FILE.
  3. ;; YOUR COMPUTER SCIENCE IDs WILL BE SUFFICIENT TO IDENTIFY YOU
  4. ;; AND, IF YOU HAVE ONE, YOUR PARTNER
  5.  
  6. ; Computer Science 110
  7. ; 2018W1
  8. ;
  9. ; Graded Problem Set 6
  10. ;
  11. ; Computer Science id (Student 1): x1p2b
  12. ; Computer Science id (Student 2): l8k2b
  13.  
  14. ;;
  15. ;; In some of your courses, you may need to write reports on a specific
  16. ;; topic. Many reports cite other previous written reports to support
  17. ;; the ideas presented in the work, or to provide background information.
  18. ;;
  19. ;; For Problem Set 6, you will be working with a simplified version of
  20. ;; information representing a report. In this simplified version, ASSUME
  21. ;; that each report is only cited by one other report, and each report
  22. ;; can have an arbitrary number of reports it cites.
  23. ;;
  24. ;; Like any program, the first thing to think about is how to represent
  25. ;; the report information as data - specifically how to represent a single
  26. ;; report as data.
  27. ;;
  28. ;; For this problem set, each report has a title, and author, a list of
  29. ;; keywords that the report is about, and a list of other reports the
  30. ;; given report referenced (cited).
  31. ;;
  32. ;; Please carefully read through the data definition for a report provided
  33. ;; for you below. You should get out a pen and paper to trace out which
  34. ;; reports cite which other reports to better visualize the structure of
  35. ;; reports given in the examples below.
  36. ;;
  37.  
  38. (@HtDD Report ListOfReport ListOfString)
  39. (define-struct report (title author keywords cites))
  40. ;; Report is (make-report String String ListOfString ListOfReport)
  41. ;; interp. a report with a title and a single author name,
  42. ;; with a list of keywords to categorize the report,
  43. ;; and a list of other reports cited
  44.  
  45. ;; ListOfReport is one of:
  46. ;; - empty
  47. ;; - (cons Report ListOfReport)
  48. ;; interp. a list of reports
  49.  
  50. ;; ListOfString is one of:
  51. ;; - empty
  52. ;; - (cons String ListOfString)
  53. ;; interp. a list of strings
  54.  
  55. (define LOS0 empty)
  56. (define LOS1 (list "Transportation"))
  57. (define LOS2 (list "Kiczales" "Ola" "Estey"))
  58.  
  59. (define LOR0 empty)
  60. (define R0 (make-report "Public transportation vs Car2Go" "A. Lee" LOS1 empty))
  61. (define R1 (make-report "Fastest Growing Programs at UBC"
  62. "Grace Hopper"
  63. (list "Enrollment" "Higher Education" "Careers")
  64. empty))
  65. (define R2 (make-report "Apprenticeship Expectations"
  66. "Art Ison"
  67. (list "Salary")
  68. empty))
  69.  
  70. (define LOR1 (list R1 R2))
  71. (define R3 (make-report "Trade School or University"
  72. "Ed Youkaytion"
  73. (list "Employment" "Future" "Salary")
  74. LOR1))
  75. (define R4 (make-report "Best Careers for 2020 and Beyond"
  76. "Grace Hopper"
  77. (list "Employment" "Salary" "Careers")
  78. (list R3)))
  79.  
  80. (define R5 (make-report "DOTA2: $25 Million on the Line"
  81. "IceFrog"
  82. (list "E-sports" "Careers" "Video Game" "MOBA")
  83. empty))
  84. (define R6 (make-report "Canucks Promising Youngsters"
  85. "P. Bure"
  86. (list "NHL" "Prospects" "Vancouver Canucks" "Salary")
  87. empty))
  88. (define R7 (make-report "Why everyone must see Cirque du Soleil"
  89. "Holly Wood"
  90. (list "Acrobatics" "Drama" "Theatre")
  91. empty))
  92. (define R8 (make-report "Quickest Events to Sell Out"
  93. "Holly Wood"
  94. (list "Entertainment" "Events" "Sports" "Tickets")
  95. (list R5 R6 R7)))
  96. (define R9 (make-report "Vancouver Interest"
  97. "G. Robertson"
  98. (list "Vancouver" "Lower Mainland" "News and Events")
  99. (list R0 R4 R8)))
  100.  
  101. (define (fn-for-report r)
  102. (... (report-title r)
  103. (report-author r)
  104. (fn-for-los (report-keywords r))
  105. (fn-for-lor (report-cites r))))
  106.  
  107. (define (fn-for-lor lor)
  108. (cond [(empty? lor) (...)]
  109. [else
  110. (... (fn-for-report (first lor))
  111. (fn-for-lor (rest lor)))]))
  112.  
  113. (define (fn-for-los los)
  114. (cond [(empty? los) (...)]
  115. [else
  116. (... (first los)
  117. (fn-for-los (rest los)))]))
  118.  
  119. (@Problem 1)
  120. ;;
  121. ;; Assume that your instructor has tasked you with reading a report
  122. ;; AND all the reports that report has cited (and all the reports
  123. ;; those reports cite, etc). The first thing you might want to do is
  124. ;; count how many reports you'll need to read.
  125. ;;
  126. ;; Design a function that will do this for you. Given a report, the
  127. ;; function should produce a count of the number of all reports reachable
  128. ;; from that report by going through all of the cited reports.
  129. ;;
  130. ;; Remember that for all functions operating on mutually referential types,
  131. ;; you must group your function definitions in the new way.
  132.  
  133. (@HtDF report-count)
  134. (@signature Report -> Natural)
  135. ;; produce count of total reports reachable by given report
  136. (check-expect (report-count R0) 1)
  137. (check-expect (report-count R1) 1)
  138. (check-expect (report-count R8) 4)
  139. (check-expect (report-count R9) 10)
  140.  
  141. ;(define (report-count r) 0) ;stub
  142.  
  143. (@template Report)
  144. (define (report-count r)
  145. (cond [(empty? (report-cites r)) 1]
  146. [else
  147. (+ 1 (lor-count (report-cites r)))]))
  148.  
  149. (@HtDF lor-count)
  150. (@signature ListOfReport -> Natural)
  151. ;; produce first report from list of reports
  152. (check-expect (lor-count LOR0) 0)
  153. (check-expect (lor-count LOR1) 2)
  154. (check-expect (lor-count (list R1 R2 R3 R7)) 6)
  155.  
  156. (@template ListOfString)
  157. (define (lor-count lor)
  158. (cond [(empty? lor) 0]
  159. [else
  160. (+ (report-count (first lor))
  161. (lor-count (rest lor)))]))
  162.  
  163.  
  164. (@Problem 2)
  165. ;;
  166. ;; Design a function that consumes a report and a keyword, and produces
  167. ;; a list of the names of reports with the given keyword.
  168. ;;
  169. ;; FYI, there is a built-in function called member that consumes
  170. ;; a String and ListOfString and produces true if the String is
  171. ;; in the list.
  172.  
  173. (@HtDF list-report)
  174. (@signature Report -> ListOfReport)
  175. ;;takes keyword and produces list that matches reports
  176. (check-expect (list-report R1 "Careers") (list R1))
  177. (check-expect (list-report R2 "Income") empty)
  178.  
  179. ;(define (list-report r s) empty) ;stub
  180.  
  181. (@template ListOfReport)
  182. (define (list-report lor)
  183. (cond [(empty? lor) empty]
  184. [else
  185. (list (fn-for-report (first lor))
  186. (list-report (rest lor)))]))
  187.  
  188. (@template Report)
  189. (define (create-report r)
  190. (... (report-title r)
  191. (report-author r)
  192. (fn-for-los (report-keywords r))
  193. (fn-for-lor (report-cites r))))
  194.  
  195. ;(@template Report)
  196. ;(define (list-report r s)
  197. ; (if (string=? (fn-for-poop (report-keywords r)) s)
  198. ; (cons (first r) (list-report (rest r) s))
  199. ; empty))
  200. ;
  201. ;(define (list-report r s)
  202. ; (cond [(empty? r) empty]
  203. ; [else
  204. ; (if (fn-for-shit r s)
  205. ; (list (first r) (list-report (rest r) s))
  206. ; (list-report (rest r) s))]))
  207. ;
  208. ;(define (fn-for-shit r s)
  209. ; [(empty? (report-keyboards r)) empty]
  210. ; [else
  211. ; (
  212. ;
  213. ;;
  214. ;(@HtDF los-keywords)
  215. ;(@signature ListOfReport -> String)
  216. ;;; produces report upon matching keywords
  217. ;(check-expect (lor-keywords LOR0 "") empty)
  218. ;(check-expect (lor-keywords LOR1 "Salary") (list R2))
  219. ;(check-expect (lor-keywords (list R1 R2 R3 R4) "Salary") (list R2 R3 R4))
  220. ;
  221. ;;(define (los-keywords lor s) empty)
  222. ;
  223. ;(@template ListOfString)
  224. ;(define (los-keywords los)
  225. ; (cond [(empty? los) empty]
  226. ; [else
  227. ; (list (first los)
  228. ; (los-keywords (rest los)))]))
  229. ;;(define (lor-keywords lor s)
  230. ;; (cond [(empty? lor) empty]
  231. ;; [else
  232. ;; (list (first lor) (lor-keywords))
  233. ;; [(string=? (report-keywords (first lor)) s) (list (first lor) (lor-keywords (rest lor) s))]
  234. ;; [else
  235. ;; (list (lor-keywords (rest lor) s))]))
  236. ;
  237.  
  238. (@Problem 3)
  239. ;;
  240. ;; Design a function that consumes a report and a title.
  241. ;; Search the given report and all cited reports for a report with the
  242. ;; given title, and if found, produce that report.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement