;; 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 psets/pset-07); Do not edit or remove this tag
;; If you are:
;; - A 110 or 107 student replace the rst set of '???'s with your cwl.
;; For problem sets, If you have a partner, please replace the second
;; set of '???'s with their cwl. Remember this, it is what you will
;; do with these @cwl annotations for the whole course.
;; - A UBC Extended Learning student, replace the rst set of ??? with
;; your email address as con rmed in the email you received from
;; extended learning. The handin password is also in that email.
;; Remember this, it is what you will do with these @cwl annotations
;; for the whole course.
;;
(@cwl ??? ???)
(@problem 1)
;; There is a primitive type called 1String, de ned as follows:
;;
;; 1String is String
;; interp. a 1String represents a single letter
;; CONSTRAINT: any 1String is only one letter long
(@htdd ListOf1String)
;; ListOf1String is one of:
;; - empty
;; - (cons 1String ListOf1String)
;; interp. a sequence of letters
(de ne L1 empty)
(de ne 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 list of 1String
;; "keep" means keep the corresponding letter
;; "space" means replace the corresponding letter with a " "
;; "remove" means remove the corresponding letter
;;
;; In this problem you will design a function called decoder, that will
;; decode encrypted messages! Very poorly encrypted messages. The function
;; consumes a ListOf1String (l) and Operations (ops) in that order. The
;; function should produce a String which is the result of applying the
fi fi fi fi fi
, ;; given operations to the successive 1String and joining the resulting
;; letters together.
;;
;; For example:
;; (decoder (list "i" "k" "l" "h" "a" "m" "k" "s" "a" "r" "m")
;; (list "keep" "remove" "remove" "space" "keep" "keep"
;; "space" "keep" "keep" "remove"))
;;
;; should produce "i am sam"
;;
;; Notice that some of the letters were kept, some were replaced with a space,
;; and some were removed.
;;
;; If ops runs out of operations before the end of the 1String, then all
;; the remaining letters in l are kept.
;;
;; If l runs out of 1String rst, then the remaining operations in ops are
;; ignored.
;;
;; Example 2:
;; (decoder (list "f" "a" "d" "e")
;; (list "remove" "keep" "space" "keep" "remove" "keep" "space"))
;;
;; should produce "a e"
;;
;; You MUST SOLVE THIS AS A 2-ONE-OF PROBLEM and your solution must include
;; a table. You must use numbers to show the correspondence between table cells
;; and cond QA pairs. By this, we mean you should NUMBER the table cells and
;; NUMBER the corresponding cond QA pairs with the same numbers (as was done
;; in lecture). If you can simplify the table you should. Finally, it is
;; IMPERATIVE that your cond questions only include the kinds of questions that
;; the data driven template rules produce, other conditional behaviour must go
;; into the cond answers. (This is the rule about not editing template questions
;; carried over into 2-one-of problems.)
;;
(@htdf decoder) ;!!! uncomment this when you start your function design
(@signature ListOf1String Operations -> String)
;; produce a string result of applying the oper. to the strings and append them
(check-expect (decoder empty empty) "")
(check-expect (decoder (list "a") empty) "a")
(check-expect (decoder empty (list "keep")) "")
(check-expect (decoder empty (list "space")) "")
(check-expect (decoder empty (list "remove")) "")
(check-expect (decoder (list "a") (list "keep")) "a")
(check-expect (decoder (list "a") (list "remove")) "")
(check-expect (decoder (list "a") (list "space")) " ")
(check-expect (decoder (list "f" "a" "d" "e")
(list "remove" "keep" "space" "keep"
"remove" "keep" "space"))
"a e")
(check-expect (decoder (list "i" "k" "l" "h" "a" "m" "k" "s" "a" "r" "m")
fi
;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
;; PARTNER.
;;
(require spd/tags)
(@assignment psets/pset-07); Do not edit or remove this tag
;; If you are:
;; - A 110 or 107 student replace the rst set of '???'s with your cwl.
;; For problem sets, If you have a partner, please replace the second
;; set of '???'s with their cwl. Remember this, it is what you will
;; do with these @cwl annotations for the whole course.
;; - A UBC Extended Learning student, replace the rst set of ??? with
;; your email address as con rmed in the email you received from
;; extended learning. The handin password is also in that email.
;; Remember this, it is what you will do with these @cwl annotations
;; for the whole course.
;;
(@cwl ??? ???)
(@problem 1)
;; There is a primitive type called 1String, de ned as follows:
;;
;; 1String is String
;; interp. a 1String represents a single letter
;; CONSTRAINT: any 1String is only one letter long
(@htdd ListOf1String)
;; ListOf1String is one of:
;; - empty
;; - (cons 1String ListOf1String)
;; interp. a sequence of letters
(de ne L1 empty)
(de ne 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 list of 1String
;; "keep" means keep the corresponding letter
;; "space" means replace the corresponding letter with a " "
;; "remove" means remove the corresponding letter
;;
;; In this problem you will design a function called decoder, that will
;; decode encrypted messages! Very poorly encrypted messages. The function
;; consumes a ListOf1String (l) and Operations (ops) in that order. The
;; function should produce a String which is the result of applying the
fi fi fi fi fi
, ;; given operations to the successive 1String and joining the resulting
;; letters together.
;;
;; For example:
;; (decoder (list "i" "k" "l" "h" "a" "m" "k" "s" "a" "r" "m")
;; (list "keep" "remove" "remove" "space" "keep" "keep"
;; "space" "keep" "keep" "remove"))
;;
;; should produce "i am sam"
;;
;; Notice that some of the letters were kept, some were replaced with a space,
;; and some were removed.
;;
;; If ops runs out of operations before the end of the 1String, then all
;; the remaining letters in l are kept.
;;
;; If l runs out of 1String rst, then the remaining operations in ops are
;; ignored.
;;
;; Example 2:
;; (decoder (list "f" "a" "d" "e")
;; (list "remove" "keep" "space" "keep" "remove" "keep" "space"))
;;
;; should produce "a e"
;;
;; You MUST SOLVE THIS AS A 2-ONE-OF PROBLEM and your solution must include
;; a table. You must use numbers to show the correspondence between table cells
;; and cond QA pairs. By this, we mean you should NUMBER the table cells and
;; NUMBER the corresponding cond QA pairs with the same numbers (as was done
;; in lecture). If you can simplify the table you should. Finally, it is
;; IMPERATIVE that your cond questions only include the kinds of questions that
;; the data driven template rules produce, other conditional behaviour must go
;; into the cond answers. (This is the rule about not editing template questions
;; carried over into 2-one-of problems.)
;;
(@htdf decoder) ;!!! uncomment this when you start your function design
(@signature ListOf1String Operations -> String)
;; produce a string result of applying the oper. to the strings and append them
(check-expect (decoder empty empty) "")
(check-expect (decoder (list "a") empty) "a")
(check-expect (decoder empty (list "keep")) "")
(check-expect (decoder empty (list "space")) "")
(check-expect (decoder empty (list "remove")) "")
(check-expect (decoder (list "a") (list "keep")) "a")
(check-expect (decoder (list "a") (list "remove")) "")
(check-expect (decoder (list "a") (list "space")) " ")
(check-expect (decoder (list "f" "a" "d" "e")
(list "remove" "keep" "space" "keep"
"remove" "keep" "space"))
"a e")
(check-expect (decoder (list "i" "k" "l" "h" "a" "m" "k" "s" "a" "r" "m")
fi