Skip to content
Snippets Groups Projects
Verified Commit d468700b authored by mirabilos's avatar mirabilos Committed by mirabilos
Browse files

yay

parent 89af6b18
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env perl
open FH, "<inputfile" or die "$!";
$pats = <FH>;
chomp $pats;
<FH>;
$pats =~ s/, /|/g;
$valid = 0;
while (<FH>) {
chomp;
/^(?:$pats)+$/o and ++$valid;
}
print $valid . "\n";
#!/usr/bin/env perl
open FH, "<inputfile" or die "$!";
$pats = <FH>;
chomp $pats;
<FH>;
@pats = split /, /, $pats;
$pats = join '|', @pats;
%h = ();
$h{''} = 0;
sub recurse($$) {
my $inv = shift;
my $t = shift;
my $r = 0;
foreach my $lv (@pats) {
$inv =~ m/^$lv(.*)$/ or next;
my $is = $1;
if ($is eq '') {
++$r;
next;
}
if (exists $h{$is}) {
# print "$t$is :: memo(" . $h{$is} . ")\n";
$r += $h{$is};
next;
}
if ($is =~ m/^(?:$pats)+$/o) {
# print "$t$is\n";
my $hr = recurse($is, "$t\t");
$r += $hr;
$h{$is} = $hr;
} else {
$h{$is} = 0;
}
}
return $r;
}
$valid = 0;
while (<FH>) {
chomp;
my $input = $_;
/^(?:$pats)+$/o or next;
print $input . "\n";
$valid += recurse($input, "\t");
}
print $valid . "\n";
#use Data::Dumper;
#print Data::Dumper::Dumper(\%h);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment