On Fri, Jul 23, 1999 at 02:23:35PM -0400, Ronald J Kimball wrote: > On Fri, Jul 23, 1999 at 12:52:35PM -0500, Brent Michalski wrote: > > 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. > > > > 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... > > For shortest, can anyone beat this one-liner? > > > perl -e'while(<>){$t+=1+ord($1)-ord"a"while/(.)/g;print if$t==100;$t=0}' I get Yugoslavia out of this, which ain't right. You forgot to normalize your data. Just stick an lc in there like so: perl -e'while(<>){$t+=1+ord(lc$1)-ord"a"while/(.)/g;print if$t==100;$t=0}' Anyhow, here's the solution I came up with: perl -nle 'BEGIN{%c=map{($_=>++$c)}"a".."z"}$s=0;print if map({$s+=$c{lc$_}}split("")),$s==100;' <word file> -- Michael G Schwern schwern@pobox.com http://www.pobox.com/~schwern /(?:(?:(1)[.-]?)?\(?(\d{3})\)?[.-]?)?(\d{3})[.-]?(\d{4})(x\d+)?/i ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe