aboutsummaryrefslogtreecommitdiff
path: root/challenge-343/e-choroba/perl/ch-2.pl
blob: 8d1681722d4e7d3122df33d4bcf565290de34ada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
use warnings;
use strict;
use experimental qw( signatures );

sub champion_team(@grid) {
    my $max = 0;
    my %wins;
    for my $y (0 .. $#grid) {
        for my $x (0 .. $#{ $grid[$y] }) {
            my $w = $grid[$y][$x] ? $y : $x;
            $max = $w if ++$wins{$w} > $wins{$max};
        }
    }
    return "Team $max"
}

use Test::More tests => 5;

is champion_team(
                 [0, 1, 1],
                 [0, 0, 1],
                 [0, 0, 0],
               ), 'Team 0', 'Example 1';

is champion_team(
                 [0, 1, 0, 0],
                 [0, 0, 0, 0],
                 [1, 1, 0, 0],
                 [1, 1, 1, 0],
               ), 'Team 3', 'Example 2';

is champion_team(
                 [0, 1, 0, 1],
                 [0, 0, 1, 1],
                 [1, 0, 0, 0],
                 [0, 0, 1, 0],
               ), 'Team 0', 'Example 3';

is champion_team(
                 [0, 1, 1],
                 [0, 0, 0],
                 [0, 1, 0],
               ), 'Team 0', 'Example 4';

is champion_team(
                 [0, 0, 0, 0, 0],
                 [1, 0, 0, 0, 0],
                 [1, 1, 0, 1, 1],
                 [1, 1, 0, 0, 0],
                 [1, 1, 0, 1, 0],
               ), 'Team 2', 'Example 5';