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