Corrections, FAQs, and Hints for Assignment 3

CSc 372, Fall 2006

Last Update: October 4, 2006, 12:21am


FAQs

 

Q1:      I can't get past the restrictions on the first two problems. Any suggestions?

A:        You might try doing them without worrying about the restrictions. Then focus on a way to remove the violations. You might just skip them and move on to the other problems—with more Ruby under your belt you'll have more ideas.

 

If you're desperate on a problem I'll surely give you a hint but then you'll miss the pleasure of solving it yourself. The seven hour goal on this assignment does include some think time on those problems.

 

I'd say that longest takes a bigger leap than seqwords but your mileage may vary.

 

Incidentally, a pretty good book on problem solving is How to Solve It, by G. Polya.

 

Q2:      Can I use methods like between? and eql? in longest.rb?

A:        Definitely not! Those are surely comparisons, albeit wrapped in a method. As a rule, any method whose name ends with "?" should be viewed with suspicion.

 

Remember that Poorna and I are happy to inspect your solutions for compliance with the restrictions. Just mail them to cs372-staff.

 

Q3:      What should xfield 1 2x 3 do? I ask because "2x".to_i produces 2.

A:        Keep it simple: If to_i doesn't produce zero, assume it's a field number (2 in this case) and proceed with it.

 

Q4:      Can the case statement be used in longest.rb?

A:        Yes, BUT only the form of case that doesn't involve a comparison. That form is shown on the bottom of page 343 (in chapter 22). The form at the top of page 344 compares target to comparison and is therefore, of course, a comparison!

 

Q5:      For seqwords.rb, will the lines with the words have trailing whitespace?

A:        No. If what you see is "one" the word is "one", not "one " or "one ", etc.

 

Q6:      What's a "Broken pipe"? I was trying one of the xfield examples and got this:

 

% ruby xfield.rb -d: 1 5 < /etc/passwd | head

root root

...

xfield.rb:38:in `write': Broken pipe (Errno::EPIPE)

 

A:        Just ignore that. Ruby's complaining because it has more data to send through the pipe to head but head exits as soon as it's read as much as it wants. That situation is known as a "broken pipe". Ruby doesn't handle it gracefully, by default.


Typos

 

1.         Spurious "are" in the third restriction for longest.rb: "The only datatypes you may [are] use are integers and strings."

 

2.         I see two places in the assignment where I say "list" instead of "array". You know what I meant!