Skip to content

Instantly share code, notes, and snippets.

@Mercerenies
Last active January 16, 2019 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mercerenies/460b2028335a448d0410da0e441c94c1 to your computer and use it in GitHub Desktop.
Save Mercerenies/460b2028335a448d0410da0e441c94c1 to your computer and use it in GitHub Desktop.
Silver Tongue Forum Game Unspoken Rules
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
=pod
1. B<Don't use big words.> These people aren't very bright. Don't use words longer than 6 characters. Excludes punctuation.
=cut
sub rule1 {
local $_ = shift;
for (split) {
s/[^\w\d]//g;
return '' if length > 6;
}
return 1;
}
=pod
2. B<Give a speech.> Say at least 12 words. If you don't say enough, they'll think you aren't serious.
=cut
sub rule2 {
local $_ = shift;
return (split() >= 12);
}
=pod
3. B<Be firm.> You should sound enthusiastic. Make sure that whatever you say ends in an exclamation point.
=cut
sub rule3 {
local $_ = shift;
return /!\s*$/;
}
=pod
4. B<Use unusual letters.> You want to stand apart from the others. Make sure to use at least one of: Z, X, Q, or J.
=cut
sub rule4 {
local $_ = shift;
return /[zxqj]/i;
}
=pod
5. B<Don't repeat yourself.> Don't use the same word multiple times.
=cut
sub rule5 {
local $_ = shift;
my %hash;
for (split) {
s/[^\w\d]//g;
$hash{lc()}++;
}
for (keys %hash) {
return '' if $hash{$_} > 1;
}
return 1;
}
sub format_output {
if (@_ == 0) {
say "Passes **no rules**.";
} elsif (@_ == 1) {
say "Passes **@_**.";
} elsif (@_ == 2) {
local $" = '** and **';
say "Passes **@_**.";
} else {
local $" = '**, **';
say "Passes **@_[0..@_-2]**, and **$_[-1]**.";
}
}
### Main ###
my @rules = (
["Rule 1" => \&rule1],
["Rule 2" => \&rule2],
["Rule 3" => \&rule3],
["Rule 4" => \&rule4],
["Rule 5" => \&rule5],
);
while (<>) {
my @matches;
for my $ix (@rules) {
push @matches, $ix->[0] if $ix->[1]->($_);
}
format_output @matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment