Transportation problem: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: delete duplicative directive)
Line 2,582: Line 2,582:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|Rakudo|2018.09}}
{{works with|Rakudo|2019.03.1}}
Using [[Vogel's_approximation_method#Perl6|Vogel's approximation method]]:
Using [[Vogel's_approximation_method#Perl6|Vogel's approximation method]]:
<lang perl6>my %costs = :S1{:3C1, :5C2, :7C3}, :S2{:3C1, :2C2, :5C3};
<lang perl6>my %costs = :S1{:3C1, :5C2, :7C3}, :S2{:3C1, :2C2, :5C3};
Line 2,601: Line 2,601:
{[$x, my $z = %costs{$x}{%g{$x}[0]},%g{$x}[1] ?? %costs{$x}{%g{$x}[1]} - $z !! $z]}
{[$x, my $z = %costs{$x}{%g{$x}[0]},%g{$x}[1] ?? %costs{$x}{%g{$x}[1]} - $z !! $z]}


@d = |@d.grep({ (.[2] == [max] @d».[2]) }).&min: :by(*.[1]);
@d = |@d.grep({ (.[2] == max @d».[2]) }).&min: :by(*.[1]);
@s = |@s.grep({ (.[2] == [max] @s».[2]) }).&min: :by(*.[1]);
@s = |@s.grep({ (.[2] == max @s».[2]) }).&min: :by(*.[1]);


my ($t, $f) = @d[2] == @s[2] ?? (@s[1],@d[1]) !! (@d[2],@s[2]);
my ($t, $f) = @d[2] == @s[2] ?? (@s[1],@d[1]) !! (@d[2],@s[2]);