Create the functions below in the upper (definitions) pane of DrRacket, save to a file and upload the file to the Homework server.
1. Create the function:
f(x) is 2 when x <= 3, and is x2 - 3x + 8 when x > 3
Put the test cases (and their correct answers) that you'll be using to test this function into the Comments-to-Teacher.
2. Create a function called Div23 which is given an integer (non-negative) and returns #t if it's evenly divisible by either 2 or 3 or both, and #f if neither. Examples:
(div23 3) ; -> #t (div23 8) ; -> #t (div23 6) ; -> #t (div23 35) ;-> #f
3. Create the function:
0 if me < 0
5 if me >= 0 and me is evenly divisible by 5
4. We want to convert from ordinary 12-hour time, to Navy time (24-hour time). For instance, 3 AM would be converted to just 3, and 11 AM would be just 11. But 2 PM would be 14, and 11 PM would be 23. But be careful: 12AM (namely, midnight) would be 0 in Navy time and 12PM (noon) would be 12. Create a function called ToNavyTime(hour,ampm) that takes 2 arguments, the first argument is the ordinary (clock) hour, and the second argument is 0 if it's AM, and 1 if it's PM. The function returns the Navy time.
(ToNavyTime 11 0) ; -> 11 (which is 11 AM) (ToNavyTime 1 1) ; -> 13 (which is 1 PM) (ToNavyTime 12 0) ; -> 0 (which is midnight) (ToNavyTime 12 1) ; -> 12 (which is noon)
5. Challenge Problem: Create the definition for the same function ToNavyTime(hour,ampm) as above, but without using IF or COND. Use only the built-in Scheme functions that you know.
6. Challenge Problem: Create the function SmallestDivisor(N) which will be given a composite (non-prime) integer between 2 and 100, and will return the smallest divisor of that integer (greater than 1).
(SmallestDivisor 24) ; -> 2 (SmallestDivisor 25) ; -> 5