logo       

Re: Perl Translation: msg#00031

lang.perl.qotw.discuss

Subject: Re: Perl Translation

On Tuesday 18 January 2005 20:57, Daniel Martin wrote:
> Shlomi Fish <shlomif-ik1l9ssToec+JF/nGntIXQ@xxxxxxxxxxxxxxxx> writes:
> > I was surprised to see such a short solution can still work for every N,
> > but it seems to be the case. (passes all the tests in my Test-Suite.t and
> > also works for every number up to 380 or so).
>
> It's actually quite a nice, simple solution, and I believe it is
> equivalent to the method of arranging N-1 points in a circle and one
> point "at infinity" that was discussed earlier.
>
> (Warning: I now go on to assume a basic abstract algebra background)
>
> Essentially, all you need to have a way of coming up with a tournament
> for N players is a family of functions f_0, f_1, ... f_{N-2} on the
> integers 0..N-1 that satisfies these three properties:
>
> [] f_i(f_i(x)) = x for all i, x
>
> [] f_i(x) != x for all i,x
>
> [] For a, b in (0..N-1), with a != b, there is exactly one i such
> that f_i(a) = b
>
[snipped]

Interesting analysis.

> > One thing that delayed me was the fact that I translated the loops to
> >
> > for my $d (0 .. $m)
> >
> > Instead of
> >
> > for my $d (0 .. ($m-1))
> >
> > Apparently the (0 ... m) operator in Ruby does not evaluate "m" itself,
> > as opposed to Perl.
>
> Ruby has both a .. (two dot) operator and a ... (three dot operator).
> The .. operator behaves as perl does, but the ... operator, as you
> observed, leaves off the upper limit. This is convenient for cases
> like this:
> l = somelist.length
> (0...l).each { |x| #whatever
> }
>
> I had to translate his version to perl for my verifier too, and got
> caught on the same thing.

So, "the problem of many is the consulation of fools." (just kidding.)

In any case, the problem is that Perl also has a ... operator which behaves
the same as ".." except in scalar context where their Flip-floppy natures
differ somewhat.

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomif-ik1l9ssToec+JF/nGntIXQ@xxxxxxxxxxxxxxxx
Homepage: http://www.shlomifish.org/

Knuth is not God! It took him two days to build the Roman Empire.



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise