]> www.fi.muni.cz Git - aoc.git/blob - 2017/23.pl
Day 25: examining the input
[aoc.git] / 2017 / 23.pl
1 #!/usr/bin/perl
2
3 use v5.30;
4 use strict;
5
6 my %zero;
7 my %graph;
8 $; = ',';
9
10 while (<>) {
11         chomp;
12         my ($src, @dsts) = /(\d+)/g;
13         $graph{$src} = [ @dsts ];
14 }
15
16
17 sub walk {
18         my ($node) = @_;
19
20         for my $neigh (@{ $graph{$node} }) {
21                 next if $zero{$neigh}++;
22                 walk($neigh);
23         }
24 }
25
26 walk(0);
27 say scalar keys %zero;