1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-08 13:45:42 -04:00

gorack did it

This commit is contained in:
Ryan Voots 2010-10-05 00:22:30 -04:00
parent 00839b59b6
commit 2039610fae

View file

@ -1,8 +1,31 @@
use List::Util qw(min);
my $findcommon = sub {
my @input = map {lc $_} @_;
my $min = min(map {length $_} @input);
my $common = "";
for my $i (0..$min-1)
{
my $count = 1;
for my $j (1..$#input)
{
$count++ if (substr($input[0], $i, 1) eq substr($input[$j], $i, 1))
}
$common .= substr($input[0], $i, 1) if ($count == @input) # did it match all inputs?
}
return $common;
};
sub { sub {
my( $said ) = @_; my( $said ) = @_;
my $ors =()= $said->{body}=~m/\bor\b/g; my $ors =()= $said->{body}=~m/\bor\b/g;
my $commas =()= $said->{body}=~m/,(?=.*\bor\b)/g; my $commas =()= $said->{body}=~m/,(?=.*\bor\b)/g;
my $common = "";
my @a; my @a;
@ -18,6 +41,8 @@ sub {
} }
s/^\s*//, s/\s*\?\s*$// for @a; #trim them up s/^\s*//, s/\s*\?\s*$// for @a; #trim them up
$common = $findcommon->(@a);
} }
else else
{ {
@ -43,7 +68,7 @@ sub {
"As I see it, yes"); "As I see it, yes");
} }
print $a[rand@a]."." print $a[rand@a]." $common."
} }
__DATA__ __DATA__