====== Programming introduction ====== ===== 1. Scala introduction ===== **Exercise 1.1.** Write a function ''startStop'' which retrieves the elements of a list from within bounds. Use patterns in your implementation. Define an object ''Main'' as shown below. Any code within the object can be directly executed. (Hint: use a simply-recursive function)/ object Main extends App { def startStop[A] (l: List[A] ,start: Int, stop: Int): List[A] = ??? println(startStop(List(1,2,3,4,5,6),1,4)) // = List(2,3,4) } **Exercise 1.2.** Write a function which determines the number of occurrences of each character in a string. (Hint: use a tail-recursive function) def countChars (s:String): Map[Char,Int] = { def aux(l: List[Char], acc: Map[Char,Int]): Map[Char,Int] = ??? ??? } **Exercise 1.3** Write a function which takes a list of records first name, last name, CNP (encoded as tuples), and returns a list of the last names and ages of all females which are younger than the average of the entire list. E.g. ''List( (“Mary”, “2030694123456”), (“Anne”,“2121092123456”), (“Matei”, “5121202123456”), (“Maggie”, “2121078123456”) )'' yields ''List( (“Mary”,28), (“Anne”,30) )''. Maggie was born in '78, whereas Mary, Anne and Matei were born in '94, '92 and 2002, respectively. (Hint: use combinations of **map** with **filter**) val example = List(("Mary", "2030694123456"), ("Anne", "2121092123456"), ("Matei", "5121202123456"), ("Maggie", "2121078123456")) def youngerThanAverage(l: List[(String,String)]): List[(String,Int)] = { def getAge(s:String):Int = ??? // female gender = True def getGender(s:String):Boolean = ??? ??? } **Exercise 1.4** A labelled graph is encoded as a String text where **each line** is an edge ''