Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use File::Slurp qw(read_file);
- my ($total, $suffix, @dictionary, @_dictionary, @failed);
- $suffix = $ARGV[0];
- @dictionary = read_file("./Etcetera/sowpods.txt") or die "couldn't open dictionary $!";
- BEGIN { $total = 0; }
- END {
- print "\n\n---------------\ntotal:\t$total\n";
- print "failed:\t@failed\n" if @failed;
- }
- @_dictionary = grep /$suffix$/, @dictionary;
- foreach ("a".."z") {
- my ($prefix, @matches, @sorted, $longest);
- $prefix = $_;
- @matches = grep /^$prefix/, @_dictionary;
- if (@matches) {
- @sorted = sort { length($b) <=> length($a) } @matches;
- $longest = $sorted[0];
- chomp $longest;
- my $score = length($longest);
- $total += $score;
- print "$score\t$longest\n";
- } else {
- push @failed, $prefix;
- }
- }
Add Comment
Please, Sign In to add comment