Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- my %graph;
- foreach my $conx (map {[m/(\w{2})-(\w{2})/]} <>) {
- push( $graph{$conx->[0]}->@*, $conx->[1] );
- push( $graph{$conx->[1]}->@*, $conx->[0] );
- }
- my $part1 = 0;
- my %table;
- foreach my $comp (grep {m/^t/} keys %graph) {
- foreach my $neigh ($graph{$comp}->@*) {
- foreach my $third ($graph{$neigh}->@*) {
- next if (!grep {$_ eq $comp} $graph{$third}->@*);
- my @sort = sort( $comp, $neigh, $third );
- $part1++ if ($comp ne $third and !$table{"@sort"}++);
- }
- }
- }
- say "Part 1: $part1";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement