Ch 02 Quiz 4
A simple list processing fizz-buzz level quiz. (Recursion.)
On paper, write the function
f :: [Int] -> [Int]
This function has the following properties:
- Skip input numbers that are below 100.
- Other numbers should be in the output list.
- Except if you hit 999 the process ends immediately, without output.
Examples:
checks1 = [ f [10,500,999,888] == [500] ]
Post-Quiz Study Guide
Memorize these templates.
Copy all of the input numbers to the output.
laze0 :: [Int] -> [Int]
laze0 [] = []
laze0 (x:xs) = x : laze0 xs
Skip odd numbers.
laze1 :: [Int] -> [Int]
laze1 [] = []
laze1 (x:xs)
| odd x = laze1 xs
| otherwise = x : laze1 xs
Stop when you get to 10.
laze2 :: [Int] -> [Int]
laze2 [] = []
laze2 (x:xs)
| x == 10 = []
| otherwise = x : laze2 xs
Alternate version. (Fancy, not the basic memorized template.)
laze2b :: [Int] -> [Int]
laze2b [] = []
laze2b (10:xs) = []
laze2b (x:xs) : laze2b xs