]> www.fi.muni.cz Git - aoc.git/blobdiff - 2017/24.pl
AoC 2017 days 11 to 15
[aoc.git] / 2017 / 24.pl
diff --git a/2017/24.pl b/2017/24.pl
new file mode 100755 (executable)
index 0000000..7b85e56
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my %zero;
+my %graph;
+$; = ',';
+
+while (<>) {
+       chomp;
+       my ($src, @dsts) = /(\d+)/g;
+       $graph{$src} = [ @dsts ];
+}
+
+
+sub walk {
+       my ($node) = @_;
+
+       for my $neigh (@{ $graph{$node} }) {
+               next if $zero{$neigh}++;
+               walk($neigh);
+       }
+}
+
+my $comp;
+for my $node (keys %graph) {
+       next if $zero{$node};
+       walk($node);
+       $comp++;
+}
+say $comp;