Anagram: read words only once.

master
gdrooid 2014-07-03 15:50:36 +02:00
parent a1a3f20ac7
commit 8b2112768b
1 changed files with 5 additions and 5 deletions

View File

@ -20,6 +20,8 @@ topics "words_and_games";
attribution github => ["https://github.com/loganom", 'loganom'], attribution github => ["https://github.com/loganom", 'loganom'],
github => ["https://github.com/beardlybread", "beardlybread"]; github => ["https://github.com/beardlybread", "beardlybread"];
my @words = share('words')->slurp;
handle remainder => sub { handle remainder => sub {
s/^of\s(.*)/$1/i; s/^of\s(.*)/$1/i;
@ -49,19 +51,17 @@ handle remainder => sub {
} }
} }
my $fileobj = share("words"); # list of words foreach (@words) { # while we have more input
open my $INF, "<", $fileobj->stringify or return; #read in the words file
while (<$INF>) { # while we have more input
# if $word has a value and the text input contains characters from our word and is the correct length # if $word has a value and the text input contains characters from our word and is the correct length
if ($word and /^[$word]{$n}$/i) { if ($word and /^[$word]{$n}$/i) {
chomp; chomp;
# skip if the word we see is the original word # skip if the word we see is the original word
next if lc($_) eq lc($word); next if lc eq lc($word);
# split the word by character, counting frequency of each character # split the word by character, counting frequency of each character
# the words here come from the list of words file # the words here come from the list of words file
my %f; my %f;
for (split //, lc($_)) { for (split //, lc) {
if ($f{$_}) { if ($f{$_}) {
$f{$_} += 1; $f{$_} += 1;
} else { } else {