(@cwl skim121)
(@problem 1)
;; There is a primi7ve type called 1String, defined as follows:
;;
;; 1String is String
;; interp. a 1String represents a single leDer
;; CONSTRAINT: any 1String is only one leDer long
(@htdd ListOf1String)
;; ListOf1String is one of:
;; - empty
;; - (cons 1String ListOf1String)
;; interp. a sequence of leDers
(define L1 empty)
(define L2 (list "a" "B" "c"))
(@htdd Opera7ons)
;; Opera7ons is one of:
;; - empty
;; - (cons "keep" Opera7ons)
;; - (cons "space" Opera7ons)
;; - (cons "remove" Opera7ons)
;; interp. a sequence of opera7ons to apply to a list of 1String
;; "keep" means keep the corresponding leDer
;; "space" means replace the corresponding leDer with a " "
;; "remove" means remove the corresponding leDer
;;
;; In this problem you will design a func7on called decoder, that will
;; decode encrypted messages! Very poorly encrypted messages. The func7on
;; consumes a ListOf1String (l) and Opera7ons (ops) in that order. The
;; func7on should produce a String which is the result of applying the
;; given opera7ons to the successive 1String and joining the resul7ng
;; leDers 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"
, ;;
;; No7ce that some of the leDers were kept, some were replaced with a space,
;; and some were removed.
;;
;; If ops runs out of opera7ons before the end of the 1String, then all
;; the remaining leDers in l are kept.
;;
;; If l runs out of 1String first, then the remaining opera7ons 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 solu7on 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 ques7ons only include the kinds of ques7ons that
;; the data driven template rules produce, other condi7onal behaviour must go
;; into the cond answers. (This is the rule about not edi7ng template ques7ons
;; carried over into 2-one-of problems.)
;;
(@htdf decoder) ;!!! uncomment this when you start your func7on design
(@signature ListOf1String Opera7ons -> String)
;; produce list of string based on given opera7on
(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 "a") empty) "a")
(check-expect (decoder (list "h" "e" "l" "l" "o") empty) "hello")
(check-expect (decoder (list "a") (list "keep")) "a")
(check-expect (decoder (list "a") (list "space")) " ")
(check-expect (decoder (list "a") (list "remove")) "")
(check-expect (decoder (list "i" "m" "h" "l" "o" "y"
"v" "u" "e" "l" "y" "h" "o" "u")
(@problem 1)
;; There is a primi7ve type called 1String, defined as follows:
;;
;; 1String is String
;; interp. a 1String represents a single leDer
;; CONSTRAINT: any 1String is only one leDer long
(@htdd ListOf1String)
;; ListOf1String is one of:
;; - empty
;; - (cons 1String ListOf1String)
;; interp. a sequence of leDers
(define L1 empty)
(define L2 (list "a" "B" "c"))
(@htdd Opera7ons)
;; Opera7ons is one of:
;; - empty
;; - (cons "keep" Opera7ons)
;; - (cons "space" Opera7ons)
;; - (cons "remove" Opera7ons)
;; interp. a sequence of opera7ons to apply to a list of 1String
;; "keep" means keep the corresponding leDer
;; "space" means replace the corresponding leDer with a " "
;; "remove" means remove the corresponding leDer
;;
;; In this problem you will design a func7on called decoder, that will
;; decode encrypted messages! Very poorly encrypted messages. The func7on
;; consumes a ListOf1String (l) and Opera7ons (ops) in that order. The
;; func7on should produce a String which is the result of applying the
;; given opera7ons to the successive 1String and joining the resul7ng
;; leDers 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"
, ;;
;; No7ce that some of the leDers were kept, some were replaced with a space,
;; and some were removed.
;;
;; If ops runs out of opera7ons before the end of the 1String, then all
;; the remaining leDers in l are kept.
;;
;; If l runs out of 1String first, then the remaining opera7ons 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 solu7on 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 ques7ons only include the kinds of ques7ons that
;; the data driven template rules produce, other condi7onal behaviour must go
;; into the cond answers. (This is the rule about not edi7ng template ques7ons
;; carried over into 2-one-of problems.)
;;
(@htdf decoder) ;!!! uncomment this when you start your func7on design
(@signature ListOf1String Opera7ons -> String)
;; produce list of string based on given opera7on
(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 "a") empty) "a")
(check-expect (decoder (list "h" "e" "l" "l" "o") empty) "hello")
(check-expect (decoder (list "a") (list "keep")) "a")
(check-expect (decoder (list "a") (list "space")) " ")
(check-expect (decoder (list "a") (list "remove")) "")
(check-expect (decoder (list "i" "m" "h" "l" "o" "y"
"v" "u" "e" "l" "y" "h" "o" "u")