|| This is a Miranda Program File
|| NOTE THAT THERE ARE MANY OTHER CORRECT ANSWERS
|| THESE ARE SHORT AND CLEAR BUT NOT NECESSARILY
|| THE MOST EFFICIENT
|| Answers for questions 1.1 to 1.5 Class Test #1
|| 1998 and 1999
|| Beginning with 1998
p1 = [2,3]
p2 = 1:p1
p3 = map myop
where
myop [] = False
myop any = True
p4 = foldr (\/) False
|| Note there is a mistake in the example output for p5
|| given on the test. The output should be [3, 22]
p5 n m = n, if #n > #m
= m, otherwise
|| Note there is a mistake in the example output for p6
|| given on the test. The output should be 2
p6 [x] = x
p6 (x:xs) = x, if x < p6 xs
= p6 xs, otherwise
p7 = p4 . p3
p8 n = [(x, y, z) | x <- n; y <- n; z <- n]
|| Answers for questions 1.1 to 1.5 Class Test #1 1999
|| Note that we call the program q1, q2 etc. so that
|| they do not clash with the programs above.
q1 = (1, 'b')
q2 = [p1]
q3 = map (#)
q4 = foldr (\/) False
q5 0 = True
q5 n = False
q6 [] =0
q6 ((a,b):rest) = a + q6 rest
q7 = q4 . (map q5) . q3
q8 n = [a | (a,b) <- n; b > 0]