Assignment

  1. Without using if, write a function
    isDivBy3: num -> bool;
    
    which returns true if and only if its argument is divisible by 3.

  2. Without using if, write a function
    isDivBy: num # num -> bool;
    
    which returns true if and only if its first argument is divisible by its second argument.

  3. Re-implement isDivBy3 using isDivBy.

  4. There is a boolean operator called NAND. Search for it on the Web and implement it in Hope.

  5. Write a function contains
    contains: alpha # list(alpha) -> bool;
    
    contains(x,k) returns true if and only if list k contains x.

  6. A list that is the same forwards and backwards is called a palindrome. Specify, design and write a function
    isPalindrome: list alpha -> bool;
    
    which returns true if and only if its argument is a palindrome. e.g. isPalindrome [1,2,1] is true but isPalindrome [1,2] is false.

  7. Specify, design and write a function which returns the middle element of a list. You decide what the middle element of a list of even length.

  8. Specify, design and write a function remove,
    remove: alpha # list alpha -> list(alpha);
    
    Such that remove(x,k) removes all occurrences of x from the list k. For example remove(2,[3,2,3,2,3,4]) gives [3,3,3,4].

  9. Specify, design and write a function removeDuplicates,
    removeDuplicates:  list (alpha) -> list(alpha);
    
    Such that removeDuplicates k removes all duplicates from k. For example removeDuplicates([3,2,3,2,3,4]) gives [3,2,4].

  10. Specify and Use Stepwise refinement to design and write a function
    isPermutation: list alpha # list alpha -> bool;
    
    isPermutation(k,m) returns true if and only if k and m are permutation of each other. For example [1,2,3,1] and [1,3,1,2] are permutations but [1,2,3,1] and [1,3,2] are not.

s.danicic@gold.ac.uk
Sebastian Danicic BSc MSc PhD (Reader in Computer Science)
Dept of Computing, Goldsmiths, University of London, London SE14 6NW
Last updated 2010-12-29