aboutsummaryrefslogtreecommitdiff
path: root/challenge-283/dave-jacoby/perl/ch-1.pl
blob: 1b1dc7820a5ad0e92a7548c6687302c0a4a7c9ad (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
#!/usr/bin/env perl

use strict;
use warnings;
use experimental qw{ postderef say signatures state };

use List::Util qw{ uniq };

my @examples = (    # added a couple test entries

    [ 3, 3, 1 ], 
    [ 3, 2, 4, 2, 4 ], 
    [1], 
    [ 4, 3, 1, 1, 1, 4 ]
);

for my $example (@examples) {
    my $input = join ', ', $example->@*;
    my $output = unique_number($example);
    say <<"END";
    Input:  \@int = ($input)
    Output: $output
END
}

sub unique_number ($input) {
    my $hash;
    for my $i ( @$input ) {
        $hash->{$i}++;
    }
    my @results = grep {$hash->{$_} == 1 } keys %$hash;
    return shift @results;
}