Created
December 1, 2015 15:49
-
-
Save emacdona/dbee94113f84de5505d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my $letters = shift or die "Specify letters"; | |
my @letters = split //, $letters; | |
my $size = shift or die "Specify count"; | |
open(DICT, "</usr/share/dict/words"); | |
my $words = {}; | |
while(my $word = <DICT>){ | |
chomp $word; | |
$word = lc($word); | |
$word =~ s/'//; | |
$words->{$word}->{"letters"} = [split //, $word]; | |
$words->{$word}->{"word"} = $word; | |
} | |
for my $word ( grep { $size == @{$words->{$_}->{"letters"}} } keys(%$words) ) { | |
for my $letter (@letters){ | |
$words->{$word}->{"word"} =~ s/$letter//; | |
} | |
} | |
for my $word ( grep { $size == @{$words->{$_}->{"letters"}} and $words->{$_}->{"word"} eq "" } keys(%$words) ) { | |
print "$word\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment