-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19.pl
54 lines (42 loc) · 744 Bytes
/
19.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use feature 'say';
use Clipboard;
use List::Util qw/sum/;
use Math::Cartesian::Product;
sub out {
my $out = shift;
Clipboard->copy_to_all_selections($out);
print "$out\n";
}
my @RULES;
sub expand {
my $rule = shift;
while ($rule =~ s/(\d+)/"(?:".$RULES[$1].")"/goe) {}
$rule =~ s/\s+//go;
$rule =~ s/\"//go;
return $rule;
}
my $res = 0;
while(<>) {
chomp;
last if /^$/;
m{(\d+): (.+)}o or die;
$RULES[$1]=$2;
}
#comment these for part1
$RULES[8] = "(?: 42 )+";
$RULES[11] = "(42 (?___)* 31)";
my $rule = expand($RULES[0]);
say $rule;
$rule =~ s/___/1/go;
$rule = "^(?:$rule)\$";
say $rule;
while (<>) {
chomp;
if (/$rule/) {
$res++;
}
}
out ($res);