- Without using
`if`

, write a functionisDivBy3: num -> bool;

which returns true if and only if its argument is divisible by 3. - Without using
`if`

, write a functionisDivBy: num # num -> bool;

which returns true if and only if its first argument is divisible by its second argument. - Re-implement
`isDivBy3`

using`isDivBy`

. - There is a boolean operator called NAND. Search for it on the Web and implement it in Hope.
- Write a function
`contains`

contains: alpha # list(alpha) -> bool;

`contains(x,k)`

returns true if and only if list`k`

contains`x`

. - A list that is the same forwards and backwards is called a
*palindrome*. Specify, design and write a functionisPalindrome: 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. - 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.
- 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]`

. - 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]`

. - 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