Re: Perl Translation

Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> Wed, 19 Jan 2005 18:13:17 +0200
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
On Wednesday 19 January 2005 13:31, Greg Matheson wrote:
> On Wed, 19 Jan 2005, I wrote:
> Jeffrey Vinocur's visualization of the problem as n-1 teams
> moving about the perimeter of n/2 parallel playing fields, ie all
> except the champions who play all their games before the stadium
> results in the same solution as the above one, I believe.

The outputs of Vinocur's variant, and Zsban Ambrus' one are similar. Thus, I 
was able to modify (after some tinkering) Ambrus' solution to produce the 
same results as Vinocur's:

<<<
use strict;
use warnings;

sub allocate_schedule
{
    my $n = shift;

    my $m = $n - 1;
    my @ret;
    for my $d (0 .. ($m-1))
    {
        my @day = ();
        push @day, ($d+1);
        for my $k (1 .. $m)
        {
            if ($k == ($d+1))
            {
                push @day, 0;
            }
            else
            {
                push @day, (1 + (2*$d+1-$k) % ($m));
            }
        }
        push @ret, [ @day ];
    }
    return \@ret;
}

1;
>>>

But naturally, this solution no longer makes use of the near and far arrays he 
allocated.

Regards,

	Shlomi Fish
-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif-ik1l9ssToec+JF/[email protected]
Homepage:        http://www.shlomifish.org/

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