]> www.fi.muni.cz Git - aoc.git/blob - 2015/33.pl
Year 2015
[aoc.git] / 2015 / 33.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4 use strict;
5
6 chomp (my @cont = sort { $a <=> $b } <>);
7
8 my $count;
9 sub walk {
10         my ($rem, $rest, $used) = @_;
11         if (!$rem) {
12                 $count++;
13                 say join(',', @$used);
14                 return;
15         }
16         return if !@$rest || $rem < $rest->[0];
17         for my $i (0 .. $#$rest) {
18                 my @nr = @$rest;
19                 my @nu = @$used;
20                 my (@a) = splice @nr, 0, $i+1;
21                 my $n = $a[-1];
22                 push @nu, $n;
23                 walk($rem - $n, \@nr, \@nu) if $rem >= $n;
24         }
25 }
26
27 walk(150, \@cont, []);
28 say $count;
29