[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] 100 point words.



How not fun is this solution?

#-----------------------8<-----------------------8<-----------------------
#!/usr/local/bin/perl -w
# wordsum.pl -- print words whose letter values (a=1, b=2, ..., z=26)
#               add up to some goal n (default n=100)

use strict;
die "Usage: wordsum.pl [goal] [word list file(s)]\n" unless @ARGV;
my $goal = $ARGV[0] =~ m/^[1-9]\d*$/ ? shift : 100;
my %ord = ();
@ord{"\n", 'A'..'Z', 'a'..'z'} = (0, 1..26, 1..26);
while (<>) {
    next unless m/^[A-Za-z]+$/;
    my $sum = 0;
    map { $sum += $ord{$_} } split //;
    print if $sum == $goal;
}
#-----------------------8<-----------------------8<-----------------------

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe