CSE 461: Programming Languages Concepts
Prof. G. Tan
Spring 2022
Homework 4: Racket warming up
Due on Mar 6th at 6pm in Canvas.
Submission: you should submit via Canvas a DrRacket file with Racket
code in. Please clearly mark your answers using comments so that we can
tell the co
espondence between your code and questions.
1. (0 points) Go through a
ief tutorial about the DrRacket program-
ming environment at http:
docs.racket-lang.org/d
acket/index.
html.
2. (3 points) sum(start, end) computes the sum from start to end; e.g.,
sum(3, 6) computes XXXXXXXXXX, which is 18. It can be defined recur-
sively in the following way. Define the co
esponding Racket function,
following the definition below.
sum(start, end) =
{
start if start = end
sum(start, endâˆ’ 1) + end otherwise
3. (3 points) Write the Hofstadter functions in Racket. Hofstadter Female
and Male functions are a pair of mutually recursive functions defined
as follows:
F (0) = 1
M(0) = 0
F (n) = nâˆ’M(F (nâˆ’ 1)),when n > 0
M(n) = nâˆ’ F (M(nâˆ’ 1)),when n > 0
4. (3 points) A cash reward credit card rewards back to a customer a
portion of the charges the customer makes over a month. One such
credit card rewards back
(a) 1% for the first $2000 of charges,
(b) 1.5% for the next $2000 (that is, the portion between $2000 and
$4000),
1
http:
docs.racket-lang.org/d
acket/index.html
http:
docs.racket-lang.org/d
acket/index.html
(c) 2% for the next $1500 (that is, the portion between $4000 and
$5500),
(d) and 2.5% for everything above $5500.
Define the function reward, which consumes a charge amount and
computes the co
esponding reward amount.
2