Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fp:lab01-java-intro [2021/03/11 13:30]
pdmatei
fp:lab01-java-intro [2021/03/11 14:50] (current)
dmihai
Line 3: Line 3:
 ===== 1. A single function to implement all of them ===== ===== 1. A single function to implement all of them =====
  
-1.1. Write a method that takes a list of integers and returns a new list with all elements multiplied by two.+1.1. Write a method that takes a list of **integers** and returns a new list with all elements multiplied by two.
  
-1.2. Write a method that takes a list of doubles and returns a new list with all elements multiplied by two.+1.2. Write a method that takes a list of **doubles** and returns a new list with all elements multiplied by two.
  
 1.3. Write a method that takes a list of integers and returns a new list with all the elements’ successors (i.e. the elements incremented by 1). 1.3. Write a method that takes a list of integers and returns a new list with all the elements’ successors (i.e. the elements incremented by 1).
Line 26: Line 26:
 2.3. Write a method that takes a list of integers and returns a new list containing **even** elements **larger** than 100. 2.3. Write a method that takes a list of integers and returns a new list containing **even** elements **larger** than 100.
  
-2.4. Write a method that takes a list of strings and returns a new list of the elements ​which are prime+2.4. Write a method that takes a list of strings and returns a new list of strings ​which start with letter ''​B''​ only.
  
 2.5. (!) Write the signature of a generic ''​filter''​ function over lists. 2.5. (!) Write the signature of a generic ''​filter''​ function over lists.
Line 40: Line 40:
 3.3. Write a method that takes a list of integers and returns a string representation of all elements separated by commas, e.g. “1,​2,​3,​4” 3.3. Write a method that takes a list of integers and returns a string representation of all elements separated by commas, e.g. “1,​2,​3,​4”
  
-3.4. Write a method that takes a list of integers ​and another list (of integers) ​and returns ​the concatenation of the second to the first.+3.4. Write a method that takes a list of integers and returns ​their greatest common denominator.
  
 3.5. (Discussion) What is (could be!) common among all implementations?​ How should a ''​fold''​ function **signature** (which generalises over all previous ones) look like? 3.5. (Discussion) What is (could be!) common among all implementations?​ How should a ''​fold''​ function **signature** (which generalises over all previous ones) look like?
Line 54: Line 54:
 4.3. Write a method that takes a list and returns a new list with the square of each element. 4.3. Write a method that takes a list and returns a new list with the square of each element.
  
-4.4. (!) Identify a generic function which can replace all the above, and implement it.+4.4. (!) Identify a generic function which can replace all the above, and implement ​it. Solve 4.3. using it.