Corrections, FAQs, and Hints for Assignment 4

CSc 372, Fall 2006

Last Update: October 12, 2006, 2:25pm


Correction

1.         The printed copies of the write-up for pancakes are correct but for a while the PostScript and PDF versions erroneously showed some whitespace being elided from the echoed order. To hopefully stamp out the confusion on this, here is the main loop in my solution: ('Sorry the indentation is squashed out.)

 

def main

while line = gets do

line.chomp!

printf("Order: %s\n\n", line)

doCakes line

puts

end

end

 

Feel free to use the above code, or any part of it, in your solution.

 

2.         At the end of the first example for calc you see this:

 

    ? 143243243243242323*342343443234324

    49038385111943393068867603094652

    ? ^D

    %

 

            In fact, if you type a control-D at calc's ? prompt, you should see this:

 

    % ruby calc.rb

    ? 3+4

    7

    ? %

 

It's not hard to make that happen—just don't print anything after gets returns nil.

 

See the loop at the bottom of slide 122, which prompts with Query? for an example of this.


FAQs

 

Q1:      For pancakes.rb, can we use the Matrix class?

A:        I didn't have Matrix in mind when I wrote the assignment but if you want to learn about Matrix, please do. My first solution is nearly an ML program written in Ruby. I should clear my mind and write a native Ruby solution, too. (When in Rome...)

 

IMPORTANT: To use Matrix, add this as the first line in your source file:

 

    require "matrix"   # Note: all lower case

 

Q2:      Do we need to match trailing whitespace on output lines in pancakes and status?

A:        No, don't worry about that. The tester configuration uses a sed command to strip trailing whitespace before comparing the output of your version with the reference version.

 

Q3:      My mirror.rb works on the first three cases in the tester but fails on /home/cs372/fall06/a4/tests/mirrortest.rb. Why?

A:        Here's a key statement in the write-up: "all that mirror(x) requires is that x responds to the method each." (mirror(x) added for clarity here.)

 

mirrortest.rb uses a class called Trio, defined in that file, that doesn't do much more than provide an each method. If you're failing that test, you've probably assumed that the argument has more capabilities than simply being able to respond to each. For example, you might be doing something like x.to_a. Duck-wise, the duck characteristic here is simply being able to handle each. Don't expect more of the duck than that!

 

Q4:      Should we handle division by zero in calc?

A:        Nope. Just let it blow!

 

Q5:      Is it ok to use Array#zip in nzip?

A:        I overlooked that method when writing the problem but you can go ahead and use it. It simplifies the computation but it will probably make you use a language feature you wouldn't have used otherwise. To learn the most, do it both with and without.


Typos


Coming soon, no doubt!