Homework 3
Due: start of class on Thursday, April 23rd
IMPORTANT NOTES
- This homework is longer than the previous homeworks. Please allocate additional time
to do the homework.
- Although you are only turning in hard copies of your code, please make sure
your code would work if run on linuxlab.
- This homework must be TYPED.
- p.300 of PLP, Exercise 6.17(a). Write an iterator function (generator) in PYTHON
only. We are giving you some starter code. As you
can see in the starter code, the program asks for a number between 2
and 9. If given, for example, 3 -- the program should output
all permutations of 123 -- which would be 123 132 213 231 312 321.
The way the program is written, it lists each permutation on its own line.
Add whatever code you need, but DO implement giveAPermutation as an
iterator function and DO NOT change any code after the line of pound
signs. A python interpreter can be found on linuxlab. You can refer
to class notes and web resources. Print out a copy of your homework3.py
(with iterator function implemented) and turn that in as part of the homework
submission.
- p.302 of PLP, Exercise 6.27. Write the function in Scheme only. Do not
look for the answer on the internet and then copy it down.
- p.398 of PLP, Exercise 7.2.
- Define a function called myif in Scheme. myif takes three parameters:
condition, ifTrue, and ifFalse. condition is of boolean type. ifTrue is a function
that takes no parameters and should be called when the condition is true.
ifFalse is a function that takes no parameters and should be called when
the condition is false. You cannot use if or cond. You can, however, use
and, or, not, and eq?. Use ONLY the functional features of
Scheme. Here is some starter code. Print out a copy of your homework3.scheme
(with myif implemented) and turn that in as part of the homework submission.
- p.553 of PLP, Exercise 10.7 (b).
- p.554 of PLP, Exercise 10.8 (a) and (b).
- Write CURRIED versions of the two functions you wrote for 10.8 (a) and (b).