> > Last summer my son came home with an assignment to find as many words as > he could that add up to 100 points. With A=1, B=2, ... Z=26 > > We were going on vacation that week and had 2 10 hour drives in the > car. At the end of the 20 hours, we had 4 or 5 words that added up to > 100. PRINTER is a word that adds up to 100. > > Well, it was driving me nuts so I told him that when we got back, i'd > write a Perl program to figure this out for us. The kid who found the > most words got a prize :-) [motivation]... > > Anyway, I wrote a program in about 15 minutes with about 20 lines of > code. We ran it against several dictionary files and came up with 10 > 4-column pages with words that add up to 100! > > It would be fun to create such a program and run it against a > "standard/common" dictionary and see who could do it in the coolest, or > shortest, way... One way: #!/usr/local/bin/perl -wn BEGIN { @lp{ 'a' .. 'z' } = ( 1 .. 26 ); } chomp; /[^a-z]/i or # skip words with non-alphabetic characters. eval join( '+', @lp{ split //, lc } ) . ' == 100 and print "$_\n"'; Another (similar) way: #!/usr/local/bin/perl -wn BEGIN { @lp{ 'a' .. 'z' } = ( 1 .. 26 ); } do { local $_ = $_; y/a-zA-Z//dc; s/(?<=\w)(?=\w)/+/g; s/(\w)/$lp{lc($1)}/g; eval "$_ == 100" } and print; -- John Porter ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe