[NBLUG/talk] Knuth re- revisited
Andru Luvisi
luvisi at andru.sonoma.edu
Mon May 26 08:36:01 PDT 2003
On Mon, 26 May 2003, Steve Zimmerman wrote:
[snip]
> B1. [Initialize.] Set T[k] <-- k for 1 <= k <= n.
>
> [end of quote]
>
> How would you code B1?
Given that most languages subscript starting at zero, you would either
ignore the zeroth element (recommended for your first try) or translate
everything down by one (not recommended for your first try).
In Perl, one could do:
@T = (undef, 1 .. $n);
or:
for(my $i = 1; $i <= $n; $i++) {
$T[$i] = $i;
}
In C one might do:
for(i = 1; i <= n; i++) {
T[i] = i;
}
> Better yet, how would you
> code the entire Algorithm B?
My Knuth's are at work and I am at home with the day off, so I'm afraid I
can't help you there.
Andru
--
Andru Luvisi, Programmer/Analyst
Quote Of The Moment:
Heisenberg may have been here.
More information about the talk
mailing list