Assigned Th 6/5/2008, due Fr 6/13 at 9pm. 50 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/).
(7+6 = 13 points)
(0[xX])?[a-fA-F0-9]+. Rewrite this regular expression using
only the “essential” features of formal regular expressions.
ps -l” command. For example, consider the
following output:
doowop1:~> ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1088 23431 23421 0 75 0 - 18991 wait pts/4 00:00:00 bash
0 R 1088 23641 23431 0 77 0 - 15863 - pts/4 00:00:00 ps
The PID and PPID of the line of output for bash are 23431 and 23421.
(5 + 7 = 12 points)
#!/usr/bin/perl -w
$a = "-";
sub f {
our $a = "f";
sub g { local $a = "g"; h() }
sub h { print $a, "\n" }
g();
print $a, "\n"
}
f()
This homework practices the “How to learn a language” steps from the lecture on 5/29/2008:
doowop1. Here is a list of compute
servers:
http://www.cims.nyu.edu/systems/resources/computeservers/.
(2+0+2+2 = 6 points) Consider the following Perl script:
#!/usr/bin/perl -w
while (<>) {
chomp;
push @rows, [ split /,\s/ ];
}
for $row (@rows) {
for ($i = 0; $i < @$row; $i++) {
$w = length $row->[$i];
$widths[$i] = $w if !$widths[$i] || $w > $widths[$i];
}
}
for $row (@rows) {
for ($i = 0; $i < @$row; $i++) {
print " " x (1 + $widths[$i] - length $row->[$i]);
print $row->[$i];
}
print "\n";
}
csv2fixed.pl, and the input into another file, for example,
table.csv. Then, you do perl csv2fixed.pl < input.csv).
0, 0, 10, 0
10, 0, 10, 0
10, -10, 10, 0
$_?
@$row return, and why? (This might be one of those
cases where you need to ask a Perl-guru if you can't figure it out
yourself.)
(8 points) Extend the script from problem hw03-3 so it computes the average of each column, and prints it as an added row at the bottom of the output. For example, given this input:
3, 4, 3
0, 0, 0
4, 5, 2.5
2, -1, 4
your script should print this output:
3 4 3
0 0 0
4 5 2.5
2 -1 4
2.25 2 2.375
For example, the average of column 3,0,4,2 is 2.25.
(8 points) Extend the script from problem hw03-3 so it computes the Euclidian distance of each row to the first row, and prints it as an added column at the right of the output. For example, given this input:
3, 4, 3
0, 0, 0
4, 5, 2.5
2, -1, 4
your script should print this output:
3 4 3 0
0 0 0 5.8309518948453
4 5 2.5 1.5
2 -1 4 5.19615242270663
For example, the first row has zero distance from itself. The second row
has Euclidian distance 5.8309518948453 from the first row.