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

Re: [FWP] Golf challenge: Scoring a word list





Keith Calvert Ivey wrote:
> 
> 50:
>   perl -lpe'INIT{$c=pop}$n+=keys%{{/([^$c])()/g}}}{$_=$n' as <test

Keith flushed me out -- I was relying on keys%{{..}} for my entry --
and so there's no point in waiting any longer:

    perl -le'$g=pop;$c+=keys%{{m!(([^$g$/]))!g}}for<>;print$c' as <test

A couple of points:

1. It works correctly in fringe cases (e.g., when guess list is "")
2. It works on all platforms (supports Unix, Mac, and DOS line endings)

Converting for Abigal's trick, I can shave off a couple of extra
characters because -l now auto-chomps for me, and so I can convert
m!(([^$g$/]))!g into /(([^$g ]))/g):

    perl -lpe'INIT{$g=pop}$c+=keys%{{/(([^ $g]))/g}}}{$_=$c' as <test

So, my best is one stroke more than Keith's, but the extra stroke lets
me handle the no-guess case as well:

    perl -lpe'INIT{$g=pop}$c+=keys%{{/(([^ $g]))/g}}}{$_=$c' "" <test
    18

BTW, here's a quick script I use to test the entries I've received:

    #!/bin/sh
    # test-cscore -- test a perl cheating-hangman score golf entry
    
    for W in ''  s a as; do
    
    "$@" $W <<EOF
    angles
    stones
    EOF
    
    "$@" $W <<EOF
    angles
    fluffs
    stones
    EOF
    
    "$@" $W <<EOF
    makers
    primal
    vulcan
    EOF
    
    egrep '^[a-z]+$' /usr/dict/words | "$@" $W
    
    done

I use it like so:

    ./test-cscore perl -lpe'INIT{$g=pop}$c+=keys%{{/(([^ $g]))/g}}}{$_=$c'

(without the guess or input redirection from testfile on the command line).
The expected output for a correct implementation should be as follows:

    11
    15
    18
    258955
    9
    12
    17
    238985
    10
    14
    15
    239607
    8
    11
    14
    219637

It's okay if the large numbers are off -- they are dependent on your
system's /usr/dict/words file -- but the small ones should match those
listed above.

Cheers,
Tom

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