Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary CPSC 110 PSET 7 SOLUTION

Rating
-
Sold
4
Pages
6
Uploaded on
11-07-2021
Written in
2020/2021

CPSC 110 PSET 7 SOLUTION

Content preview

;; The first three lines of this file were inserted by DrRacket. 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 pset-07-solution) (read-
case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-
decimal #f #t none #f () #t)))
;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE.
;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
;; PARTNER.
;;
(require spd/tags)

(@assignment pset-07); Do not edit or remove this tag

(@problem 1)

(@htdd Letters)
;; Letters is one of:
;; - empty
;; - (cons String Letters)
;; interp. a sequence of letters
;; CONSTRAINT: every string in the sequence is only one letter

(define L1 empty)
(define L2 (list "a" "B" "c"))

(@htdd Operations)
;; Operations is one of:
;; - empty
;; - (cons "keep" Operations)
;; - (cons "space" Operations)
;; - (cons "remove" Operations)
;; interp. a sequence of operations to apply to a sequence of letters
;; "keep" means keep the letter
;; "space" means replace the letter with a space
;; "remove" means remove the letter

(@htdf decoder)
(@signature Letters Operations -> String)
;; produce string containing letters in l with operations applied
(check-expect (decoder empty empty) "")
(check-expect (decoder empty (list "keep")) "")
(check-expect (decoder empty (list "space")) "")
(check-expect (decoder empty (list "remove")) "")
(check-expect (decoder (list "h" "i") empty) "hi")
(check-expect (decoder (list "h" "o" "w") (list "keep" "keep" "keep"))
"how")
(check-expect (decoder (list "o" "h") (list "space" "space"))
" ")
(check-expect (decoder (list "a" "d" "d") (list "remove" "remove"))
"d")
(check-expect (decoder (list "i" "k" "l" "h" "a" "m" "k" "s" "a" "r" "m")
(list "keep" "remove" "remove" "space" "keep" "keep"
"space" "keep" "keep" "remove" "keep"))
"i am sam")

(check-expect (decoder (list "e" "s" "r" "a" "m" "d" "i" "f" "a" "m")
(list "remove" "keep" "remove" "keep" "keep" "space"

, "keep" "space"))
"sam i am")


#|
CROSS PRODUCT OF TYPE-COMMENTS TABLE

\ | |
\ l-> | empty | (cons String Letters)
ops \ | |
____V_____________\__|________________|__________________________________
| |
empty | | (string-append (first l) ;(2)
| | (decoder (rest l)
| | empty))
_____________________| |_____________________________________
| |
(cons "keep" | | (string-append (first l) ;(3)
Operations) | | (decoder (rest l)
| | (rest ops)))
_____________________| "" ;(1) |_____________________________________
| |
(cons "space" | | (string-append " " ;(4)
Operations) | | (decoder (rest l)
| | (rest ops)))
_____________________| |_____________________________________
| |
(cons "remove" | | (decoder (rest l) (rest ops)) ;(5)
Operations) | |
|#

(@template 2-one-of)

(define (decoder l ops)
(cond [(empty? l) ""] ;(1)
[(empty? ops) ;(2)
(string-append (first l)
(decoder (rest l)
empty))]
[(string=? "keep" (first ops)) ;(3)
(string-append (first l)
(decoder (rest l)
(rest ops)))]
[(string=? "space" (first ops)) ;(4)
(string-append " "
(decoder (rest l)
(rest ops)))]
[else ;(5)
(decoder (rest l)
(rest ops))]))


;;
;; Problems 2-7.
;; Below is our solution for problem one in Problem Set 6. Problems
;; 2-7 are included in this, asking you to improve the PS6 solution
;; in various ways.
;;

Document information

Uploaded on
July 11, 2021
Number of pages
6
Written in
2020/2021
Type
SUMMARY
CA$30.47
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
travissmith1 UBC
View profile
Follow You need to be logged in order to follow users or courses
Sold
97
Member since
5 year
Number of followers
61
Documents
36
Last sold
8 months ago

3.6

16 reviews

5
6
4
6
3
0
2
0
1
4

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions