diff --git a/src/Assignment6/Ex3.sc b/src/Assignment6/Ex3.sc new file mode 100644 index 0000000..8bc35d2 --- /dev/null +++ b/src/Assignment6/Ex3.sc @@ -0,0 +1,22 @@ +val cities = List("Paris", "London", "Berlin", "Lausanne") +val relatives = List("Grandma", "Grandpa", "Aunt Lottie", "Dad") +val travellers = List("Pierre-Andre", "Rachel") + +def generatePostcards(cities: List[String], relatives: List[String], travellers: List[String]): List[String] = { + for (t <- travellers; + r <- relatives; + c <- cities) yield s"Dear $r, Wish you were here in $c! Love, $t" +} + +def generatePostcards2(cities: List[String], relatives: List[String], travellers: List[String]): List[String] = { + for (t <- travellers; + r <- relatives; + c <- cities; + if r.startsWith("G")) yield s"Dear $r, Wish you were here in $c! Love, $t" +} + +val cards: List[String] = generatePostcards(cities, relatives, travellers) +println(cards.mkString("\n")) + +val cards2: List[String] = generatePostcards2(cities, relatives, travellers) +println(cards2.mkString("\n"))