Assigned Th 7/17/2008, due Mo 7/28 at 9pm. 15 points.
http://www.cs.nyu.edu/courses/summer08/G22.3033-002/
Homeworks are due on Fridays at 9pm. This deadline will be strictly enforced.
Email your answers to Robert Soulé robert.soule@gmail.com. Please put your solutions to VBA programming problems in a powerpoint presentation. For all other questions (including programming problems in other languages), just send a simple text file, such as what you get when using Emacs, Vi, Notepad, or the "save as text only" feature in Word.
Please make sure that your code works with the compilers and tools installed at CIWW. Specifically, please test:
doowop1
(see http://www.cims.nyu.edu/systems/resources/computeservers/).
(3+12 = 15 points) Consider the following buggy Perl script:
#!/usr/bin/perl # 1
use strict; use warnings; # 2
# 3
sub compute_avg { # 4
my @sums; # 5
my $nrows = $#_; # 6
for (my $i=0; $i<$nrows; $i++) { # 7
my $row = $_[$i]; # 8
for (my $j = 0; $j < @$row; $j++) { # 9
$sums[$j] += $row->[$j]; #10
} #11
} #12
my @result; #13
for (my $i = 0; $i < @sums; $i++) { #14
$result[$i] = $sums[$i] / $nrows; #15
} #16
return @result; #17
} #18
#19
sub to_string { #20
my $result = ""; #21
for my $row (@_) { #22
$result .= " " . $_ for (@$row); #23
$result .= "\n"; #24
} #25
return $result; #26
} #27
#28
our @input = ([2, 1, 3], [0, 1, 1], [4, 1, 2]); #29
print "initial input:\n" . to_string @input; #30
our @expected = ([2, 1, 3], [0, 1, 1], [4, 1, 2], [2, 1, 2]); #31
print "expected output:\n" . to_string @expected; #32
our @avg = compute_avg @input; #33
our @output = @input; #34
push @output, [ @avg ]; #35
print "actual output:\n" . to_string @output; #36
1 Hypothesis (e.g., variable has wrong value in given line)
Experiment (e.g., run debugger, set breakpoint, inspect value)
Observation (e.g., the value of the variable at that place)
Conclusion (e.g., hypothesis verified, falsified, inconclusive)
2 Hypothesis ...
Experiment ...
Observation ...
Conclusion ...
3 ...
...
(0 points) When you learn a new language, a good way to make progress is by solving some moderately difficult programming problems. At the same time, when you learn a new algorithm, a good way to understand and remember it is by implementing it. Therefore, I suggest you combine the two by using one of the new languages you learned in prior lectures to implement one of the debugging algorithms you learned in the most recent lecture.
ddmin algorithm to JavaScript or PHP. You can start from
the Perl version on the slides, or you can start from the publicly
available Python version by Andreas Zeller.