aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/atschneid/perl/ch-1.pl
blob: ca3352ab24d54b8b3f57055d9da21ab42989760e (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
use warnings;
use strict;

use v5.38;

sub no_connection( @routes ) {
    my %out_count;
    for (@routes) {
	my ( $from, $to ) = @$_;
	$out_count{ $from } += 1;
	$out_count{ $to } += 0;
    }

    return grep { !$out_count{ $_ } } keys %out_count;
}

my @inputs = (
    [
     ["B", "C"],
     ["D", "B"],
     ["C", "A"],
    ],
    [
     ["B", "C"],
     ["D", "B"],
     ["C", "A"],
     ["C", "Z"],
    ],
    [
     ["A", "Z"],
    ]
    );
for my $input (@inputs) {
    for (@$input) {
	printf '[ ' . ( join ', ', @$_ ) . ' ] ';
    }
    say ' => ' . ( join ', ', no_connection( @$input ) );
}