http://www.perlmonks.org?node_id=255437

Was the phrase used in The Perl Journal which kept me from submiting this. However, I think it's pretty nice, and I have made it as short as I know how.
sub q{$;=1;for(0..3){$;[$_]=int(rand(9))}}sub _{print@_}&q;for(;;){$:= +$~=0 ;_"$/$; ";$_=<>;if(/^\d{4}$/){@q=split//;--$#q;$@=-1;for(@q){$a=$_;($a +==$; [++$@])&&++$:||(grep/$a/,@;)&&++$~}_"$~W$:B ";++$;;$:==4|$;>10&&_(@;)& +&&q}}