[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [FWP] Golf challenge: Scoring a word list
Tom Moertel wrote:
>
> Write the shortest Perl one-liner that reads a list of words on
> standard input and prints its score, given that the letters in
> $ARGV[0] have been guessed. For example, if the file "test" contains:
>
> makers
> primal
> vulcan
>
> You should be able to enter the following command line
>
> perl [MAGIC STUFF HERE] "as" <test
>
> and see "14" as output.
Here's a couple using Abigail's trick.
57 characters:
perl -lpe'INIT{$x=pop}s/[$x]//g;s/./$c{$&.$.}++/ge}{$_=keys%c' as <test
55 characters:
perl -lpe'INIT{$x=pop}s/(?![$x])./$c{$&.$.}++/ge}{$_=keys%c' as <test
--
Rick Delaney
rick.delaney@home.com
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe