[CHALLENGE] Boggle

Jasper McCrea jasper at guideguide.com
Fri Jan 31 06:16:48 CST 2003


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

Jasp
-- 
I'm an _alcofrolic_, there's a difference!



More information about the Belfast-pm mailing list