Exercise 1 Name _____________________ Pts ___/12
Write the functions that return the following results:
g)
inc 4
returns 5
;
hM
Modulus operation
modulus(5,2)
returns 1
modulus(14,3)
returns 2
modulus(12,4)
returns 0
Note the use of a parameter tuple requires the function to be defined as:
fun modulus (a,b) = ...
Euclid's Algorithm for greatest common denominator
gcd(13, 5)
the greatest common divisor, returns 1
gcd(10,4)
returns 2
gcd(36,15)
returns 3
second ["hello","world"];
returns "world"
second [4, 5, 3];
returns 5
i)
smallest [5, ~4, 3];
returns ~4
j)
snoc 3 [4,5]
returns [4, 5, 3]
Note the use of two parameters requires the function to be defined as:
fun snoc a L = ...