[CHALLENGE] Boggle

Jasper McCrea jasper at guideguide.com
Fri Jan 31 08:46:48 CST 2003


Jasper McCrea wrote:
> 
> Simon Cozens wrote:
> >
> > Well, here's my submission; should be straightforward:
> >
> > my at n=(0,[0,[[2,2],[2,1],[1,2]],[[2,3],[2,2],[2,1],[1,3]
> > ,[1,1]],[[2,4],[2,3],[2,2],[1,4],[1,2]],[[2,4],[2,3],[1
> > ,3]]],[0,[[3,2],[3,1],[2,2],[1,2],[1,1],[1,2]],[[3,3],[
> > 3,2],[3,1],[2,3],[2,1],[1,3],[1,2],[1,3]],[[3,4],[3,3],
> > [3,2],[2,4],[2,2],[1,4],[1,3],[1,2]],[[3,4],[3,3],[2,3]
> > ,[1,4]]],[0,[[4,2],[4,1],[3,2],[2,2],[2,1],[2,2]],[[4,3
> > ],[4,2],[4,1],[3,3],[3,1],[2,3],[2,2],[2,3]],[[4,4],[4,
> > 3],[4,2],[3,4],[3,2],[2,4],[2,3],[2,4]],[[4,4],[4,3],[3
> > ,3],[2,4]]],[0,[[4,2],[3,2],[3,1],[3,2]],[[4,3],[4,1],[
> > 3,3],[3,2],[3,3]],[[4,4],[4,2],[3,4],[3,3],[3,4]],[[4,3
> > ],[3,4]]]);my at b=[];my($h,%w);for my $l(0,1,2,3){chop(my
> > $r=<>);my at r=split//,$r;push at b,[0, at r];push@{$w{$r[$_]}},
> > [$l,$_]for 1..4;$h.=$r}while (<>){/^[$h]{3,9}$/o||next;
> > chomp;my at s=split//,(my$w=$_);p($_,{$_->[0].$_->[1]=>1},
> > @s)&&print$w."\n"for@{$w{shift at s}}}sub p{my($p,$h, at l)=@
> > _;my at z=@{$n[$p->[0]][$p->[1]]};for my$n(@{$w{shift at l}})
> > {next if(!scalar grep{$n->[0]==$_->[0]&&$n->[1]==$_->[1
> > ]}@z)||$h->{$n->[0].$n->[1]}++;return!@l||p($n,$h, at l)}}
> 
> Ahhh, golf is it?
> 
> #!perl -n0
> sub j{pop=~/(.)(.) (.)(.)$/;($1-$3)**2+(
> $2-$4)**2>2}sub b{my$p=pop;my($l, at l)=@{
> pop()};($p&&$p=~$_||j("$p $_"))||(!@l
> ||b([@l],"$p $_"))&&(return 1)for@{
> $l{lc$l}}}/=+/;$v=$';push @{$l{$_.'u'x/q/}},
> $i%4 .int$i++/4 for$`=~/\w/sg;for($v=~/...+
> /g){print if!$n{$_}++&&b([/qu|./g],'')}exit

Did I say that? I meant:

#!perl -n0
/=+/;$_=$';push@{$l{/q/ ?qu:$_}},$i%4 .int$i++/4 for
$`=~/./g;$n{$_}++||b(0,/qu|./g)&&print for /...+\n/g
;exit; sub b{my($p,$l, at l)=@_;($p&&$p=~$_||j("$p $_")
)||(!@l||b("$p $_", at l))&&return 1 for@{$l{lc$l}}}sub
j{pop =~/(.)(.) (.)(.)$/;($1 -$3)**2+($2-$4) **2 >2}

And this is nothing like my 'real' solution, honest! It's a bazillion gazillion
times faster than that!

Jasper
-- 
You let him win, didn't you, Notch?
Yes I did, Kimberly, but you'll never get me to admit it.



More information about the Belfast-pm mailing list