15-112 Spring 2015 Homework 5
Due Sunday, 15-Feb, at 10pm
Read these instructions first!
-
This hw is SOLO.
-
Starting this week, you may use 1d lists, in addition to strings, graphics and stepAnimation, loops and conditionals, but (as usual) you may not use constructs we have not yet covered (2d lists, sets, maps, recursion, etc), unless explicitly allowed below.
-
This week you may only make up to 5 submissions max to Autolab. As usual, only your last one counts.
-
Do not use global variables! Do use test functions! Do use helper functions!
- Hint: How to test a destructive function?
Say you have a destructive function f(a) and you want to test it. Since it returns None (right?), you can't just do:
assert(f([1,2,3]) == "whatever we expect")
Instead, assign it to a variable, call the destructive function, then do your test, like so:
a = [1,2,3]
f(a) # destructive
assert(a == "whatever we expect")
- Hint: How to test a non-destructive function?
You've been testing non-destructive functions all semester, but now you
have to add an additional test to verify that they are in fact non-destructive!
How? First, copy the parameters, then call the function, then verify that
the original parameters equal the copy. For reasons we'll cover next week,
you should in fact use deepcopy, so you convert this:
a = [1,2,3]
assert(f(a) == "whatever we expect")
to this:
import copy
a = [1,2,3]
aCopy = copy.deepcopy(a)
assert(f(a) == "whatever we expect")
assert(a == aCopy) # verify that the parameter is unchanged
- s15 Quiz4 Animation [10 pts, manually graded]
First, carefully watch the video solutions for the animation problem
in s15 (this semester's) quiz4, as explained in the
s15-quiz4-solutions
videos.
Be sure to carefully watch these videos in their entirety, and be sure you understand each step of the solution. Then, duplicate the solution
(just to the animation problem) in your hw5.py file (below the #ignore_rest line, of course). Do not turn this into merely a typing exercise, but rather be sure you understand every step of the solution. That said, of course, we would expect everyone to have very similar or nearly identical solutions just to this specific problem.
- f14 Quiz 5 [10 pts, manually graded]
In a triple-quoted string at the top of your hw file,
include the solutions to
f14's quiz5 (except for the bonus, which you should skip (or do for
fun if you wish)).
-
From
f14-hw5:
-
nondestructiveRotateList [10 pts, autograded]
-
destructiveRotateList [10 pts, autograded]
-
histogram [10 pts, autograded]
Important note: here, you will change this function to take a second parameter,
so it will be histogram(a, bucketCount=10). The second parameter is the number
of buckets, and is guaranteed to be a positive integer, and in fact is guaranteed
to be a factor of 100. The example in f14-hw5 includes a bucketCount of 10,
which is the default value if no bucketCount is supplied. The size of each
bucket is 100/bucketCount, hence for a bucketCount of 10, each bucket size is
10 (00-09, 10-19, etc). If the bucketCount was, say, 5, then each bucket size
would be 20 (00-19, 20-39, etc). The last bucket is always written with the ++
notation (so, with a bucketCount of 5, you'd get 00-19, 20-39, 40-59, 60-79, 80++).
-
lookAndSay [10 pts, autograded]
-
inverseLookAndSay [10 pts, autograded]
-
From
f12-hw5a:
-
solvesCryptarithm [10 pts, autograded]
-
areaOfPolygon [10 pts, autograded]
-
bestScrabbleScore [10 pts, autograded]
-
Bonus/Optional: infiniteZoomAnimation [2.5 pts, manually graded]
Write the function infiniteZoomAnimation(), taking no parameters, that
when called displays a step animation that matches
this video.
Your animation should dynamically generate (visually-pleasing) colors
so that they never repeat (beyond chance).
-
Bonus/Optional: wordCloudAnimation [2.5 pts, manually graded]
Given a list of words, you could create a static word cloud by laying
them out in a non-overlapping way, using a variety of text sizes
and colors, such as in
these images.
For this problem, given the limitations of Tkinter, you may restrict
these layouts to strictly horizontal text, as in
this image
or
this one.
Actually, while not required, it would be easy to also have vertical text
where the letters are oriented horizontally (just draw the text one letter
at a time).
These are static word clouds. You could also make them dynamic, in an animation
that shows the word cloud being constructed and deconstructed, such as in
this video (though it uses
non-horizontal text, which you would not).
With this in mind, write the function
wordCloudAnimation(words) that takes a list of words and displays a
step animation that
animates the construction and deconstruction of a word cloud
composed of the given words, as in the video above. Your animation
may repeat with the same word cloud (though it would be even nicer
if it generated new word clouds each time!).
Also, just for this problem, you may use 2d lists
if you know how to do so and think they would help (though you do not
necessarily need them and may ignore this option). Finally, as a hint,
you will probably want to compute the word cloud layout first, then pass that
information somehow into the animation (rather than have the animation
repeat the world cloud layout computation on every step). Good luck, and have fun!