5 Homework 3B
Due:
Thursday, 1/25 at 9PM
This assignment is SOLO, and entirely AUTOGRADED.
What to Download:
Please start with this file, filling in where appropriate, and submit your homework to the HW3B assignment on Gradescope. This page has additional information, and allows us to format things nicely.
5.1 Problem 1
Design a function exclusive-range? that takes three integers, lo, hi, and n, and returns #t if n is between lo and hi, and #f if it is either equal to them or outside the range.
Use check-contract to ensure that your function satisfies the contract you gave it.
Next write a function exclusive-range?-prop that takes two integers, lo and hi, picks a random number between them, and ensures that exclusive-range? always returns #t. If it is passed input where (>= (add1 lo) hi), you can just have it return #t. Ensure that this works using check-contract (note that, as a property that should always hold, it should return True).
5.2 Problem 2
Define a contract Odd for odd integers. Use that to design a function double-plus1 which takes a number, doubles it and adds 1. It should take in and produce Odd numbers. Verify that it works using check-contract.
5.3 Problem 3
Define a predicate divisible-by-3-or-5? that takes an integer and checks whether it is divisible by either 3 or 5. Use check-contract to make sure it satisfies the contract you give it. Then use it to define a contract Divis3Or5. Then design a function divide-3-or-5 that takes an integer and if it is divisible by 3 or 5, returns the same number; otherwise it should return 0. The output type of your function should be Divis3Or5, and you should confirm your function satisfies its contract with check-contract.