Introduction to Programming

Assignment 1


Date: Tue, 17 August 2004

Due on: Tue, 24 August 2004


  1. Define the function mostlyTrue that takes as input three values of type Bool and returns True if at least two them are True. For instance:
               mostlyTrue True True False = True
               mostlyTrue False True False = False
               
  2. Define the function bestTwo that takes as input three Int values and returns the sum of the largest two of the three. For instance:
               bestTwo 3 1 2 = 5
               bestTwo 3 4 3 = 7
               
  3. Define the function find that takes as input x (an Int) and ys (a list of Int) and returns True if x appears in ys. For instance:
               find 7 [8,9]   = False
               find 7 [8,7,9] = True
               
  4. Define the function findboth that takes as input x, y (both Int) and zs (a list of Int) and returns True if both x and y appear in zs. For instance:
               findboth 7 8 [8,9]   = False
               findboth 7 8 [8,7,9] = True
               
  5. Define the function findall that takes as input xs and ys (both lists of Int) and returns True if every Int in xs appears in ys. For instance:
               findall [] [1,3] = True
               findall [3,4] [1,3] =  False
               findall [3,4] [1,3,4,1] = True
               

Madhavan Mukund
Last modified: Tue Aug 17 09:30:14 IST 2004